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, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 223 | bool do_clinit, |
| 224 | const CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = nullptr) |
| 225 | : SlowPathCodeMIPS(at), |
| 226 | cls_(cls), |
| 227 | dex_pc_(dex_pc), |
| 228 | do_clinit_(do_clinit), |
| 229 | bss_info_high_(bss_info_high) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 230 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 231 | } |
| 232 | |
| 233 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 234 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 235 | Location out = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 236 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 237 | const bool baker_or_no_read_barriers = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 238 | InvokeRuntimeCallingConvention calling_convention; |
| 239 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 240 | const bool is_load_class_bss_entry = |
| 241 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 242 | __ Bind(GetEntryLabel()); |
| 243 | SaveLiveRegisters(codegen, locations); |
| 244 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 245 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 246 | Register entry_address = kNoRegister; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 247 | if (is_load_class_bss_entry && baker_or_no_read_barriers) { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 248 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 249 | bool temp_is_a0 = (temp == calling_convention.GetRegisterAt(0)); |
| 250 | // In the unlucky case that `temp` is A0, we preserve the address in `out` across the |
| 251 | // kSaveEverything call. |
| 252 | entry_address = temp_is_a0 ? out.AsRegister<Register>() : temp; |
| 253 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 254 | if (temp_is_a0) { |
| 255 | __ Move(entry_address, temp); |
| 256 | } |
| 257 | } |
| 258 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 259 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 260 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 261 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 262 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 263 | mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 264 | if (do_clinit_) { |
| 265 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 266 | } else { |
| 267 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 268 | } |
| 269 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 270 | // For HLoadClass/kBssEntry, store the resolved class to the BSS entry. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 271 | if (is_load_class_bss_entry && baker_or_no_read_barriers) { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 272 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 273 | DCHECK(bss_info_high_); |
| 274 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 275 | mips_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index, bss_info_high_); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 276 | __ Sw(calling_convention.GetRegisterAt(0), |
| 277 | entry_address, |
| 278 | /* placeholder */ 0x5678, |
| 279 | &info_low->label); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 282 | // Move the class to the desired location. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 283 | if (out.IsValid()) { |
| 284 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 285 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 286 | mips_codegen->MoveLocation(out, |
| 287 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 288 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 289 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 290 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 291 | |
| 292 | // For HLoadClass/kBssEntry, store the resolved class to the BSS entry. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 293 | if (is_load_class_bss_entry && !baker_or_no_read_barriers) { |
| 294 | // For non-Baker read barriers we need to re-calculate the address of |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 295 | // the class entry. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 296 | const bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 297 | const bool has_irreducible_loops = codegen->GetGraph()->HasIrreducibleLoops(); |
| 298 | Register base = |
| 299 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 300 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 301 | mips_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 302 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 303 | mips_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index, info_high); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 304 | mips_codegen->EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base); |
| 305 | __ Sw(out.AsRegister<Register>(), TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 306 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 307 | __ B(GetExitLabel()); |
| 308 | } |
| 309 | |
| 310 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } |
| 311 | |
| 312 | private: |
| 313 | // The class this slow path will load. |
| 314 | HLoadClass* const cls_; |
| 315 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 316 | // The dex PC of `at_`. |
| 317 | const uint32_t dex_pc_; |
| 318 | |
| 319 | // Whether to initialize the class. |
| 320 | const bool do_clinit_; |
| 321 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 322 | // Pointer to the high half PC-relative patch info for HLoadClass/kBssEntry. |
| 323 | const CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high_; |
| 324 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 325 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 326 | }; |
| 327 | |
| 328 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 329 | public: |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 330 | explicit LoadStringSlowPathMIPS(HLoadString* instruction, |
| 331 | const CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high) |
| 332 | : SlowPathCodeMIPS(instruction), bss_info_high_(bss_info_high) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 333 | |
| 334 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 335 | DCHECK(instruction_->IsLoadString()); |
| 336 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 337 | LocationSummary* locations = instruction_->GetLocations(); |
| 338 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 339 | HLoadString* load = instruction_->AsLoadString(); |
| 340 | const dex::StringIndex string_index = load->GetStringIndex(); |
| 341 | Register out = locations->Out().AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 342 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 343 | const bool baker_or_no_read_barriers = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 344 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 345 | __ Bind(GetEntryLabel()); |
| 346 | SaveLiveRegisters(codegen, locations); |
| 347 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 348 | // For HLoadString/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 349 | Register entry_address = kNoRegister; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 350 | if (baker_or_no_read_barriers) { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 351 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 352 | bool temp_is_a0 = (temp == calling_convention.GetRegisterAt(0)); |
| 353 | // In the unlucky case that `temp` is A0, we preserve the address in `out` across the |
| 354 | // kSaveEverything call. |
| 355 | entry_address = temp_is_a0 ? out : temp; |
| 356 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 357 | if (temp_is_a0) { |
| 358 | __ Move(entry_address, temp); |
| 359 | } |
| 360 | } |
| 361 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 362 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 363 | mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 364 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 365 | |
| 366 | // Store the resolved string to the BSS entry. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 367 | if (baker_or_no_read_barriers) { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 368 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 369 | DCHECK(bss_info_high_); |
| 370 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 371 | mips_codegen->NewStringBssEntryPatch(load->GetDexFile(), string_index, bss_info_high_); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 372 | __ Sw(calling_convention.GetRegisterAt(0), |
| 373 | entry_address, |
| 374 | /* placeholder */ 0x5678, |
| 375 | &info_low->label); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 378 | DataType::Type type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 379 | mips_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 380 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 381 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 382 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 383 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 384 | // Store the resolved string to the BSS entry. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 385 | if (!baker_or_no_read_barriers) { |
| 386 | // For non-Baker read barriers we need to re-calculate the address of |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 387 | // the string entry. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 388 | const bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 389 | const bool has_irreducible_loops = codegen->GetGraph()->HasIrreducibleLoops(); |
| 390 | Register base = |
| 391 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 392 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 393 | mips_codegen->NewStringBssEntryPatch(load->GetDexFile(), string_index); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 394 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 395 | mips_codegen->NewStringBssEntryPatch(load->GetDexFile(), string_index, info_high); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 396 | mips_codegen->EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base); |
| 397 | __ Sw(out, TMP, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 398 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 399 | __ B(GetExitLabel()); |
| 400 | } |
| 401 | |
| 402 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } |
| 403 | |
| 404 | private: |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 405 | // Pointer to the high half PC-relative patch info. |
| 406 | const CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high_; |
| 407 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 408 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 409 | }; |
| 410 | |
| 411 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 412 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 413 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 414 | |
| 415 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 416 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 417 | __ Bind(GetEntryLabel()); |
| 418 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 419 | // Live registers will be restored in the catch block if caught. |
| 420 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 421 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 422 | mips_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 423 | instruction_, |
| 424 | instruction_->GetDexPc(), |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 425 | this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 426 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 427 | } |
| 428 | |
| 429 | bool IsFatal() const OVERRIDE { return true; } |
| 430 | |
| 431 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } |
| 432 | |
| 433 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 434 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 435 | }; |
| 436 | |
| 437 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 438 | public: |
| 439 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 440 | : SlowPathCodeMIPS(instruction), successor_(successor) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 441 | |
| 442 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 443 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 444 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 445 | __ Bind(GetEntryLabel()); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 446 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 447 | mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 448 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 449 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 450 | if (successor_ == nullptr) { |
| 451 | __ B(GetReturnLabel()); |
| 452 | } else { |
| 453 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | MipsLabel* GetReturnLabel() { |
| 458 | DCHECK(successor_ == nullptr); |
| 459 | return &return_label_; |
| 460 | } |
| 461 | |
| 462 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } |
| 463 | |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 464 | HBasicBlock* GetSuccessor() const { |
| 465 | return successor_; |
| 466 | } |
| 467 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 468 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 469 | // If not null, the block to branch to after the suspend check. |
| 470 | HBasicBlock* const successor_; |
| 471 | |
| 472 | // If `successor_` is null, the label to branch to after the suspend check. |
| 473 | MipsLabel return_label_; |
| 474 | |
| 475 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 476 | }; |
| 477 | |
| 478 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 479 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 480 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal) |
| 481 | : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 482 | |
| 483 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 484 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 485 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 486 | DCHECK(instruction_->IsCheckCast() |
| 487 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 488 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 489 | |
| 490 | __ Bind(GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 491 | if (!is_fatal_) { |
| 492 | SaveLiveRegisters(codegen, locations); |
| 493 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 494 | |
| 495 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 496 | // move resolver. |
| 497 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 498 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 499 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 500 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 501 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 502 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 503 | DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 504 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 505 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 506 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 507 | DataType::Type ret_type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 508 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 509 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 510 | } else { |
| 511 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 512 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 513 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 516 | if (!is_fatal_) { |
| 517 | RestoreLiveRegisters(codegen, locations); |
| 518 | __ B(GetExitLabel()); |
| 519 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 523 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 524 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 525 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 526 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 527 | const bool is_fatal_; |
| 528 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 529 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 530 | }; |
| 531 | |
| 532 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 533 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 534 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 535 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 536 | |
| 537 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 538 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 539 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 540 | LocationSummary* locations = instruction_->GetLocations(); |
| 541 | SaveLiveRegisters(codegen, locations); |
| 542 | InvokeRuntimeCallingConvention calling_convention; |
| 543 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 544 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 545 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 546 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 550 | |
| 551 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 552 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 553 | }; |
| 554 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 555 | class ArraySetSlowPathMIPS : public SlowPathCodeMIPS { |
| 556 | public: |
| 557 | explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
| 558 | |
| 559 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 560 | LocationSummary* locations = instruction_->GetLocations(); |
| 561 | __ Bind(GetEntryLabel()); |
| 562 | SaveLiveRegisters(codegen, locations); |
| 563 | |
| 564 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 565 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 566 | parallel_move.AddMove( |
| 567 | locations->InAt(0), |
| 568 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 569 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 570 | nullptr); |
| 571 | parallel_move.AddMove( |
| 572 | locations->InAt(1), |
| 573 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 574 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 575 | nullptr); |
| 576 | parallel_move.AddMove( |
| 577 | locations->InAt(2), |
| 578 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 579 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 580 | nullptr); |
| 581 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 582 | |
| 583 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 584 | mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 585 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 586 | RestoreLiveRegisters(codegen, locations); |
| 587 | __ B(GetExitLabel()); |
| 588 | } |
| 589 | |
| 590 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS"; } |
| 591 | |
| 592 | private: |
| 593 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS); |
| 594 | }; |
| 595 | |
| 596 | // Slow path marking an object reference `ref` during a read |
| 597 | // barrier. The field `obj.field` in the object `obj` holding this |
| 598 | // reference does not get updated by this slow path after marking (see |
| 599 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that). |
| 600 | // |
| 601 | // This means that after the execution of this slow path, `ref` will |
| 602 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 603 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 604 | // probably still be a from-space reference (unless it gets updated by |
| 605 | // another thread, or if another thread installed another object |
| 606 | // reference (different from `ref`) in `obj.field`). |
| 607 | // |
| 608 | // If `entrypoint` is a valid location it is assumed to already be |
| 609 | // holding the entrypoint. The case where the entrypoint is passed in |
| 610 | // is for the GcRoot read barrier. |
| 611 | class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS { |
| 612 | public: |
| 613 | ReadBarrierMarkSlowPathMIPS(HInstruction* instruction, |
| 614 | Location ref, |
| 615 | Location entrypoint = Location::NoLocation()) |
| 616 | : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 617 | DCHECK(kEmitCompilerReadBarrier); |
| 618 | } |
| 619 | |
| 620 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 621 | |
| 622 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 623 | LocationSummary* locations = instruction_->GetLocations(); |
| 624 | Register ref_reg = ref_.AsRegister<Register>(); |
| 625 | DCHECK(locations->CanCall()); |
| 626 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 627 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 628 | instruction_->IsStaticFieldGet() || |
| 629 | instruction_->IsArrayGet() || |
| 630 | instruction_->IsArraySet() || |
| 631 | instruction_->IsLoadClass() || |
| 632 | instruction_->IsLoadString() || |
| 633 | instruction_->IsInstanceOf() || |
| 634 | instruction_->IsCheckCast() || |
| 635 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 636 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 637 | << "Unexpected instruction in read barrier marking slow path: " |
| 638 | << instruction_->DebugName(); |
| 639 | |
| 640 | __ Bind(GetEntryLabel()); |
| 641 | // No need to save live registers; it's taken care of by the |
| 642 | // entrypoint. Also, there is no need to update the stack mask, |
| 643 | // as this runtime call will not trigger a garbage collection. |
| 644 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 645 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 646 | (S2 <= ref_reg && ref_reg <= S7) || |
| 647 | (ref_reg == FP)) << ref_reg; |
| 648 | // "Compact" slow path, saving two moves. |
| 649 | // |
| 650 | // Instead of using the standard runtime calling convention (input |
| 651 | // and output in A0 and V0 respectively): |
| 652 | // |
| 653 | // A0 <- ref |
| 654 | // V0 <- ReadBarrierMark(A0) |
| 655 | // ref <- V0 |
| 656 | // |
| 657 | // we just use rX (the register containing `ref`) as input and output |
| 658 | // of a dedicated entrypoint: |
| 659 | // |
| 660 | // rX <- ReadBarrierMarkRegX(rX) |
| 661 | // |
| 662 | if (entrypoint_.IsValid()) { |
| 663 | mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 664 | DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9); |
| 665 | __ Jalr(entrypoint_.AsRegister<Register>()); |
| 666 | __ NopIfNoReordering(); |
| 667 | } else { |
| 668 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 669 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 670 | // This runtime call does not require a stack map. |
| 671 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 672 | instruction_, |
| 673 | this, |
| 674 | /* direct */ false); |
| 675 | } |
| 676 | __ B(GetExitLabel()); |
| 677 | } |
| 678 | |
| 679 | private: |
| 680 | // The location (register) of the marked object reference. |
| 681 | const Location ref_; |
| 682 | |
| 683 | // The location of the entrypoint if already loaded. |
| 684 | const Location entrypoint_; |
| 685 | |
| 686 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS); |
| 687 | }; |
| 688 | |
| 689 | // Slow path marking an object reference `ref` during a read barrier, |
| 690 | // and if needed, atomically updating the field `obj.field` in the |
| 691 | // object `obj` holding this reference after marking (contrary to |
| 692 | // ReadBarrierMarkSlowPathMIPS above, which never tries to update |
| 693 | // `obj.field`). |
| 694 | // |
| 695 | // This means that after the execution of this slow path, both `ref` |
| 696 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 697 | // hold the same to-space reference (unless another thread installed |
| 698 | // another object reference (different from `ref`) in `obj.field`). |
| 699 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS { |
| 700 | public: |
| 701 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction, |
| 702 | Location ref, |
| 703 | Register obj, |
| 704 | Location field_offset, |
| 705 | Register temp1) |
| 706 | : SlowPathCodeMIPS(instruction), |
| 707 | ref_(ref), |
| 708 | obj_(obj), |
| 709 | field_offset_(field_offset), |
| 710 | temp1_(temp1) { |
| 711 | DCHECK(kEmitCompilerReadBarrier); |
| 712 | } |
| 713 | |
| 714 | const char* GetDescription() const OVERRIDE { |
| 715 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS"; |
| 716 | } |
| 717 | |
| 718 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 719 | LocationSummary* locations = instruction_->GetLocations(); |
| 720 | Register ref_reg = ref_.AsRegister<Register>(); |
| 721 | DCHECK(locations->CanCall()); |
| 722 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 723 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 724 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 725 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 726 | << instruction_->DebugName(); |
| 727 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 728 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 729 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 730 | |
| 731 | __ Bind(GetEntryLabel()); |
| 732 | |
| 733 | // Save the old reference. |
| 734 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 735 | // are used by the code that follows, but we need the old reference after |
| 736 | // the call to the ReadBarrierMarkRegX entry point. |
| 737 | DCHECK_NE(temp1_, AT); |
| 738 | DCHECK_NE(temp1_, TMP); |
| 739 | __ Move(temp1_, ref_reg); |
| 740 | |
| 741 | // No need to save live registers; it's taken care of by the |
| 742 | // entrypoint. Also, there is no need to update the stack mask, |
| 743 | // as this runtime call will not trigger a garbage collection. |
| 744 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 745 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 746 | (S2 <= ref_reg && ref_reg <= S7) || |
| 747 | (ref_reg == FP)) << ref_reg; |
| 748 | // "Compact" slow path, saving two moves. |
| 749 | // |
| 750 | // Instead of using the standard runtime calling convention (input |
| 751 | // and output in A0 and V0 respectively): |
| 752 | // |
| 753 | // A0 <- ref |
| 754 | // V0 <- ReadBarrierMark(A0) |
| 755 | // ref <- V0 |
| 756 | // |
| 757 | // we just use rX (the register containing `ref`) as input and output |
| 758 | // of a dedicated entrypoint: |
| 759 | // |
| 760 | // rX <- ReadBarrierMarkRegX(rX) |
| 761 | // |
| 762 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 763 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 764 | // This runtime call does not require a stack map. |
| 765 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 766 | instruction_, |
| 767 | this, |
| 768 | /* direct */ false); |
| 769 | |
| 770 | // If the new reference is different from the old reference, |
| 771 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 772 | // |
| 773 | // Note that this field could also hold a different object, if |
| 774 | // another thread had concurrently changed it. In that case, the |
| 775 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 776 | // field as-is. |
| 777 | MipsLabel done; |
| 778 | __ Beq(temp1_, ref_reg, &done); |
| 779 | |
| 780 | // Update the the holder's field atomically. This may fail if |
| 781 | // mutator updates before us, but it's OK. This is achieved |
| 782 | // using a strong compare-and-set (CAS) operation with relaxed |
| 783 | // memory synchronization ordering, where the expected value is |
| 784 | // the old reference and the desired value is the new reference. |
| 785 | |
| 786 | // Convenience aliases. |
| 787 | Register base = obj_; |
| 788 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 789 | // offset ("long offset"), of which only the low part contains |
| 790 | // data. |
| 791 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 792 | Register expected = temp1_; |
| 793 | Register value = ref_reg; |
| 794 | Register tmp_ptr = TMP; // Pointer to actual memory. |
| 795 | Register tmp = AT; // Value in memory. |
| 796 | |
| 797 | __ Addu(tmp_ptr, base, offset); |
| 798 | |
| 799 | if (kPoisonHeapReferences) { |
| 800 | __ PoisonHeapReference(expected); |
| 801 | // Do not poison `value` if it is the same register as |
| 802 | // `expected`, which has just been poisoned. |
| 803 | if (value != expected) { |
| 804 | __ PoisonHeapReference(value); |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | // do { |
| 809 | // tmp = [r_ptr] - expected; |
| 810 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 811 | |
| 812 | bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 813 | MipsLabel loop_head, exit_loop; |
| 814 | __ Bind(&loop_head); |
| 815 | if (is_r6) { |
| 816 | __ LlR6(tmp, tmp_ptr); |
| 817 | } else { |
| 818 | __ LlR2(tmp, tmp_ptr); |
| 819 | } |
| 820 | __ Bne(tmp, expected, &exit_loop); |
| 821 | __ Move(tmp, value); |
| 822 | if (is_r6) { |
| 823 | __ ScR6(tmp, tmp_ptr); |
| 824 | } else { |
| 825 | __ ScR2(tmp, tmp_ptr); |
| 826 | } |
| 827 | __ Beqz(tmp, &loop_head); |
| 828 | __ Bind(&exit_loop); |
| 829 | |
| 830 | if (kPoisonHeapReferences) { |
| 831 | __ UnpoisonHeapReference(expected); |
| 832 | // Do not unpoison `value` if it is the same register as |
| 833 | // `expected`, which has just been unpoisoned. |
| 834 | if (value != expected) { |
| 835 | __ UnpoisonHeapReference(value); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | __ Bind(&done); |
| 840 | __ B(GetExitLabel()); |
| 841 | } |
| 842 | |
| 843 | private: |
| 844 | // The location (register) of the marked object reference. |
| 845 | const Location ref_; |
| 846 | // The register containing the object holding the marked object reference field. |
| 847 | const Register obj_; |
| 848 | // The location of the offset of the marked reference field within `obj_`. |
| 849 | Location field_offset_; |
| 850 | |
| 851 | const Register temp1_; |
| 852 | |
| 853 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS); |
| 854 | }; |
| 855 | |
| 856 | // Slow path generating a read barrier for a heap reference. |
| 857 | class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS { |
| 858 | public: |
| 859 | ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction, |
| 860 | Location out, |
| 861 | Location ref, |
| 862 | Location obj, |
| 863 | uint32_t offset, |
| 864 | Location index) |
| 865 | : SlowPathCodeMIPS(instruction), |
| 866 | out_(out), |
| 867 | ref_(ref), |
| 868 | obj_(obj), |
| 869 | offset_(offset), |
| 870 | index_(index) { |
| 871 | DCHECK(kEmitCompilerReadBarrier); |
| 872 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 873 | // has been overwritten by (or after) the heap object reference load |
| 874 | // to be instrumented, e.g.: |
| 875 | // |
| 876 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 877 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 878 | // |
| 879 | // In that case, we have lost the information about the original |
| 880 | // object, and the emitted read barrier cannot work properly. |
| 881 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 882 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 883 | } |
| 884 | |
| 885 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 886 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 887 | LocationSummary* locations = instruction_->GetLocations(); |
| 888 | Register reg_out = out_.AsRegister<Register>(); |
| 889 | DCHECK(locations->CanCall()); |
| 890 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 891 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 892 | instruction_->IsStaticFieldGet() || |
| 893 | instruction_->IsArrayGet() || |
| 894 | instruction_->IsInstanceOf() || |
| 895 | instruction_->IsCheckCast() || |
| 896 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 897 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 898 | << instruction_->DebugName(); |
| 899 | |
| 900 | __ Bind(GetEntryLabel()); |
| 901 | SaveLiveRegisters(codegen, locations); |
| 902 | |
| 903 | // We may have to change the index's value, but as `index_` is a |
| 904 | // constant member (like other "inputs" of this slow path), |
| 905 | // introduce a copy of it, `index`. |
| 906 | Location index = index_; |
| 907 | if (index_.IsValid()) { |
| 908 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 909 | if (instruction_->IsArrayGet()) { |
| 910 | // Compute the actual memory offset and store it in `index`. |
| 911 | Register index_reg = index_.AsRegister<Register>(); |
| 912 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 913 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 914 | // We are about to change the value of `index_reg` (see the |
| 915 | // calls to art::mips::MipsAssembler::Sll and |
| 916 | // art::mips::MipsAssembler::Addiu32 below), but it has |
| 917 | // not been saved by the previous call to |
| 918 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 919 | // callee-save register -- |
| 920 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 921 | // callee-save registers, as it has been designed with the |
| 922 | // assumption that callee-save registers are supposed to be |
| 923 | // handled by the called function. So, as a callee-save |
| 924 | // register, `index_reg` _would_ eventually be saved onto |
| 925 | // the stack, but it would be too late: we would have |
| 926 | // changed its value earlier. Therefore, we manually save |
| 927 | // it here into another freely available register, |
| 928 | // `free_reg`, chosen of course among the caller-save |
| 929 | // registers (as a callee-save `free_reg` register would |
| 930 | // exhibit the same problem). |
| 931 | // |
| 932 | // Note we could have requested a temporary register from |
| 933 | // the register allocator instead; but we prefer not to, as |
| 934 | // this is a slow path, and we know we can find a |
| 935 | // caller-save register that is available. |
| 936 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 937 | __ Move(free_reg, index_reg); |
| 938 | index_reg = free_reg; |
| 939 | index = Location::RegisterLocation(index_reg); |
| 940 | } else { |
| 941 | // The initial register stored in `index_` has already been |
| 942 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 943 | // (as it is not a callee-save register), so we can freely |
| 944 | // use it. |
| 945 | } |
| 946 | // Shifting the index value contained in `index_reg` by the scale |
| 947 | // factor (2) cannot overflow in practice, as the runtime is |
| 948 | // unable to allocate object arrays with a size larger than |
| 949 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 950 | __ Sll(index_reg, index_reg, TIMES_4); |
| 951 | static_assert( |
| 952 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 953 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 954 | __ Addiu32(index_reg, index_reg, offset_); |
| 955 | } else { |
| 956 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 957 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 958 | // (as in the case of ArrayGet), as it is actually an offset |
| 959 | // to an object field within an object. |
| 960 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 961 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 962 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 963 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 964 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 965 | DCHECK_EQ(offset_, 0U); |
| 966 | DCHECK(index_.IsRegisterPair()); |
| 967 | // UnsafeGet's offset location is a register pair, the low |
| 968 | // part contains the correct offset. |
| 969 | index = index_.ToLow(); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | // We're moving two or three locations to locations that could |
| 974 | // overlap, so we need a parallel move resolver. |
| 975 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 976 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 977 | parallel_move.AddMove(ref_, |
| 978 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 979 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 980 | nullptr); |
| 981 | parallel_move.AddMove(obj_, |
| 982 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 983 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 984 | nullptr); |
| 985 | if (index.IsValid()) { |
| 986 | parallel_move.AddMove(index, |
| 987 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 988 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 989 | nullptr); |
| 990 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 991 | } else { |
| 992 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 993 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 994 | } |
| 995 | mips_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 996 | instruction_, |
| 997 | instruction_->GetDexPc(), |
| 998 | this); |
| 999 | CheckEntrypointTypes< |
| 1000 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1001 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1002 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 1003 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1004 | |
| 1005 | RestoreLiveRegisters(codegen, locations); |
| 1006 | __ B(GetExitLabel()); |
| 1007 | } |
| 1008 | |
| 1009 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathMIPS"; } |
| 1010 | |
| 1011 | private: |
| 1012 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1013 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1014 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1015 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1016 | if (i != ref && |
| 1017 | i != obj && |
| 1018 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 1019 | !codegen->IsBlockedCoreRegister(i)) { |
| 1020 | return static_cast<Register>(i); |
| 1021 | } |
| 1022 | } |
| 1023 | // We shall never fail to find a free caller-save register, as |
| 1024 | // there are more than two core caller-save registers on MIPS |
| 1025 | // (meaning it is possible to find one which is different from |
| 1026 | // `ref` and `obj`). |
| 1027 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1028 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1029 | UNREACHABLE(); |
| 1030 | } |
| 1031 | |
| 1032 | const Location out_; |
| 1033 | const Location ref_; |
| 1034 | const Location obj_; |
| 1035 | const uint32_t offset_; |
| 1036 | // An additional location containing an index to an array. |
| 1037 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1038 | // UnsafeGetObjectVolatile intrinsics. |
| 1039 | const Location index_; |
| 1040 | |
| 1041 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS); |
| 1042 | }; |
| 1043 | |
| 1044 | // Slow path generating a read barrier for a GC root. |
| 1045 | class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS { |
| 1046 | public: |
| 1047 | ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root) |
| 1048 | : SlowPathCodeMIPS(instruction), out_(out), root_(root) { |
| 1049 | DCHECK(kEmitCompilerReadBarrier); |
| 1050 | } |
| 1051 | |
| 1052 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1053 | LocationSummary* locations = instruction_->GetLocations(); |
| 1054 | Register reg_out = out_.AsRegister<Register>(); |
| 1055 | DCHECK(locations->CanCall()); |
| 1056 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 1057 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1058 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1059 | << instruction_->DebugName(); |
| 1060 | |
| 1061 | __ Bind(GetEntryLabel()); |
| 1062 | SaveLiveRegisters(codegen, locations); |
| 1063 | |
| 1064 | InvokeRuntimeCallingConvention calling_convention; |
| 1065 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1066 | mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1067 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1068 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1069 | mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1070 | instruction_, |
| 1071 | instruction_->GetDexPc(), |
| 1072 | this); |
| 1073 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1074 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1075 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 1076 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1077 | |
| 1078 | RestoreLiveRegisters(codegen, locations); |
| 1079 | __ B(GetExitLabel()); |
| 1080 | } |
| 1081 | |
| 1082 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS"; } |
| 1083 | |
| 1084 | private: |
| 1085 | const Location out_; |
| 1086 | const Location root_; |
| 1087 | |
| 1088 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS); |
| 1089 | }; |
| 1090 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1091 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 1092 | const MipsInstructionSetFeatures& isa_features, |
| 1093 | const CompilerOptions& compiler_options, |
| 1094 | OptimizingCompilerStats* stats) |
| 1095 | : CodeGenerator(graph, |
| 1096 | kNumberOfCoreRegisters, |
| 1097 | kNumberOfFRegisters, |
| 1098 | kNumberOfRegisterPairs, |
| 1099 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1100 | arraysize(kCoreCalleeSaves)), |
| 1101 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1102 | arraysize(kFpuCalleeSaves)), |
| 1103 | compiler_options, |
| 1104 | stats), |
| 1105 | block_labels_(nullptr), |
| 1106 | location_builder_(graph, this), |
| 1107 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1108 | move_resolver_(graph->GetAllocator(), this), |
| 1109 | assembler_(graph->GetAllocator(), &isa_features), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1110 | isa_features_(isa_features), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1111 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1112 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1113 | pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1114 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1115 | pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1116 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1117 | pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1118 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1119 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1120 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1121 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1122 | // Save RA (containing the return address) to mimic Quick. |
| 1123 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 1124 | } |
| 1125 | |
| 1126 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1127 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1128 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1129 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1130 | |
| 1131 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 1132 | // Ensure that we fix up branches. |
| 1133 | __ FinalizeCode(); |
| 1134 | |
| 1135 | // Adjust native pc offsets in stack maps. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1136 | StackMapStream* stack_map_stream = GetStackMapStream(); |
| 1137 | 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] | 1138 | uint32_t old_position = |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1139 | stack_map_stream->GetStackMap(i).native_pc_code_offset.Uint32Value(InstructionSet::kMips); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1140 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1141 | DCHECK_GE(new_position, old_position); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1142 | stack_map_stream->SetStackMapNativePcOffset(i, new_position); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | // Adjust pc offsets for the disassembly information. |
| 1146 | if (disasm_info_ != nullptr) { |
| 1147 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1148 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1149 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1150 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1151 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1152 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1153 | } |
| 1154 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1155 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1156 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | CodeGenerator::Finalize(allocator); |
| 1161 | } |
| 1162 | |
| 1163 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 1164 | return codegen_->GetAssembler(); |
| 1165 | } |
| 1166 | |
| 1167 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 1168 | DCHECK_LT(index, moves_.size()); |
| 1169 | MoveOperands* move = moves_[index]; |
| 1170 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1171 | } |
| 1172 | |
| 1173 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 1174 | DCHECK_LT(index, moves_.size()); |
| 1175 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1176 | DataType::Type type = move->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1177 | Location loc1 = move->GetDestination(); |
| 1178 | Location loc2 = move->GetSource(); |
| 1179 | |
| 1180 | DCHECK(!loc1.IsConstant()); |
| 1181 | DCHECK(!loc2.IsConstant()); |
| 1182 | |
| 1183 | if (loc1.Equals(loc2)) { |
| 1184 | return; |
| 1185 | } |
| 1186 | |
| 1187 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 1188 | // Swap 2 GPRs. |
| 1189 | Register r1 = loc1.AsRegister<Register>(); |
| 1190 | Register r2 = loc2.AsRegister<Register>(); |
| 1191 | __ Move(TMP, r2); |
| 1192 | __ Move(r2, r1); |
| 1193 | __ Move(r1, TMP); |
| 1194 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
| 1195 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 1196 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1197 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1198 | __ MovS(FTMP, f2); |
| 1199 | __ MovS(f2, f1); |
| 1200 | __ MovS(f1, FTMP); |
| 1201 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1202 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1203 | __ MovD(FTMP, f2); |
| 1204 | __ MovD(f2, f1); |
| 1205 | __ MovD(f1, FTMP); |
| 1206 | } |
| 1207 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 1208 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 1209 | // Swap FPR and GPR. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1210 | DCHECK_EQ(type, DataType::Type::kFloat32); // Can only swap a float. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1211 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1212 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1213 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1214 | __ Move(TMP, r2); |
| 1215 | __ Mfc1(r2, f1); |
| 1216 | __ Mtc1(TMP, f1); |
| 1217 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 1218 | // Swap 2 GPR register pairs. |
| 1219 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 1220 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 1221 | __ Move(TMP, r2); |
| 1222 | __ Move(r2, r1); |
| 1223 | __ Move(r1, TMP); |
| 1224 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 1225 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 1226 | __ Move(TMP, r2); |
| 1227 | __ Move(r2, r1); |
| 1228 | __ Move(r1, TMP); |
| 1229 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 1230 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 1231 | // Swap FPR and GPR register pair. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1232 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1233 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1234 | : loc2.AsFpuRegister<FRegister>(); |
| 1235 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1236 | : loc2.AsRegisterPairLow<Register>(); |
| 1237 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1238 | : loc2.AsRegisterPairHigh<Register>(); |
| 1239 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 1240 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 1241 | // unpredictable and the following mfch1 will fail. |
| 1242 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1243 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1244 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1245 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1246 | __ Move(r2_l, TMP); |
| 1247 | __ Move(r2_h, AT); |
| 1248 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 1249 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 1250 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 1251 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1252 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 1253 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1254 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 1255 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1256 | __ Move(TMP, reg); |
| 1257 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 1258 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 1259 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 1260 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 1261 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1262 | : loc2.AsRegisterPairLow<Register>(); |
| 1263 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1264 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1265 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1266 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 1267 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 1268 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1269 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1270 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 1271 | __ Move(TMP, reg_h); |
| 1272 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 1273 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1274 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 1275 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1276 | : loc2.AsFpuRegister<FRegister>(); |
| 1277 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1278 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1279 | __ MovS(FTMP, reg); |
| 1280 | __ LoadSFromOffset(reg, SP, offset); |
| 1281 | __ StoreSToOffset(FTMP, SP, offset); |
| 1282 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1283 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1284 | __ MovD(FTMP, reg); |
| 1285 | __ LoadDFromOffset(reg, SP, offset); |
| 1286 | __ StoreDToOffset(FTMP, SP, offset); |
| 1287 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1288 | } else { |
| 1289 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 1294 | __ Pop(static_cast<Register>(reg)); |
| 1295 | } |
| 1296 | |
| 1297 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 1298 | __ Push(static_cast<Register>(reg)); |
| 1299 | } |
| 1300 | |
| 1301 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 1302 | // Allocate a scratch register other than TMP, if available. |
| 1303 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1304 | // automatically unspilled when the scratch scope object is destroyed). |
| 1305 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1306 | // 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] | 1307 | int stack_offset = ensure_scratch.IsSpilled() ? kStackAlignment : 0; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1308 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 1309 | __ LoadFromOffset(kLoadWord, |
| 1310 | Register(ensure_scratch.GetRegister()), |
| 1311 | SP, |
| 1312 | index1 + stack_offset); |
| 1313 | __ LoadFromOffset(kLoadWord, |
| 1314 | TMP, |
| 1315 | SP, |
| 1316 | index2 + stack_offset); |
| 1317 | __ StoreToOffset(kStoreWord, |
| 1318 | Register(ensure_scratch.GetRegister()), |
| 1319 | SP, |
| 1320 | index2 + stack_offset); |
| 1321 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 1322 | } |
| 1323 | } |
| 1324 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1325 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 1326 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1327 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1328 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 1329 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 1330 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 1331 | // within the stack frame. |
| 1332 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 1333 | core_spill_mask_ |= (1 << ZERO); |
| 1334 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1338 | // 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] | 1339 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 1340 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 1341 | // 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] | 1342 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1345 | static dwarf::Reg DWARFReg(Register reg) { |
| 1346 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 1347 | } |
| 1348 | |
| 1349 | // TODO: mapping of floating-point registers to DWARF. |
| 1350 | |
| 1351 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 1352 | __ Bind(&frame_entry_label_); |
| 1353 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1354 | bool do_overflow_check = |
| 1355 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips) || !IsLeafMethod(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1356 | |
| 1357 | if (do_overflow_check) { |
| 1358 | __ LoadFromOffset(kLoadWord, |
| 1359 | ZERO, |
| 1360 | SP, |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1361 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1362 | RecordPcInfo(nullptr, 0); |
| 1363 | } |
| 1364 | |
| 1365 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1366 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 1367 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 1368 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1369 | return; |
| 1370 | } |
| 1371 | |
| 1372 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1373 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips)) { |
| 1374 | LOG(FATAL) << "Stack frame larger than " |
| 1375 | << GetStackOverflowReservedBytes(InstructionSet::kMips) << " bytes"; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1379 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1380 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1381 | __ IncreaseFrameSize(ofs); |
| 1382 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1383 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1384 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1385 | mask ^= 1u << reg; |
| 1386 | ofs -= kMipsWordSize; |
| 1387 | // The ZERO register is only included for alignment. |
| 1388 | if (reg != ZERO) { |
| 1389 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1390 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1391 | } |
| 1392 | } |
| 1393 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1394 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1395 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1396 | mask ^= 1u << reg; |
| 1397 | ofs -= kMipsDoublewordSize; |
| 1398 | __ StoreDToOffset(reg, SP, ofs); |
| 1399 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1400 | } |
| 1401 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1402 | // Save the current method if we need it. Note that we do not |
| 1403 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1404 | // in the SSA graph. |
| 1405 | if (RequiresCurrentMethod()) { |
| 1406 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 1407 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1408 | |
| 1409 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1410 | // Initialize should deoptimize flag to 0. |
| 1411 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1412 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 1416 | __ cfi().RememberState(); |
| 1417 | |
| 1418 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1419 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1420 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1421 | // For better instruction scheduling restore RA before other registers. |
| 1422 | uint32_t ofs = GetFrameSize(); |
| 1423 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1424 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1425 | mask ^= 1u << reg; |
| 1426 | ofs -= kMipsWordSize; |
| 1427 | // The ZERO register is only included for alignment. |
| 1428 | if (reg != ZERO) { |
| 1429 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1430 | __ cfi().Restore(DWARFReg(reg)); |
| 1431 | } |
| 1432 | } |
| 1433 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1434 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1435 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1436 | mask ^= 1u << reg; |
| 1437 | ofs -= kMipsDoublewordSize; |
| 1438 | __ LoadDFromOffset(reg, SP, ofs); |
| 1439 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 1440 | } |
| 1441 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1442 | size_t frame_size = GetFrameSize(); |
| 1443 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 1444 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 1445 | bool reordering = __ SetReorder(false); |
| 1446 | if (exchange) { |
| 1447 | __ Jr(RA); |
| 1448 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 1449 | } else { |
| 1450 | __ DecreaseFrameSize(frame_size); |
| 1451 | __ Jr(RA); |
| 1452 | __ Nop(); // In delay slot. |
| 1453 | } |
| 1454 | __ SetReorder(reordering); |
| 1455 | } else { |
| 1456 | __ Jr(RA); |
| 1457 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1458 | } |
| 1459 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1460 | __ cfi().RestoreState(); |
| 1461 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1462 | } |
| 1463 | |
| 1464 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 1465 | __ Bind(GetLabelOf(block)); |
| 1466 | } |
| 1467 | |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1468 | VectorRegister VectorRegisterFrom(Location location) { |
| 1469 | DCHECK(location.IsFpuRegister()); |
| 1470 | return static_cast<VectorRegister>(location.AsFpuRegister<FRegister>()); |
| 1471 | } |
| 1472 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1473 | void CodeGeneratorMIPS::MoveLocation(Location destination, |
| 1474 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1475 | DataType::Type dst_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1476 | if (source.Equals(destination)) { |
| 1477 | return; |
| 1478 | } |
| 1479 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1480 | if (source.IsConstant()) { |
| 1481 | MoveConstant(destination, source.GetConstant()); |
| 1482 | } else { |
| 1483 | if (destination.IsRegister()) { |
| 1484 | if (source.IsRegister()) { |
| 1485 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 1486 | } else if (source.IsFpuRegister()) { |
| 1487 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 1488 | } else { |
| 1489 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1490 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1491 | } |
| 1492 | } else if (destination.IsRegisterPair()) { |
| 1493 | if (source.IsRegisterPair()) { |
| 1494 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 1495 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 1496 | } else if (source.IsFpuRegister()) { |
| 1497 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 1498 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 1499 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 1500 | __ Mfc1(dst_low, src); |
| 1501 | __ MoveFromFpuHigh(dst_high, src); |
| 1502 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1503 | DCHECK(source.IsDoubleStackSlot()) |
| 1504 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1505 | int32_t off = source.GetStackIndex(); |
| 1506 | Register r = destination.AsRegisterPairLow<Register>(); |
| 1507 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 1508 | } |
| 1509 | } else if (destination.IsFpuRegister()) { |
| 1510 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1511 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1512 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 1513 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1514 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1515 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 1516 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 1517 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 1518 | __ Mtc1(src_low, dst); |
| 1519 | __ MoveToFpuHigh(src_high, dst); |
| 1520 | } else if (source.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1521 | if (GetGraph()->HasSIMD()) { |
| 1522 | __ MoveV(VectorRegisterFrom(destination), |
| 1523 | VectorRegisterFrom(source)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1524 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1525 | if (DataType::Is64BitType(dst_type)) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1526 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1527 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1528 | DCHECK_EQ(dst_type, DataType::Type::kFloat32); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1529 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1530 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1531 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1532 | } else if (source.IsSIMDStackSlot()) { |
| 1533 | __ LoadQFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1534 | } else if (source.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1535 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1536 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1537 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1538 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1539 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1540 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1541 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1542 | } else if (destination.IsSIMDStackSlot()) { |
| 1543 | if (source.IsFpuRegister()) { |
| 1544 | __ StoreQToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 1545 | } else { |
| 1546 | DCHECK(source.IsSIMDStackSlot()); |
| 1547 | __ LoadQFromOffset(FTMP, SP, source.GetStackIndex()); |
| 1548 | __ StoreQToOffset(FTMP, SP, destination.GetStackIndex()); |
| 1549 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1550 | } else if (destination.IsDoubleStackSlot()) { |
| 1551 | int32_t dst_offset = destination.GetStackIndex(); |
| 1552 | if (source.IsRegisterPair()) { |
| 1553 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, dst_offset); |
| 1554 | } else if (source.IsFpuRegister()) { |
| 1555 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1556 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1557 | DCHECK(source.IsDoubleStackSlot()) |
| 1558 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1559 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1560 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1561 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 1562 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset + 4); |
| 1563 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1564 | } else { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1565 | DCHECK(destination.IsStackSlot()) << destination; |
| 1566 | int32_t dst_offset = destination.GetStackIndex(); |
| 1567 | if (source.IsRegister()) { |
| 1568 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, dst_offset); |
| 1569 | } else if (source.IsFpuRegister()) { |
| 1570 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1571 | } else { |
| 1572 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1573 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1574 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1575 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1576 | } |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 1581 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 1582 | // Move 32 bit constant. |
| 1583 | int32_t value = GetInt32ValueOf(c); |
| 1584 | if (destination.IsRegister()) { |
| 1585 | Register dst = destination.AsRegister<Register>(); |
| 1586 | __ LoadConst32(dst, value); |
| 1587 | } else { |
| 1588 | DCHECK(destination.IsStackSlot()) |
| 1589 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1590 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1591 | } |
| 1592 | } else if (c->IsLongConstant()) { |
| 1593 | // Move 64 bit constant. |
| 1594 | int64_t value = GetInt64ValueOf(c); |
| 1595 | if (destination.IsRegisterPair()) { |
| 1596 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 1597 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 1598 | __ LoadConst64(r_h, r_l, value); |
| 1599 | } else { |
| 1600 | DCHECK(destination.IsDoubleStackSlot()) |
| 1601 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1602 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1603 | } |
| 1604 | } else if (c->IsFloatConstant()) { |
| 1605 | // Move 32 bit float constant. |
| 1606 | int32_t value = GetInt32ValueOf(c); |
| 1607 | if (destination.IsFpuRegister()) { |
| 1608 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 1609 | } else { |
| 1610 | DCHECK(destination.IsStackSlot()) |
| 1611 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1612 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1613 | } |
| 1614 | } else { |
| 1615 | // Move 64 bit double constant. |
| 1616 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 1617 | int64_t value = GetInt64ValueOf(c); |
| 1618 | if (destination.IsFpuRegister()) { |
| 1619 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 1620 | __ LoadDConst64(fd, value, TMP); |
| 1621 | } else { |
| 1622 | DCHECK(destination.IsDoubleStackSlot()) |
| 1623 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1624 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 1630 | DCHECK(destination.IsRegister()); |
| 1631 | Register dst = destination.AsRegister<Register>(); |
| 1632 | __ LoadConst32(dst, value); |
| 1633 | } |
| 1634 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1635 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1636 | if (location.IsRegister()) { |
| 1637 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 1638 | } else if (location.IsRegisterPair()) { |
| 1639 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1640 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1641 | } else { |
| 1642 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1643 | } |
| 1644 | } |
| 1645 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1646 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1647 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 1648 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1649 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1650 | for (const PcRelativePatchInfo& info : infos) { |
| 1651 | const DexFile& dex_file = info.target_dex_file; |
| 1652 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1653 | DCHECK(info.label.IsBound()); |
| 1654 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1655 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 1656 | // the assembler's base label used for PC-relative addressing. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1657 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1658 | uint32_t pc_rel_offset = info_high.pc_rel_label.IsBound() |
| 1659 | ? __ GetLabelLocation(&info_high.pc_rel_label) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1660 | : __ GetPcRelBaseLabelLocation(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1661 | 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] | 1662 | } |
| 1663 | } |
| 1664 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1665 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1666 | DCHECK(linker_patches->empty()); |
| 1667 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1668 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1669 | method_bss_entry_patches_.size() + |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1670 | pc_relative_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1671 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1672 | pc_relative_string_patches_.size() + |
| 1673 | string_bss_entry_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1674 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1675 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1676 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1677 | pc_relative_method_patches_, linker_patches); |
| 1678 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1679 | pc_relative_type_patches_, linker_patches); |
| 1680 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 1681 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1682 | } else { |
| 1683 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1684 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 1685 | pc_relative_type_patches_, linker_patches); |
| 1686 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 1687 | pc_relative_string_patches_, linker_patches); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1688 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1689 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1690 | method_bss_entry_patches_, linker_patches); |
| 1691 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1692 | type_bss_entry_patches_, linker_patches); |
| 1693 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1694 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1695 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1698 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1699 | MethodReference target_method, |
| 1700 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1701 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1702 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1703 | info_high, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1704 | &pc_relative_method_patches_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1707 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1708 | MethodReference target_method, |
| 1709 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1710 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1711 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1712 | info_high, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1713 | &method_bss_entry_patches_); |
| 1714 | } |
| 1715 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1716 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1717 | const DexFile& dex_file, |
| 1718 | dex::TypeIndex type_index, |
| 1719 | const PcRelativePatchInfo* info_high) { |
| 1720 | 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] | 1721 | } |
| 1722 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1723 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1724 | const DexFile& dex_file, |
| 1725 | dex::TypeIndex type_index, |
| 1726 | const PcRelativePatchInfo* info_high) { |
| 1727 | 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] | 1728 | } |
| 1729 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1730 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1731 | const DexFile& dex_file, |
| 1732 | dex::StringIndex string_index, |
| 1733 | const PcRelativePatchInfo* info_high) { |
| 1734 | 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] | 1735 | } |
| 1736 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1737 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch( |
| 1738 | const DexFile& dex_file, |
| 1739 | dex::StringIndex string_index, |
| 1740 | const PcRelativePatchInfo* info_high) { |
| 1741 | return NewPcRelativePatch(dex_file, string_index.index_, info_high, &string_bss_entry_patches_); |
| 1742 | } |
| 1743 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1744 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1745 | const DexFile& dex_file, |
| 1746 | uint32_t offset_or_index, |
| 1747 | const PcRelativePatchInfo* info_high, |
| 1748 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1749 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1750 | return &patches->back(); |
| 1751 | } |
| 1752 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1753 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1754 | return map->GetOrCreate( |
| 1755 | value, |
| 1756 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1757 | } |
| 1758 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1759 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1760 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1763 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1764 | Register out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1765 | Register base) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1766 | DCHECK(!info_high->patch_info_high); |
Alexey Frunze | 6079dca | 2017-05-28 19:10:28 -0700 | [diff] [blame] | 1767 | DCHECK_NE(out, base); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1768 | bool reordering = __ SetReorder(false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1769 | if (GetInstructionSetFeatures().IsR6()) { |
| 1770 | DCHECK_EQ(base, ZERO); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1771 | __ Bind(&info_high->label); |
| 1772 | __ Bind(&info_high->pc_rel_label); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1773 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1774 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1775 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1776 | } else { |
| 1777 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1778 | if (base == ZERO) { |
| 1779 | // Generate a dummy PC-relative call to obtain PC. |
| 1780 | __ Nal(); |
| 1781 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1782 | __ Bind(&info_high->label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1783 | __ Lui(out, /* placeholder */ 0x1234); |
| 1784 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1785 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1786 | if (base == ZERO) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1787 | __ Bind(&info_high->pc_rel_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1788 | } |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1789 | __ SetReorder(reordering); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1790 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1791 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1792 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1793 | // 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] | 1794 | // offset to `out` (e.g. lw, jialc, addiu). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1797 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch( |
| 1798 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1799 | dex::StringIndex string_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1800 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1801 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| 1802 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1803 | return &jit_string_patches_.back(); |
| 1804 | } |
| 1805 | |
| 1806 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch( |
| 1807 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1808 | dex::TypeIndex type_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1809 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1810 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| 1811 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1812 | return &jit_class_patches_.back(); |
| 1813 | } |
| 1814 | |
| 1815 | void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code, |
| 1816 | const uint8_t* roots_data, |
| 1817 | const CodeGeneratorMIPS::JitPatchInfo& info, |
| 1818 | uint64_t index_in_table) const { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1819 | uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label); |
| 1820 | uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1821 | uintptr_t address = |
| 1822 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1823 | uint32_t addr32 = dchecked_integral_cast<uint32_t>(address); |
| 1824 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1825 | DCHECK_EQ(code[high_literal_offset + 0], 0x34); |
| 1826 | DCHECK_EQ(code[high_literal_offset + 1], 0x12); |
| 1827 | DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00); |
| 1828 | DCHECK_EQ(code[high_literal_offset + 3], 0x3C); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1829 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1830 | DCHECK_EQ(code[low_literal_offset + 0], 0x78); |
| 1831 | DCHECK_EQ(code[low_literal_offset + 1], 0x56); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1832 | addr32 += (addr32 & 0x8000) << 1; // Account for sign extension in "instr reg, reg, addr32_low". |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1833 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1834 | code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16); |
| 1835 | code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1836 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1837 | code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0); |
| 1838 | code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1842 | for (const JitPatchInfo& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1843 | StringReference string_reference(&info.target_dex_file, dex::StringIndex(info.index)); |
| 1844 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1845 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1846 | } |
| 1847 | for (const JitPatchInfo& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1848 | TypeReference type_reference(&info.target_dex_file, dex::TypeIndex(info.index)); |
| 1849 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1850 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1851 | } |
| 1852 | } |
| 1853 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1854 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1855 | Register value, |
| 1856 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1857 | MipsLabel done; |
| 1858 | Register card = AT; |
| 1859 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1860 | if (value_can_be_null) { |
| 1861 | __ Beqz(value, &done); |
| 1862 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1863 | __ LoadFromOffset(kLoadWord, |
| 1864 | card, |
| 1865 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1866 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1867 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1868 | __ Addu(temp, card, temp); |
| 1869 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1870 | if (value_can_be_null) { |
| 1871 | __ Bind(&done); |
| 1872 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1873 | } |
| 1874 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1875 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1876 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1877 | blocked_core_registers_[ZERO] = true; |
| 1878 | blocked_core_registers_[K0] = true; |
| 1879 | blocked_core_registers_[K1] = true; |
| 1880 | blocked_core_registers_[GP] = true; |
| 1881 | blocked_core_registers_[SP] = true; |
| 1882 | blocked_core_registers_[RA] = true; |
| 1883 | |
| 1884 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1885 | // (similar to how AT is used by MIPS assemblers). |
| 1886 | blocked_core_registers_[AT] = true; |
| 1887 | blocked_core_registers_[TMP] = true; |
| 1888 | blocked_fpu_registers_[FTMP] = true; |
| 1889 | |
| 1890 | // Reserve suspend and thread registers. |
| 1891 | blocked_core_registers_[S0] = true; |
| 1892 | blocked_core_registers_[TR] = true; |
| 1893 | |
| 1894 | // Reserve T9 for function calls |
| 1895 | blocked_core_registers_[T9] = true; |
| 1896 | |
| 1897 | // Reserve odd-numbered FPU registers. |
| 1898 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1899 | blocked_fpu_registers_[i] = true; |
| 1900 | } |
| 1901 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1902 | if (GetGraph()->IsDebuggable()) { |
| 1903 | // Stubs do not save callee-save floating point registers. If the graph |
| 1904 | // is debuggable, we need to deal with these registers differently. For |
| 1905 | // now, just block them. |
| 1906 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1907 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1908 | } |
| 1909 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1910 | } |
| 1911 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1912 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1913 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1914 | return kMipsWordSize; |
| 1915 | } |
| 1916 | |
| 1917 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1918 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1919 | return kMipsWordSize; |
| 1920 | } |
| 1921 | |
| 1922 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1923 | if (GetGraph()->HasSIMD()) { |
| 1924 | __ StoreQToOffset(FRegister(reg_id), SP, stack_index); |
| 1925 | } else { |
| 1926 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1927 | } |
| 1928 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1932 | if (GetGraph()->HasSIMD()) { |
| 1933 | __ LoadQFromOffset(FRegister(reg_id), SP, stack_index); |
| 1934 | } else { |
| 1935 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1936 | } |
| 1937 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1941 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1945 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1946 | } |
| 1947 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1948 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1949 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1950 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1951 | HInstruction* instruction, |
| 1952 | uint32_t dex_pc, |
| 1953 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1954 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1955 | GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(), |
| 1956 | IsDirectEntrypoint(entrypoint)); |
| 1957 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1958 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1963 | HInstruction* instruction, |
| 1964 | SlowPathCode* slow_path, |
| 1965 | bool direct) { |
| 1966 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1967 | GenerateInvokeRuntime(entry_point_offset, direct); |
| 1968 | } |
| 1969 | |
| 1970 | void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) { |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1971 | bool reordering = __ SetReorder(false); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1972 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1973 | __ Jalr(T9); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1974 | if (direct) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1975 | // Reserve argument space on stack (for $a0-$a3) for |
| 1976 | // entrypoints that directly reference native implementations. |
| 1977 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1978 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1979 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1980 | } else { |
| 1981 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1982 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1983 | __ SetReorder(reordering); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1987 | Register class_reg) { |
| 1988 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1989 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1990 | __ Blt(TMP, AT, slow_path->GetEntryLabel()); |
| 1991 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1992 | __ Sync(0); |
| 1993 | __ Bind(slow_path->GetExitLabel()); |
| 1994 | } |
| 1995 | |
| 1996 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1997 | __ Sync(0); // Only stype 0 is supported. |
| 1998 | } |
| 1999 | |
| 2000 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2001 | HBasicBlock* successor) { |
| 2002 | SuspendCheckSlowPathMIPS* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 2003 | down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath()); |
| 2004 | |
| 2005 | if (slow_path == nullptr) { |
| 2006 | slow_path = |
| 2007 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 2008 | instruction->SetSlowPath(slow_path); |
| 2009 | codegen_->AddSlowPath(slow_path); |
| 2010 | if (successor != nullptr) { |
| 2011 | DCHECK(successor->IsLoopHeader()); |
| 2012 | } |
| 2013 | } else { |
| 2014 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2015 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2016 | |
| 2017 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2018 | TMP, |
| 2019 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2020 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2021 | if (successor == nullptr) { |
| 2022 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 2023 | __ Bind(slow_path->GetReturnLabel()); |
| 2024 | } else { |
| 2025 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 2026 | __ B(slow_path->GetEntryLabel()); |
| 2027 | // slow_path will return to GetLabelOf(successor). |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 2032 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2033 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2034 | assembler_(codegen->GetAssembler()), |
| 2035 | codegen_(codegen) {} |
| 2036 | |
| 2037 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 2038 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2039 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2040 | DataType::Type type = instruction->GetResultType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2041 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2042 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2043 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2044 | HInstruction* right = instruction->InputAt(1); |
| 2045 | bool can_use_imm = false; |
| 2046 | if (right->IsConstant()) { |
| 2047 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 2048 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 2049 | can_use_imm = IsUint<16>(imm); |
| 2050 | } else if (instruction->IsAdd()) { |
| 2051 | can_use_imm = IsInt<16>(imm); |
| 2052 | } else { |
| 2053 | DCHECK(instruction->IsSub()); |
| 2054 | can_use_imm = IsInt<16>(-imm); |
| 2055 | } |
| 2056 | } |
| 2057 | if (can_use_imm) |
| 2058 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 2059 | else |
| 2060 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2061 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2062 | break; |
| 2063 | } |
| 2064 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2065 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2066 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2067 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2068 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2069 | break; |
| 2070 | } |
| 2071 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2072 | case DataType::Type::kFloat32: |
| 2073 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2074 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2075 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2076 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2077 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2078 | break; |
| 2079 | |
| 2080 | default: |
| 2081 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2086 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2087 | LocationSummary* locations = instruction->GetLocations(); |
| 2088 | |
| 2089 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2090 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2091 | Register dst = locations->Out().AsRegister<Register>(); |
| 2092 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2093 | Location rhs_location = locations->InAt(1); |
| 2094 | |
| 2095 | Register rhs_reg = ZERO; |
| 2096 | int32_t rhs_imm = 0; |
| 2097 | bool use_imm = rhs_location.IsConstant(); |
| 2098 | if (use_imm) { |
| 2099 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2100 | } else { |
| 2101 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2102 | } |
| 2103 | |
| 2104 | if (instruction->IsAnd()) { |
| 2105 | if (use_imm) |
| 2106 | __ Andi(dst, lhs, rhs_imm); |
| 2107 | else |
| 2108 | __ And(dst, lhs, rhs_reg); |
| 2109 | } else if (instruction->IsOr()) { |
| 2110 | if (use_imm) |
| 2111 | __ Ori(dst, lhs, rhs_imm); |
| 2112 | else |
| 2113 | __ Or(dst, lhs, rhs_reg); |
| 2114 | } else if (instruction->IsXor()) { |
| 2115 | if (use_imm) |
| 2116 | __ Xori(dst, lhs, rhs_imm); |
| 2117 | else |
| 2118 | __ Xor(dst, lhs, rhs_reg); |
| 2119 | } else if (instruction->IsAdd()) { |
| 2120 | if (use_imm) |
| 2121 | __ Addiu(dst, lhs, rhs_imm); |
| 2122 | else |
| 2123 | __ Addu(dst, lhs, rhs_reg); |
| 2124 | } else { |
| 2125 | DCHECK(instruction->IsSub()); |
| 2126 | if (use_imm) |
| 2127 | __ Addiu(dst, lhs, -rhs_imm); |
| 2128 | else |
| 2129 | __ Subu(dst, lhs, rhs_reg); |
| 2130 | } |
| 2131 | break; |
| 2132 | } |
| 2133 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2134 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2135 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2136 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2137 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2138 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2139 | Location rhs_location = locations->InAt(1); |
| 2140 | bool use_imm = rhs_location.IsConstant(); |
| 2141 | if (!use_imm) { |
| 2142 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2143 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2144 | if (instruction->IsAnd()) { |
| 2145 | __ And(dst_low, lhs_low, rhs_low); |
| 2146 | __ And(dst_high, lhs_high, rhs_high); |
| 2147 | } else if (instruction->IsOr()) { |
| 2148 | __ Or(dst_low, lhs_low, rhs_low); |
| 2149 | __ Or(dst_high, lhs_high, rhs_high); |
| 2150 | } else if (instruction->IsXor()) { |
| 2151 | __ Xor(dst_low, lhs_low, rhs_low); |
| 2152 | __ Xor(dst_high, lhs_high, rhs_high); |
| 2153 | } else if (instruction->IsAdd()) { |
| 2154 | if (lhs_low == rhs_low) { |
| 2155 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 2156 | __ Slt(TMP, lhs_low, ZERO); |
| 2157 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2158 | } else { |
| 2159 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2160 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 2161 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 2162 | } |
| 2163 | __ Addu(dst_high, lhs_high, rhs_high); |
| 2164 | __ Addu(dst_high, dst_high, TMP); |
| 2165 | } else { |
| 2166 | DCHECK(instruction->IsSub()); |
| 2167 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2168 | __ Subu(dst_low, lhs_low, rhs_low); |
| 2169 | __ Subu(dst_high, lhs_high, rhs_high); |
| 2170 | __ Subu(dst_high, dst_high, TMP); |
| 2171 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2172 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2173 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2174 | if (instruction->IsOr()) { |
| 2175 | uint32_t low = Low32Bits(value); |
| 2176 | uint32_t high = High32Bits(value); |
| 2177 | if (IsUint<16>(low)) { |
| 2178 | if (dst_low != lhs_low || low != 0) { |
| 2179 | __ Ori(dst_low, lhs_low, low); |
| 2180 | } |
| 2181 | } else { |
| 2182 | __ LoadConst32(TMP, low); |
| 2183 | __ Or(dst_low, lhs_low, TMP); |
| 2184 | } |
| 2185 | if (IsUint<16>(high)) { |
| 2186 | if (dst_high != lhs_high || high != 0) { |
| 2187 | __ Ori(dst_high, lhs_high, high); |
| 2188 | } |
| 2189 | } else { |
| 2190 | if (high != low) { |
| 2191 | __ LoadConst32(TMP, high); |
| 2192 | } |
| 2193 | __ Or(dst_high, lhs_high, TMP); |
| 2194 | } |
| 2195 | } else if (instruction->IsXor()) { |
| 2196 | uint32_t low = Low32Bits(value); |
| 2197 | uint32_t high = High32Bits(value); |
| 2198 | if (IsUint<16>(low)) { |
| 2199 | if (dst_low != lhs_low || low != 0) { |
| 2200 | __ Xori(dst_low, lhs_low, low); |
| 2201 | } |
| 2202 | } else { |
| 2203 | __ LoadConst32(TMP, low); |
| 2204 | __ Xor(dst_low, lhs_low, TMP); |
| 2205 | } |
| 2206 | if (IsUint<16>(high)) { |
| 2207 | if (dst_high != lhs_high || high != 0) { |
| 2208 | __ Xori(dst_high, lhs_high, high); |
| 2209 | } |
| 2210 | } else { |
| 2211 | if (high != low) { |
| 2212 | __ LoadConst32(TMP, high); |
| 2213 | } |
| 2214 | __ Xor(dst_high, lhs_high, TMP); |
| 2215 | } |
| 2216 | } else if (instruction->IsAnd()) { |
| 2217 | uint32_t low = Low32Bits(value); |
| 2218 | uint32_t high = High32Bits(value); |
| 2219 | if (IsUint<16>(low)) { |
| 2220 | __ Andi(dst_low, lhs_low, low); |
| 2221 | } else if (low != 0xFFFFFFFF) { |
| 2222 | __ LoadConst32(TMP, low); |
| 2223 | __ And(dst_low, lhs_low, TMP); |
| 2224 | } else if (dst_low != lhs_low) { |
| 2225 | __ Move(dst_low, lhs_low); |
| 2226 | } |
| 2227 | if (IsUint<16>(high)) { |
| 2228 | __ Andi(dst_high, lhs_high, high); |
| 2229 | } else if (high != 0xFFFFFFFF) { |
| 2230 | if (high != low) { |
| 2231 | __ LoadConst32(TMP, high); |
| 2232 | } |
| 2233 | __ And(dst_high, lhs_high, TMP); |
| 2234 | } else if (dst_high != lhs_high) { |
| 2235 | __ Move(dst_high, lhs_high); |
| 2236 | } |
| 2237 | } else { |
| 2238 | if (instruction->IsSub()) { |
| 2239 | value = -value; |
| 2240 | } else { |
| 2241 | DCHECK(instruction->IsAdd()); |
| 2242 | } |
| 2243 | int32_t low = Low32Bits(value); |
| 2244 | int32_t high = High32Bits(value); |
| 2245 | if (IsInt<16>(low)) { |
| 2246 | if (dst_low != lhs_low || low != 0) { |
| 2247 | __ Addiu(dst_low, lhs_low, low); |
| 2248 | } |
| 2249 | if (low != 0) { |
| 2250 | __ Sltiu(AT, dst_low, low); |
| 2251 | } |
| 2252 | } else { |
| 2253 | __ LoadConst32(TMP, low); |
| 2254 | __ Addu(dst_low, lhs_low, TMP); |
| 2255 | __ Sltu(AT, dst_low, TMP); |
| 2256 | } |
| 2257 | if (IsInt<16>(high)) { |
| 2258 | if (dst_high != lhs_high || high != 0) { |
| 2259 | __ Addiu(dst_high, lhs_high, high); |
| 2260 | } |
| 2261 | } else { |
| 2262 | if (high != low) { |
| 2263 | __ LoadConst32(TMP, high); |
| 2264 | } |
| 2265 | __ Addu(dst_high, lhs_high, TMP); |
| 2266 | } |
| 2267 | if (low != 0) { |
| 2268 | __ Addu(dst_high, dst_high, AT); |
| 2269 | } |
| 2270 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2271 | } |
| 2272 | break; |
| 2273 | } |
| 2274 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2275 | case DataType::Type::kFloat32: |
| 2276 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2277 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2278 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2279 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2280 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2281 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2282 | __ AddS(dst, lhs, rhs); |
| 2283 | } else { |
| 2284 | __ AddD(dst, lhs, rhs); |
| 2285 | } |
| 2286 | } else { |
| 2287 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2288 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2289 | __ SubS(dst, lhs, rhs); |
| 2290 | } else { |
| 2291 | __ SubD(dst, lhs, rhs); |
| 2292 | } |
| 2293 | } |
| 2294 | break; |
| 2295 | } |
| 2296 | |
| 2297 | default: |
| 2298 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2303 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2304 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2305 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2306 | DataType::Type type = instr->GetResultType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2307 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2308 | case DataType::Type::kInt32: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2309 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2310 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2311 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2312 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2313 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2314 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2315 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2316 | locations->SetOut(Location::RequiresRegister()); |
| 2317 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2318 | default: |
| 2319 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 2324 | |
| 2325 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2326 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2327 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2328 | DataType::Type type = instr->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2329 | |
| 2330 | Location rhs_location = locations->InAt(1); |
| 2331 | bool use_imm = rhs_location.IsConstant(); |
| 2332 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 2333 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2334 | const uint32_t shift_mask = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2335 | (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2336 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2337 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 2338 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2339 | |
| 2340 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2341 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2342 | Register dst = locations->Out().AsRegister<Register>(); |
| 2343 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2344 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2345 | if (shift_value == 0) { |
| 2346 | if (dst != lhs) { |
| 2347 | __ Move(dst, lhs); |
| 2348 | } |
| 2349 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2350 | __ Sll(dst, lhs, shift_value); |
| 2351 | } else if (instr->IsShr()) { |
| 2352 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2353 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2354 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2355 | } else { |
| 2356 | if (has_ins_rotr) { |
| 2357 | __ Rotr(dst, lhs, shift_value); |
| 2358 | } else { |
| 2359 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 2360 | __ Srl(dst, lhs, shift_value); |
| 2361 | __ Or(dst, dst, TMP); |
| 2362 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2363 | } |
| 2364 | } else { |
| 2365 | if (instr->IsShl()) { |
| 2366 | __ Sllv(dst, lhs, rhs_reg); |
| 2367 | } else if (instr->IsShr()) { |
| 2368 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2369 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2370 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2371 | } else { |
| 2372 | if (has_ins_rotr) { |
| 2373 | __ Rotrv(dst, lhs, rhs_reg); |
| 2374 | } else { |
| 2375 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2376 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 2377 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 2378 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 2379 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 2380 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2381 | __ Sllv(TMP, lhs, TMP); |
| 2382 | __ Srlv(dst, lhs, rhs_reg); |
| 2383 | __ Or(dst, dst, TMP); |
| 2384 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | break; |
| 2388 | } |
| 2389 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2390 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2391 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2392 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2393 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2394 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2395 | if (use_imm) { |
| 2396 | if (shift_value == 0) { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 2397 | codegen_->MoveLocation(locations->Out(), locations->InAt(0), type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2398 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2399 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2400 | if (instr->IsShl()) { |
| 2401 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2402 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 2403 | __ Sll(dst_low, lhs_low, shift_value); |
| 2404 | } else if (instr->IsShr()) { |
| 2405 | __ Srl(dst_low, lhs_low, shift_value); |
| 2406 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2407 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2408 | } else if (instr->IsUShr()) { |
| 2409 | __ Srl(dst_low, lhs_low, shift_value); |
| 2410 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2411 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2412 | } else { |
| 2413 | __ Srl(dst_low, lhs_low, shift_value); |
| 2414 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2415 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2416 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2417 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2418 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2419 | if (instr->IsShl()) { |
| 2420 | __ Sll(dst_low, lhs_low, shift_value); |
| 2421 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 2422 | __ Sll(dst_high, lhs_high, shift_value); |
| 2423 | __ Or(dst_high, dst_high, TMP); |
| 2424 | } else if (instr->IsShr()) { |
| 2425 | __ Sra(dst_high, lhs_high, shift_value); |
| 2426 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2427 | __ Srl(dst_low, lhs_low, shift_value); |
| 2428 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2429 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2430 | __ Srl(dst_high, lhs_high, shift_value); |
| 2431 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2432 | __ Srl(dst_low, lhs_low, shift_value); |
| 2433 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2434 | } else { |
| 2435 | __ Srl(TMP, lhs_low, shift_value); |
| 2436 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 2437 | __ Or(dst_low, dst_low, TMP); |
| 2438 | __ Srl(TMP, lhs_high, shift_value); |
| 2439 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2440 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2441 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2442 | } |
| 2443 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2444 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2445 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2446 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2447 | __ Move(dst_low, ZERO); |
| 2448 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2449 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2450 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2451 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2452 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2453 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2454 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2455 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2456 | // 64-bit rotation by 32 is just a swap. |
| 2457 | __ Move(dst_low, lhs_high); |
| 2458 | __ Move(dst_high, lhs_low); |
| 2459 | } else { |
| 2460 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2461 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 2462 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 2463 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 2464 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2465 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2466 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 2467 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2468 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2469 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 2470 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2471 | __ Or(dst_high, dst_high, TMP); |
| 2472 | } |
| 2473 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2474 | } |
| 2475 | } |
| 2476 | } else { |
| 2477 | MipsLabel done; |
| 2478 | if (instr->IsShl()) { |
| 2479 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 2480 | __ Nor(AT, ZERO, rhs_reg); |
| 2481 | __ Srl(TMP, lhs_low, 1); |
| 2482 | __ Srlv(TMP, TMP, AT); |
| 2483 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 2484 | __ Or(dst_high, dst_high, TMP); |
| 2485 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 2486 | __ Beqz(TMP, &done); |
| 2487 | __ Move(dst_high, dst_low); |
| 2488 | __ Move(dst_low, ZERO); |
| 2489 | } else if (instr->IsShr()) { |
| 2490 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 2491 | __ Nor(AT, ZERO, rhs_reg); |
| 2492 | __ Sll(TMP, lhs_high, 1); |
| 2493 | __ Sllv(TMP, TMP, AT); |
| 2494 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2495 | __ Or(dst_low, dst_low, TMP); |
| 2496 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 2497 | __ Beqz(TMP, &done); |
| 2498 | __ Move(dst_low, dst_high); |
| 2499 | __ Sra(dst_high, dst_high, 31); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2500 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2501 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 2502 | __ Nor(AT, ZERO, rhs_reg); |
| 2503 | __ Sll(TMP, lhs_high, 1); |
| 2504 | __ Sllv(TMP, TMP, AT); |
| 2505 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2506 | __ Or(dst_low, dst_low, TMP); |
| 2507 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 2508 | __ Beqz(TMP, &done); |
| 2509 | __ Move(dst_low, dst_high); |
| 2510 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2511 | } else { |
| 2512 | __ Nor(AT, ZERO, rhs_reg); |
| 2513 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 2514 | __ Sll(dst_low, lhs_high, 1); |
| 2515 | __ Sllv(dst_low, dst_low, AT); |
| 2516 | __ Or(dst_low, dst_low, TMP); |
| 2517 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 2518 | __ Sll(dst_high, lhs_low, 1); |
| 2519 | __ Sllv(dst_high, dst_high, AT); |
| 2520 | __ Or(dst_high, dst_high, TMP); |
| 2521 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 2522 | __ Beqz(TMP, &done); |
| 2523 | __ Move(TMP, dst_high); |
| 2524 | __ Move(dst_high, dst_low); |
| 2525 | __ Move(dst_low, TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2526 | } |
| 2527 | __ Bind(&done); |
| 2528 | } |
| 2529 | break; |
| 2530 | } |
| 2531 | |
| 2532 | default: |
| 2533 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2534 | } |
| 2535 | } |
| 2536 | |
| 2537 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 2538 | HandleBinaryOp(instruction); |
| 2539 | } |
| 2540 | |
| 2541 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 2542 | HandleBinaryOp(instruction); |
| 2543 | } |
| 2544 | |
| 2545 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 2546 | HandleBinaryOp(instruction); |
| 2547 | } |
| 2548 | |
| 2549 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 2550 | HandleBinaryOp(instruction); |
| 2551 | } |
| 2552 | |
| 2553 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2554 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2555 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2556 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2557 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2558 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2559 | object_array_get_with_read_barrier |
| 2560 | ? LocationSummary::kCallOnSlowPath |
| 2561 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2562 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2563 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2564 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2565 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2566 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2567 | if (DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2568 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2569 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2570 | // The output overlaps in the case of an object array get with |
| 2571 | // read barriers enabled: we do not want the move to overwrite the |
| 2572 | // array's location, as we need it to emit the read barrier. |
| 2573 | locations->SetOut(Location::RequiresRegister(), |
| 2574 | object_array_get_with_read_barrier |
| 2575 | ? Location::kOutputOverlap |
| 2576 | : Location::kNoOutputOverlap); |
| 2577 | } |
| 2578 | // We need a temporary register for the read barrier marking slow |
| 2579 | // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier. |
| 2580 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2581 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2582 | ? !kBakerReadBarrierThunksEnableForFields |
| 2583 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2584 | if (temp_needed) { |
| 2585 | locations->AddTemp(Location::RequiresRegister()); |
| 2586 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2590 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 2591 | auto null_checker = [codegen, instruction]() { |
| 2592 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2593 | }; |
| 2594 | return null_checker; |
| 2595 | } |
| 2596 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2597 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 2598 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2599 | Location obj_loc = locations->InAt(0); |
| 2600 | Register obj = obj_loc.AsRegister<Register>(); |
| 2601 | Location out_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2602 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2603 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2604 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2605 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2606 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2607 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2608 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2609 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2610 | case DataType::Type::kBool: |
| 2611 | case DataType::Type::kUint8: { |
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(kLoadUnsignedByte, 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(kLoadUnsignedByte, 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::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2625 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2626 | if (index.IsConstant()) { |
| 2627 | size_t offset = |
| 2628 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2629 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2630 | } else { |
| 2631 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2632 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2633 | } |
| 2634 | break; |
| 2635 | } |
| 2636 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2637 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2638 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2639 | if (maybe_compressed_char_at) { |
| 2640 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2641 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 2642 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 2643 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2644 | "Expecting 0=compressed, 1=uncompressed"); |
| 2645 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2646 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2647 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2648 | if (maybe_compressed_char_at) { |
| 2649 | MipsLabel uncompressed_load, done; |
| 2650 | __ Bnez(TMP, &uncompressed_load); |
| 2651 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2652 | out, |
| 2653 | obj, |
| 2654 | data_offset + (const_index << TIMES_1)); |
| 2655 | __ B(&done); |
| 2656 | __ Bind(&uncompressed_load); |
| 2657 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2658 | out, |
| 2659 | obj, |
| 2660 | data_offset + (const_index << TIMES_2)); |
| 2661 | __ Bind(&done); |
| 2662 | } else { |
| 2663 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2664 | out, |
| 2665 | obj, |
| 2666 | data_offset + (const_index << TIMES_2), |
| 2667 | null_checker); |
| 2668 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2669 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2670 | Register index_reg = index.AsRegister<Register>(); |
| 2671 | if (maybe_compressed_char_at) { |
| 2672 | MipsLabel uncompressed_load, done; |
| 2673 | __ Bnez(TMP, &uncompressed_load); |
| 2674 | __ Addu(TMP, obj, index_reg); |
| 2675 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2676 | __ B(&done); |
| 2677 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2678 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2679 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2680 | __ Bind(&done); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2681 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2682 | __ Addu(TMP, index_reg, obj); |
| 2683 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2684 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2685 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2686 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2687 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2688 | } |
| 2689 | break; |
| 2690 | } |
| 2691 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2692 | case DataType::Type::kInt16: { |
| 2693 | Register out = out_loc.AsRegister<Register>(); |
| 2694 | if (index.IsConstant()) { |
| 2695 | size_t offset = |
| 2696 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2697 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2698 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2699 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2700 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2701 | } else { |
| 2702 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP); |
| 2703 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2704 | } |
| 2705 | break; |
| 2706 | } |
| 2707 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2708 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2709 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2710 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2711 | if (index.IsConstant()) { |
| 2712 | size_t offset = |
| 2713 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2714 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2715 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2716 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2717 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2718 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2719 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2720 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2721 | } |
| 2722 | break; |
| 2723 | } |
| 2724 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2725 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2726 | static_assert( |
| 2727 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2728 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2729 | // /* HeapReference<Object> */ out = |
| 2730 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2731 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2732 | bool temp_needed = index.IsConstant() |
| 2733 | ? !kBakerReadBarrierThunksEnableForFields |
| 2734 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2735 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2736 | // Note that a potential implicit null check is handled in this |
| 2737 | // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2738 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2739 | if (index.IsConstant()) { |
| 2740 | // Array load with a constant index can be treated as a field load. |
| 2741 | size_t offset = |
| 2742 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2743 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2744 | out_loc, |
| 2745 | obj, |
| 2746 | offset, |
| 2747 | temp, |
| 2748 | /* needs_null_check */ false); |
| 2749 | } else { |
| 2750 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2751 | out_loc, |
| 2752 | obj, |
| 2753 | data_offset, |
| 2754 | index, |
| 2755 | temp, |
| 2756 | /* needs_null_check */ false); |
| 2757 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2758 | } else { |
| 2759 | Register out = out_loc.AsRegister<Register>(); |
| 2760 | if (index.IsConstant()) { |
| 2761 | size_t offset = |
| 2762 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2763 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
| 2764 | // If read barriers are enabled, emit read barriers other than |
| 2765 | // Baker's using a slow path (and also unpoison the loaded |
| 2766 | // reference, if heap poisoning is enabled). |
| 2767 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2768 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2769 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2770 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
| 2771 | // If read barriers are enabled, emit read barriers other than |
| 2772 | // Baker's using a slow path (and also unpoison the loaded |
| 2773 | // reference, if heap poisoning is enabled). |
| 2774 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2775 | out_loc, |
| 2776 | out_loc, |
| 2777 | obj_loc, |
| 2778 | data_offset, |
| 2779 | index); |
| 2780 | } |
| 2781 | } |
| 2782 | break; |
| 2783 | } |
| 2784 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2785 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2786 | Register out = out_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2787 | if (index.IsConstant()) { |
| 2788 | size_t offset = |
| 2789 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2790 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2791 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2792 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2793 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2794 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2795 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2796 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2797 | } |
| 2798 | break; |
| 2799 | } |
| 2800 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2801 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2802 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2803 | if (index.IsConstant()) { |
| 2804 | size_t offset = |
| 2805 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2806 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2807 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2808 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2809 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2810 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2811 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2812 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2813 | } |
| 2814 | break; |
| 2815 | } |
| 2816 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2817 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2818 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2819 | if (index.IsConstant()) { |
| 2820 | size_t offset = |
| 2821 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2822 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2823 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2824 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2825 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2826 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2827 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2828 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2829 | } |
| 2830 | break; |
| 2831 | } |
| 2832 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2833 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2834 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2835 | UNREACHABLE(); |
| 2836 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2840 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2841 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2842 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2843 | } |
| 2844 | |
| 2845 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2846 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2847 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2848 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2849 | Register out = locations->Out().AsRegister<Register>(); |
| 2850 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2851 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2852 | // Mask out compression flag from String's array length. |
| 2853 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2854 | __ Srl(out, out, 1u); |
| 2855 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2856 | } |
| 2857 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2858 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2859 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2860 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2861 | : Location::RequiresRegister(); |
| 2862 | } |
| 2863 | |
| 2864 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2865 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2866 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2867 | // but we should only prefer this if the constant has a single use. |
| 2868 | if (instruction->IsConstant() && |
| 2869 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2870 | instruction->GetUses().HasExactlyOneElement())) { |
| 2871 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2872 | // Otherwise fall through and require an FPU register for the constant. |
| 2873 | } |
| 2874 | return Location::RequiresFpuRegister(); |
| 2875 | } |
| 2876 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2877 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2878 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2879 | |
| 2880 | bool needs_write_barrier = |
| 2881 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2882 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2883 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2884 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2885 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2886 | may_need_runtime_call_for_type_check ? |
| 2887 | LocationSummary::kCallOnSlowPath : |
| 2888 | LocationSummary::kNoCall); |
| 2889 | |
| 2890 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2891 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2892 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2893 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2894 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2895 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2896 | } |
| 2897 | if (needs_write_barrier) { |
| 2898 | // Temporary register for the write barrier. |
| 2899 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2900 | } |
| 2901 | } |
| 2902 | |
| 2903 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2904 | LocationSummary* locations = instruction->GetLocations(); |
| 2905 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2906 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2907 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2908 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2909 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2910 | bool needs_write_barrier = |
| 2911 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2912 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2913 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2914 | |
| 2915 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2916 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2917 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2918 | case DataType::Type::kInt8: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2919 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2920 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2921 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2922 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2923 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2924 | } |
| 2925 | if (value_location.IsConstant()) { |
| 2926 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2927 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2928 | } else { |
| 2929 | Register value = value_location.AsRegister<Register>(); |
| 2930 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2931 | } |
| 2932 | break; |
| 2933 | } |
| 2934 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2935 | case DataType::Type::kUint16: |
| 2936 | case DataType::Type::kInt16: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2937 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2938 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2939 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2940 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2941 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2942 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2943 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2944 | } |
| 2945 | if (value_location.IsConstant()) { |
| 2946 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2947 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2948 | } else { |
| 2949 | Register value = value_location.AsRegister<Register>(); |
| 2950 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2951 | } |
| 2952 | break; |
| 2953 | } |
| 2954 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2955 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2956 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2957 | if (index.IsConstant()) { |
| 2958 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2959 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2960 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2961 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2962 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2963 | } |
| 2964 | if (value_location.IsConstant()) { |
| 2965 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2966 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2967 | } else { |
| 2968 | Register value = value_location.AsRegister<Register>(); |
| 2969 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2970 | } |
| 2971 | break; |
| 2972 | } |
| 2973 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2974 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2975 | if (value_location.IsConstant()) { |
| 2976 | // Just setting null. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2977 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2978 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2979 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2980 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2981 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2982 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2983 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2984 | DCHECK_EQ(value, 0); |
| 2985 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2986 | DCHECK(!needs_write_barrier); |
| 2987 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2988 | break; |
| 2989 | } |
| 2990 | |
| 2991 | DCHECK(needs_write_barrier); |
| 2992 | Register value = value_location.AsRegister<Register>(); |
| 2993 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2994 | Register temp2 = TMP; // Doesn't need to survive slow path. |
| 2995 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2996 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2997 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2998 | MipsLabel done; |
| 2999 | SlowPathCodeMIPS* slow_path = nullptr; |
| 3000 | |
| 3001 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3002 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3003 | codegen_->AddSlowPath(slow_path); |
| 3004 | if (instruction->GetValueCanBeNull()) { |
| 3005 | MipsLabel non_zero; |
| 3006 | __ Bnez(value, &non_zero); |
| 3007 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3008 | if (index.IsConstant()) { |
| 3009 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3010 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3011 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3012 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3013 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3014 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3015 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3016 | __ B(&done); |
| 3017 | __ Bind(&non_zero); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3018 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3019 | |
| 3020 | // Note that when read barriers are enabled, the type checks |
| 3021 | // are performed without read barriers. This is fine, even in |
| 3022 | // the case where a class object is in the from-space after |
| 3023 | // the flip, as a comparison involving such a type would not |
| 3024 | // produce a false positive; it may of course produce a false |
| 3025 | // negative, in which case we would take the ArraySet slow |
| 3026 | // path. |
| 3027 | |
| 3028 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 3029 | __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker); |
| 3030 | __ MaybeUnpoisonHeapReference(temp1); |
| 3031 | |
| 3032 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 3033 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 3034 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3035 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 3036 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 3037 | // nor `temp2`, as we are comparing two poisoned references. |
| 3038 | |
| 3039 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3040 | MipsLabel do_put; |
| 3041 | __ Beq(temp1, temp2, &do_put); |
| 3042 | // If heap poisoning is enabled, the `temp1` reference has |
| 3043 | // not been unpoisoned yet; unpoison it now. |
| 3044 | __ MaybeUnpoisonHeapReference(temp1); |
| 3045 | |
| 3046 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 3047 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 3048 | // If heap poisoning is enabled, no need to unpoison |
| 3049 | // `temp1`, as we are comparing against null below. |
| 3050 | __ Bnez(temp1, slow_path->GetEntryLabel()); |
| 3051 | __ Bind(&do_put); |
| 3052 | } else { |
| 3053 | __ Bne(temp1, temp2, slow_path->GetEntryLabel()); |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | Register source = value; |
| 3058 | if (kPoisonHeapReferences) { |
| 3059 | // Note that in the case where `value` is a null reference, |
| 3060 | // we do not enter this block, as a null reference does not |
| 3061 | // need poisoning. |
| 3062 | __ Move(temp1, value); |
| 3063 | __ PoisonHeapReference(temp1); |
| 3064 | source = temp1; |
| 3065 | } |
| 3066 | |
| 3067 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3068 | if (index.IsConstant()) { |
| 3069 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3070 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3071 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3072 | } |
| 3073 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 3074 | |
| 3075 | if (!may_need_runtime_call_for_type_check) { |
| 3076 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3077 | } |
| 3078 | |
| 3079 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 3080 | |
| 3081 | if (done.IsLinked()) { |
| 3082 | __ Bind(&done); |
| 3083 | } |
| 3084 | |
| 3085 | if (slow_path != nullptr) { |
| 3086 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3087 | } |
| 3088 | break; |
| 3089 | } |
| 3090 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3091 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3092 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3093 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3094 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3095 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3096 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3097 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3098 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3099 | } |
| 3100 | if (value_location.IsConstant()) { |
| 3101 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3102 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3103 | } else { |
| 3104 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 3105 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3106 | } |
| 3107 | break; |
| 3108 | } |
| 3109 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3110 | case DataType::Type::kFloat32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3111 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3112 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3113 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3114 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3115 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3116 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3117 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3118 | } |
| 3119 | if (value_location.IsConstant()) { |
| 3120 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3121 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3122 | } else { |
| 3123 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3124 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3125 | } |
| 3126 | break; |
| 3127 | } |
| 3128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3129 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3130 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3131 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3132 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3133 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3134 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3135 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3136 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3137 | } |
| 3138 | if (value_location.IsConstant()) { |
| 3139 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3140 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3141 | } else { |
| 3142 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3143 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3144 | } |
| 3145 | break; |
| 3146 | } |
| 3147 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3148 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3149 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3150 | UNREACHABLE(); |
| 3151 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3152 | } |
| 3153 | |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3154 | void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex( |
| 3155 | HIntermediateArrayAddressIndex* instruction) { |
| 3156 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3157 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3158 | |
| 3159 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 3160 | |
| 3161 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3162 | locations->SetInAt(1, Location::ConstantLocation(shift)); |
| 3163 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3164 | } |
| 3165 | |
| 3166 | void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex( |
| 3167 | HIntermediateArrayAddressIndex* instruction) { |
| 3168 | LocationSummary* locations = instruction->GetLocations(); |
| 3169 | Register index_reg = locations->InAt(0).AsRegister<Register>(); |
| 3170 | uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue(); |
| 3171 | __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift); |
| 3172 | } |
| 3173 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3174 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3175 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3176 | InvokeRuntimeCallingConvention calling_convention; |
| 3177 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3178 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3179 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3180 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3181 | locations->SetInAt(1, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3185 | LocationSummary* locations = instruction->GetLocations(); |
| 3186 | BoundsCheckSlowPathMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3187 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3188 | codegen_->AddSlowPath(slow_path); |
| 3189 | |
| 3190 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 3191 | Register length = locations->InAt(1).AsRegister<Register>(); |
| 3192 | |
| 3193 | // length is limited by the maximum positive signed 32-bit integer. |
| 3194 | // Unsigned comparison of length and index checks for index < 0 |
| 3195 | // and for length <= index simultaneously. |
| 3196 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 3197 | } |
| 3198 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3199 | // Temp is used for read barrier. |
| 3200 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3201 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 3202 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3203 | (kUseBakerReadBarrier || |
| 3204 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3205 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3206 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3207 | return 1; |
| 3208 | } |
| 3209 | return 0; |
| 3210 | } |
| 3211 | |
| 3212 | // Extra temp is used for read barrier. |
| 3213 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3214 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 3215 | } |
| 3216 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3217 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3218 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3219 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3220 | |
| 3221 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3222 | switch (type_check_kind) { |
| 3223 | case TypeCheckKind::kExactCheck: |
| 3224 | case TypeCheckKind::kAbstractClassCheck: |
| 3225 | case TypeCheckKind::kClassHierarchyCheck: |
| 3226 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3227 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3228 | ? LocationSummary::kCallOnSlowPath |
| 3229 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 3230 | break; |
| 3231 | case TypeCheckKind::kArrayCheck: |
| 3232 | case TypeCheckKind::kUnresolvedCheck: |
| 3233 | case TypeCheckKind::kInterfaceCheck: |
| 3234 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3235 | break; |
| 3236 | } |
| 3237 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3238 | LocationSummary* locations = |
| 3239 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3240 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3241 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3242 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3246 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3247 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3248 | Location obj_loc = locations->InAt(0); |
| 3249 | Register obj = obj_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3250 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3251 | Location temp_loc = locations->GetTemp(0); |
| 3252 | Register temp = temp_loc.AsRegister<Register>(); |
| 3253 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3254 | DCHECK_LE(num_temps, 2u); |
| 3255 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3256 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3257 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3258 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3259 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3260 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3261 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3262 | const uint32_t object_array_data_offset = |
| 3263 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3264 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3265 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3266 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 3267 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 3268 | // read barriers is done for performance and code size reasons. |
| 3269 | bool is_type_check_slow_path_fatal = false; |
| 3270 | if (!kEmitCompilerReadBarrier) { |
| 3271 | is_type_check_slow_path_fatal = |
| 3272 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3273 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3274 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3275 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3276 | !instruction->CanThrowIntoCatchBlock(); |
| 3277 | } |
| 3278 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3279 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 3280 | instruction, is_type_check_slow_path_fatal); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3281 | codegen_->AddSlowPath(slow_path); |
| 3282 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3283 | // Avoid this check if we know `obj` is not null. |
| 3284 | if (instruction->MustDoNullCheck()) { |
| 3285 | __ Beqz(obj, &done); |
| 3286 | } |
| 3287 | |
| 3288 | switch (type_check_kind) { |
| 3289 | case TypeCheckKind::kExactCheck: |
| 3290 | case TypeCheckKind::kArrayCheck: { |
| 3291 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3292 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3293 | temp_loc, |
| 3294 | obj_loc, |
| 3295 | class_offset, |
| 3296 | maybe_temp2_loc, |
| 3297 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3298 | // Jump to slow path for throwing the exception or doing a |
| 3299 | // more involved array check. |
| 3300 | __ Bne(temp, cls, slow_path->GetEntryLabel()); |
| 3301 | break; |
| 3302 | } |
| 3303 | |
| 3304 | case TypeCheckKind::kAbstractClassCheck: { |
| 3305 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3306 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3307 | temp_loc, |
| 3308 | obj_loc, |
| 3309 | class_offset, |
| 3310 | maybe_temp2_loc, |
| 3311 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3312 | // If the class is abstract, we eagerly fetch the super class of the |
| 3313 | // object to avoid doing a comparison we know will fail. |
| 3314 | MipsLabel loop; |
| 3315 | __ Bind(&loop); |
| 3316 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3317 | GenerateReferenceLoadOneRegister(instruction, |
| 3318 | temp_loc, |
| 3319 | super_offset, |
| 3320 | maybe_temp2_loc, |
| 3321 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3322 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3323 | // exception. |
| 3324 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3325 | // Otherwise, compare the classes. |
| 3326 | __ Bne(temp, cls, &loop); |
| 3327 | break; |
| 3328 | } |
| 3329 | |
| 3330 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3331 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3332 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3333 | temp_loc, |
| 3334 | obj_loc, |
| 3335 | class_offset, |
| 3336 | maybe_temp2_loc, |
| 3337 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3338 | // Walk over the class hierarchy to find a match. |
| 3339 | MipsLabel loop; |
| 3340 | __ Bind(&loop); |
| 3341 | __ Beq(temp, cls, &done); |
| 3342 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3343 | GenerateReferenceLoadOneRegister(instruction, |
| 3344 | temp_loc, |
| 3345 | super_offset, |
| 3346 | maybe_temp2_loc, |
| 3347 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3348 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3349 | // exception. Otherwise, jump to the beginning of the loop. |
| 3350 | __ Bnez(temp, &loop); |
| 3351 | __ B(slow_path->GetEntryLabel()); |
| 3352 | break; |
| 3353 | } |
| 3354 | |
| 3355 | case TypeCheckKind::kArrayObjectCheck: { |
| 3356 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3357 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3358 | temp_loc, |
| 3359 | obj_loc, |
| 3360 | class_offset, |
| 3361 | maybe_temp2_loc, |
| 3362 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3363 | // Do an exact check. |
| 3364 | __ Beq(temp, cls, &done); |
| 3365 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3366 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3367 | GenerateReferenceLoadOneRegister(instruction, |
| 3368 | temp_loc, |
| 3369 | component_offset, |
| 3370 | maybe_temp2_loc, |
| 3371 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3372 | // If the component type is null, jump to the slow path to throw the exception. |
| 3373 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3374 | // Otherwise, the object is indeed an array, further check that this component |
| 3375 | // type is not a primitive type. |
| 3376 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3377 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3378 | __ Bnez(temp, slow_path->GetEntryLabel()); |
| 3379 | break; |
| 3380 | } |
| 3381 | |
| 3382 | case TypeCheckKind::kUnresolvedCheck: |
| 3383 | // We always go into the type check slow path for the unresolved check case. |
| 3384 | // We cannot directly call the CheckCast runtime entry point |
| 3385 | // without resorting to a type checking slow path here (i.e. by |
| 3386 | // calling InvokeRuntime directly), as it would require to |
| 3387 | // assign fixed registers for the inputs of this HInstanceOf |
| 3388 | // instruction (following the runtime calling convention), which |
| 3389 | // might be cluttered by the potential first read barrier |
| 3390 | // emission at the beginning of this method. |
| 3391 | __ B(slow_path->GetEntryLabel()); |
| 3392 | break; |
| 3393 | |
| 3394 | case TypeCheckKind::kInterfaceCheck: { |
| 3395 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3396 | // positives by doing this. |
| 3397 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3398 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3399 | temp_loc, |
| 3400 | obj_loc, |
| 3401 | class_offset, |
| 3402 | maybe_temp2_loc, |
| 3403 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3404 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3405 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3406 | temp_loc, |
| 3407 | temp_loc, |
| 3408 | iftable_offset, |
| 3409 | maybe_temp2_loc, |
| 3410 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3411 | // Iftable is never null. |
| 3412 | __ Lw(TMP, temp, array_length_offset); |
| 3413 | // Loop through the iftable and check if any class matches. |
| 3414 | MipsLabel loop; |
| 3415 | __ Bind(&loop); |
| 3416 | __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2. |
| 3417 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3418 | __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize); |
| 3419 | __ MaybeUnpoisonHeapReference(AT); |
| 3420 | // Go to next interface. |
| 3421 | __ Addiu(TMP, TMP, -2); |
| 3422 | // Compare the classes and continue the loop if they do not match. |
| 3423 | __ Bne(AT, cls, &loop); |
| 3424 | break; |
| 3425 | } |
| 3426 | } |
| 3427 | |
| 3428 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3429 | __ Bind(slow_path->GetExitLabel()); |
| 3430 | } |
| 3431 | |
| 3432 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3433 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3434 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3435 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3436 | if (check->HasUses()) { |
| 3437 | locations->SetOut(Location::SameAsFirstInput()); |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3442 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3443 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3444 | check->GetLoadClass(), |
| 3445 | check, |
| 3446 | check->GetDexPc(), |
| 3447 | true); |
| 3448 | codegen_->AddSlowPath(slow_path); |
| 3449 | GenerateClassInitializationCheck(slow_path, |
| 3450 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 3451 | } |
| 3452 | |
| 3453 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3454 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3455 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3456 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3457 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3458 | |
| 3459 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3460 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3461 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3462 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3463 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3464 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3465 | case DataType::Type::kInt32: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3466 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3467 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3468 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3469 | break; |
| 3470 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3471 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3472 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3473 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3474 | // Output overlaps because it is written before doing the low comparison. |
| 3475 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3476 | break; |
| 3477 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3478 | case DataType::Type::kFloat32: |
| 3479 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3480 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3481 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3482 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3483 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3484 | |
| 3485 | default: |
| 3486 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 3491 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3492 | Register res = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3493 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3494 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3495 | |
| 3496 | // 0 if: left == right |
| 3497 | // 1 if: left > right |
| 3498 | // -1 if: left < right |
| 3499 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3500 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3501 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3502 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3503 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3504 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3505 | case DataType::Type::kInt32: { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3506 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3507 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3508 | __ Slt(TMP, lhs, rhs); |
| 3509 | __ Slt(res, rhs, lhs); |
| 3510 | __ Subu(res, res, TMP); |
| 3511 | break; |
| 3512 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3513 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3514 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3515 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3516 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3517 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3518 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3519 | // TODO: more efficient (direct) comparison with a constant. |
| 3520 | __ Slt(TMP, lhs_high, rhs_high); |
| 3521 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 3522 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3523 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 3524 | __ Sltu(TMP, lhs_low, rhs_low); |
| 3525 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 3526 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3527 | __ Bind(&done); |
| 3528 | break; |
| 3529 | } |
| 3530 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3531 | case DataType::Type::kFloat32: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3532 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3533 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3534 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3535 | MipsLabel done; |
| 3536 | if (isR6) { |
| 3537 | __ CmpEqS(FTMP, lhs, rhs); |
| 3538 | __ LoadConst32(res, 0); |
| 3539 | __ Bc1nez(FTMP, &done); |
| 3540 | if (gt_bias) { |
| 3541 | __ CmpLtS(FTMP, lhs, rhs); |
| 3542 | __ LoadConst32(res, -1); |
| 3543 | __ Bc1nez(FTMP, &done); |
| 3544 | __ LoadConst32(res, 1); |
| 3545 | } else { |
| 3546 | __ CmpLtS(FTMP, rhs, lhs); |
| 3547 | __ LoadConst32(res, 1); |
| 3548 | __ Bc1nez(FTMP, &done); |
| 3549 | __ LoadConst32(res, -1); |
| 3550 | } |
| 3551 | } else { |
| 3552 | if (gt_bias) { |
| 3553 | __ ColtS(0, lhs, rhs); |
| 3554 | __ LoadConst32(res, -1); |
| 3555 | __ Bc1t(0, &done); |
| 3556 | __ CeqS(0, lhs, rhs); |
| 3557 | __ LoadConst32(res, 1); |
| 3558 | __ Movt(res, ZERO, 0); |
| 3559 | } else { |
| 3560 | __ ColtS(0, rhs, lhs); |
| 3561 | __ LoadConst32(res, 1); |
| 3562 | __ Bc1t(0, &done); |
| 3563 | __ CeqS(0, lhs, rhs); |
| 3564 | __ LoadConst32(res, -1); |
| 3565 | __ Movt(res, ZERO, 0); |
| 3566 | } |
| 3567 | } |
| 3568 | __ Bind(&done); |
| 3569 | break; |
| 3570 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3571 | case DataType::Type::kFloat64: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3572 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3573 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3574 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3575 | MipsLabel done; |
| 3576 | if (isR6) { |
| 3577 | __ CmpEqD(FTMP, lhs, rhs); |
| 3578 | __ LoadConst32(res, 0); |
| 3579 | __ Bc1nez(FTMP, &done); |
| 3580 | if (gt_bias) { |
| 3581 | __ CmpLtD(FTMP, lhs, rhs); |
| 3582 | __ LoadConst32(res, -1); |
| 3583 | __ Bc1nez(FTMP, &done); |
| 3584 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3585 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3586 | __ CmpLtD(FTMP, rhs, lhs); |
| 3587 | __ LoadConst32(res, 1); |
| 3588 | __ Bc1nez(FTMP, &done); |
| 3589 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3590 | } |
| 3591 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3592 | if (gt_bias) { |
| 3593 | __ ColtD(0, lhs, rhs); |
| 3594 | __ LoadConst32(res, -1); |
| 3595 | __ Bc1t(0, &done); |
| 3596 | __ CeqD(0, lhs, rhs); |
| 3597 | __ LoadConst32(res, 1); |
| 3598 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3599 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3600 | __ ColtD(0, rhs, lhs); |
| 3601 | __ LoadConst32(res, 1); |
| 3602 | __ Bc1t(0, &done); |
| 3603 | __ CeqD(0, lhs, rhs); |
| 3604 | __ LoadConst32(res, -1); |
| 3605 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3606 | } |
| 3607 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3608 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3609 | break; |
| 3610 | } |
| 3611 | |
| 3612 | default: |
| 3613 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3614 | } |
| 3615 | } |
| 3616 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3617 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3618 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3619 | switch (instruction->InputAt(0)->GetType()) { |
| 3620 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3621 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3622 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3623 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3624 | break; |
| 3625 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3626 | case DataType::Type::kFloat32: |
| 3627 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3628 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3629 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3630 | break; |
| 3631 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3632 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3633 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3634 | } |
| 3635 | } |
| 3636 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3637 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3638 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3639 | return; |
| 3640 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3641 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3642 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3643 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3644 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3645 | switch (type) { |
| 3646 | default: |
| 3647 | // Integer case. |
| 3648 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 3649 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3650 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3651 | case DataType::Type::kInt64: |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 3652 | GenerateLongCompare(instruction->GetCondition(), locations); |
| 3653 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3654 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3655 | case DataType::Type::kFloat32: |
| 3656 | case DataType::Type::kFloat64: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3657 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3658 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3659 | } |
| 3660 | } |
| 3661 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3662 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3663 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3664 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3665 | |
| 3666 | LocationSummary* locations = instruction->GetLocations(); |
| 3667 | Location second = locations->InAt(1); |
| 3668 | DCHECK(second.IsConstant()); |
| 3669 | |
| 3670 | Register out = locations->Out().AsRegister<Register>(); |
| 3671 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3672 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3673 | DCHECK(imm == 1 || imm == -1); |
| 3674 | |
| 3675 | if (instruction->IsRem()) { |
| 3676 | __ Move(out, ZERO); |
| 3677 | } else { |
| 3678 | if (imm == -1) { |
| 3679 | __ Subu(out, ZERO, dividend); |
| 3680 | } else if (out != dividend) { |
| 3681 | __ Move(out, dividend); |
| 3682 | } |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3687 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3688 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3689 | |
| 3690 | LocationSummary* locations = instruction->GetLocations(); |
| 3691 | Location second = locations->InAt(1); |
| 3692 | DCHECK(second.IsConstant()); |
| 3693 | |
| 3694 | Register out = locations->Out().AsRegister<Register>(); |
| 3695 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3696 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3697 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3698 | int ctz_imm = CTZ(abs_imm); |
| 3699 | |
| 3700 | if (instruction->IsDiv()) { |
| 3701 | if (ctz_imm == 1) { |
| 3702 | // Fast path for division by +/-2, which is very common. |
| 3703 | __ Srl(TMP, dividend, 31); |
| 3704 | } else { |
| 3705 | __ Sra(TMP, dividend, 31); |
| 3706 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3707 | } |
| 3708 | __ Addu(out, dividend, TMP); |
| 3709 | __ Sra(out, out, ctz_imm); |
| 3710 | if (imm < 0) { |
| 3711 | __ Subu(out, ZERO, out); |
| 3712 | } |
| 3713 | } else { |
| 3714 | if (ctz_imm == 1) { |
| 3715 | // Fast path for modulo +/-2, which is very common. |
| 3716 | __ Sra(TMP, dividend, 31); |
| 3717 | __ Subu(out, dividend, TMP); |
| 3718 | __ Andi(out, out, 1); |
| 3719 | __ Addu(out, out, TMP); |
| 3720 | } else { |
| 3721 | __ Sra(TMP, dividend, 31); |
| 3722 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3723 | __ Addu(out, dividend, TMP); |
| 3724 | if (IsUint<16>(abs_imm - 1)) { |
| 3725 | __ Andi(out, out, abs_imm - 1); |
| 3726 | } else { |
| 3727 | __ Sll(out, out, 32 - ctz_imm); |
| 3728 | __ Srl(out, out, 32 - ctz_imm); |
| 3729 | } |
| 3730 | __ Subu(out, out, TMP); |
| 3731 | } |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3736 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3737 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3738 | |
| 3739 | LocationSummary* locations = instruction->GetLocations(); |
| 3740 | Location second = locations->InAt(1); |
| 3741 | DCHECK(second.IsConstant()); |
| 3742 | |
| 3743 | Register out = locations->Out().AsRegister<Register>(); |
| 3744 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3745 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3746 | |
| 3747 | int64_t magic; |
| 3748 | int shift; |
| 3749 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3750 | |
| 3751 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3752 | |
| 3753 | __ LoadConst32(TMP, magic); |
| 3754 | if (isR6) { |
| 3755 | __ MuhR6(TMP, dividend, TMP); |
| 3756 | } else { |
| 3757 | __ MultR2(dividend, TMP); |
| 3758 | __ Mfhi(TMP); |
| 3759 | } |
| 3760 | if (imm > 0 && magic < 0) { |
| 3761 | __ Addu(TMP, TMP, dividend); |
| 3762 | } else if (imm < 0 && magic > 0) { |
| 3763 | __ Subu(TMP, TMP, dividend); |
| 3764 | } |
| 3765 | |
| 3766 | if (shift != 0) { |
| 3767 | __ Sra(TMP, TMP, shift); |
| 3768 | } |
| 3769 | |
| 3770 | if (instruction->IsDiv()) { |
| 3771 | __ Sra(out, TMP, 31); |
| 3772 | __ Subu(out, TMP, out); |
| 3773 | } else { |
| 3774 | __ Sra(AT, TMP, 31); |
| 3775 | __ Subu(AT, TMP, AT); |
| 3776 | __ LoadConst32(TMP, imm); |
| 3777 | if (isR6) { |
| 3778 | __ MulR6(TMP, AT, TMP); |
| 3779 | } else { |
| 3780 | __ MulR2(TMP, AT, TMP); |
| 3781 | } |
| 3782 | __ Subu(out, dividend, TMP); |
| 3783 | } |
| 3784 | } |
| 3785 | |
| 3786 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3787 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3788 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3789 | |
| 3790 | LocationSummary* locations = instruction->GetLocations(); |
| 3791 | Register out = locations->Out().AsRegister<Register>(); |
| 3792 | Location second = locations->InAt(1); |
| 3793 | |
| 3794 | if (second.IsConstant()) { |
| 3795 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3796 | if (imm == 0) { |
| 3797 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3798 | } else if (imm == 1 || imm == -1) { |
| 3799 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3800 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3801 | DivRemByPowerOfTwo(instruction); |
| 3802 | } else { |
| 3803 | DCHECK(imm <= -2 || imm >= 2); |
| 3804 | GenerateDivRemWithAnyConstant(instruction); |
| 3805 | } |
| 3806 | } else { |
| 3807 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3808 | Register divisor = second.AsRegister<Register>(); |
| 3809 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3810 | if (instruction->IsDiv()) { |
| 3811 | if (isR6) { |
| 3812 | __ DivR6(out, dividend, divisor); |
| 3813 | } else { |
| 3814 | __ DivR2(out, dividend, divisor); |
| 3815 | } |
| 3816 | } else { |
| 3817 | if (isR6) { |
| 3818 | __ ModR6(out, dividend, divisor); |
| 3819 | } else { |
| 3820 | __ ModR2(out, dividend, divisor); |
| 3821 | } |
| 3822 | } |
| 3823 | } |
| 3824 | } |
| 3825 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3826 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3827 | DataType::Type type = div->GetResultType(); |
| 3828 | LocationSummary::CallKind call_kind = (type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3829 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3830 | : LocationSummary::kNoCall; |
| 3831 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3832 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3833 | |
| 3834 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3835 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3836 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3837 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3838 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3839 | break; |
| 3840 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3841 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3842 | InvokeRuntimeCallingConvention calling_convention; |
| 3843 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3844 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3845 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3846 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3847 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 3848 | break; |
| 3849 | } |
| 3850 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3851 | case DataType::Type::kFloat32: |
| 3852 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3853 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3854 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3855 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3856 | break; |
| 3857 | |
| 3858 | default: |
| 3859 | LOG(FATAL) << "Unexpected div type " << type; |
| 3860 | } |
| 3861 | } |
| 3862 | |
| 3863 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3864 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3865 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3866 | |
| 3867 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3868 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3869 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3870 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3871 | case DataType::Type::kInt64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 3872 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3873 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 3874 | break; |
| 3875 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3876 | case DataType::Type::kFloat32: |
| 3877 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3878 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 3879 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3880 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3881 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3882 | __ DivS(dst, lhs, rhs); |
| 3883 | } else { |
| 3884 | __ DivD(dst, lhs, rhs); |
| 3885 | } |
| 3886 | break; |
| 3887 | } |
| 3888 | default: |
| 3889 | LOG(FATAL) << "Unexpected div type " << type; |
| 3890 | } |
| 3891 | } |
| 3892 | |
| 3893 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3894 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3895 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3899 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3900 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3901 | codegen_->AddSlowPath(slow_path); |
| 3902 | Location value = instruction->GetLocations()->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3903 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3904 | |
| 3905 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3906 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3907 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3908 | case DataType::Type::kInt8: |
| 3909 | case DataType::Type::kUint16: |
| 3910 | case DataType::Type::kInt16: |
| 3911 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3912 | if (value.IsConstant()) { |
| 3913 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3914 | __ B(slow_path->GetEntryLabel()); |
| 3915 | } else { |
| 3916 | // A division by a non-null constant is valid. We don't need to perform |
| 3917 | // any check, so simply fall through. |
| 3918 | } |
| 3919 | } else { |
| 3920 | DCHECK(value.IsRegister()) << value; |
| 3921 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 3922 | } |
| 3923 | break; |
| 3924 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3925 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3926 | if (value.IsConstant()) { |
| 3927 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3928 | __ B(slow_path->GetEntryLabel()); |
| 3929 | } else { |
| 3930 | // A division by a non-null constant is valid. We don't need to perform |
| 3931 | // any check, so simply fall through. |
| 3932 | } |
| 3933 | } else { |
| 3934 | DCHECK(value.IsRegisterPair()) << value; |
| 3935 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 3936 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3937 | } |
| 3938 | break; |
| 3939 | } |
| 3940 | default: |
| 3941 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 3942 | } |
| 3943 | } |
| 3944 | |
| 3945 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3946 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3947 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3948 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3949 | } |
| 3950 | |
| 3951 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3952 | // Will be generated at use site. |
| 3953 | } |
| 3954 | |
| 3955 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 3956 | exit->SetLocations(nullptr); |
| 3957 | } |
| 3958 | |
| 3959 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3960 | } |
| 3961 | |
| 3962 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 3963 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3964 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3965 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3966 | } |
| 3967 | |
| 3968 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3969 | // Will be generated at use site. |
| 3970 | } |
| 3971 | |
| 3972 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 3973 | got->SetLocations(nullptr); |
| 3974 | } |
| 3975 | |
| 3976 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 3977 | DCHECK(!successor->IsExitBlock()); |
| 3978 | HBasicBlock* block = got->GetBlock(); |
| 3979 | HInstruction* previous = got->GetPrevious(); |
| 3980 | HLoopInformation* info = block->GetLoopInformation(); |
| 3981 | |
| 3982 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3983 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3984 | return; |
| 3985 | } |
| 3986 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3987 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3988 | } |
| 3989 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 3990 | __ B(codegen_->GetLabelOf(successor)); |
| 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 3995 | HandleGoto(got, got->GetSuccessor()); |
| 3996 | } |
| 3997 | |
| 3998 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3999 | try_boundary->SetLocations(nullptr); |
| 4000 | } |
| 4001 | |
| 4002 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4003 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 4004 | if (!successor->IsExitBlock()) { |
| 4005 | HandleGoto(try_boundary, successor); |
| 4006 | } |
| 4007 | } |
| 4008 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4009 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 4010 | LocationSummary* locations) { |
| 4011 | Register dst = locations->Out().AsRegister<Register>(); |
| 4012 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4013 | Location rhs_location = locations->InAt(1); |
| 4014 | Register rhs_reg = ZERO; |
| 4015 | int64_t rhs_imm = 0; |
| 4016 | bool use_imm = rhs_location.IsConstant(); |
| 4017 | if (use_imm) { |
| 4018 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4019 | } else { |
| 4020 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4021 | } |
| 4022 | |
| 4023 | switch (cond) { |
| 4024 | case kCondEQ: |
| 4025 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4026 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4027 | if (rhs_imm == 0) { |
| 4028 | if (cond == kCondEQ) { |
| 4029 | __ Sltiu(dst, lhs, 1); |
| 4030 | } else { |
| 4031 | __ Sltu(dst, ZERO, lhs); |
| 4032 | } |
| 4033 | } else { |
| 4034 | __ Addiu(dst, lhs, -rhs_imm); |
| 4035 | if (cond == kCondEQ) { |
| 4036 | __ Sltiu(dst, dst, 1); |
| 4037 | } else { |
| 4038 | __ Sltu(dst, ZERO, dst); |
| 4039 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4040 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4041 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4042 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 4043 | __ Xori(dst, lhs, rhs_imm); |
| 4044 | } else { |
| 4045 | if (use_imm) { |
| 4046 | rhs_reg = TMP; |
| 4047 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4048 | } |
| 4049 | __ Xor(dst, lhs, rhs_reg); |
| 4050 | } |
| 4051 | if (cond == kCondEQ) { |
| 4052 | __ Sltiu(dst, dst, 1); |
| 4053 | } else { |
| 4054 | __ Sltu(dst, ZERO, dst); |
| 4055 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4056 | } |
| 4057 | break; |
| 4058 | |
| 4059 | case kCondLT: |
| 4060 | case kCondGE: |
| 4061 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4062 | __ Slti(dst, lhs, rhs_imm); |
| 4063 | } else { |
| 4064 | if (use_imm) { |
| 4065 | rhs_reg = TMP; |
| 4066 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4067 | } |
| 4068 | __ Slt(dst, lhs, rhs_reg); |
| 4069 | } |
| 4070 | if (cond == kCondGE) { |
| 4071 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4072 | // only the slt instruction but no sge. |
| 4073 | __ Xori(dst, dst, 1); |
| 4074 | } |
| 4075 | break; |
| 4076 | |
| 4077 | case kCondLE: |
| 4078 | case kCondGT: |
| 4079 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4080 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4081 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4082 | if (cond == kCondGT) { |
| 4083 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4084 | // only the slti instruction but no sgti. |
| 4085 | __ Xori(dst, dst, 1); |
| 4086 | } |
| 4087 | } else { |
| 4088 | if (use_imm) { |
| 4089 | rhs_reg = TMP; |
| 4090 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4091 | } |
| 4092 | __ Slt(dst, rhs_reg, lhs); |
| 4093 | if (cond == kCondLE) { |
| 4094 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4095 | // only the slt instruction but no sle. |
| 4096 | __ Xori(dst, dst, 1); |
| 4097 | } |
| 4098 | } |
| 4099 | break; |
| 4100 | |
| 4101 | case kCondB: |
| 4102 | case kCondAE: |
| 4103 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4104 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4105 | // the comparison and thus lets us compare directly with |
| 4106 | // unsigned values in the ranges [0, 0x7fff] and |
| 4107 | // [0xffff8000, 0xffffffff]. |
| 4108 | __ Sltiu(dst, lhs, rhs_imm); |
| 4109 | } else { |
| 4110 | if (use_imm) { |
| 4111 | rhs_reg = TMP; |
| 4112 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4113 | } |
| 4114 | __ Sltu(dst, lhs, rhs_reg); |
| 4115 | } |
| 4116 | if (cond == kCondAE) { |
| 4117 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4118 | // only the sltu instruction but no sgeu. |
| 4119 | __ Xori(dst, dst, 1); |
| 4120 | } |
| 4121 | break; |
| 4122 | |
| 4123 | case kCondBE: |
| 4124 | case kCondA: |
| 4125 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4126 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4127 | // Note that this only works if rhs + 1 does not overflow |
| 4128 | // to 0, hence the check above. |
| 4129 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4130 | // the comparison and thus lets us compare directly with |
| 4131 | // unsigned values in the ranges [0, 0x7fff] and |
| 4132 | // [0xffff8000, 0xffffffff]. |
| 4133 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4134 | if (cond == kCondA) { |
| 4135 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4136 | // only the sltiu instruction but no sgtiu. |
| 4137 | __ Xori(dst, dst, 1); |
| 4138 | } |
| 4139 | } else { |
| 4140 | if (use_imm) { |
| 4141 | rhs_reg = TMP; |
| 4142 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4143 | } |
| 4144 | __ Sltu(dst, rhs_reg, lhs); |
| 4145 | if (cond == kCondBE) { |
| 4146 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4147 | // only the sltu instruction but no sleu. |
| 4148 | __ Xori(dst, dst, 1); |
| 4149 | } |
| 4150 | } |
| 4151 | break; |
| 4152 | } |
| 4153 | } |
| 4154 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4155 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 4156 | LocationSummary* input_locations, |
| 4157 | Register dst) { |
| 4158 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 4159 | Location rhs_location = input_locations->InAt(1); |
| 4160 | Register rhs_reg = ZERO; |
| 4161 | int64_t rhs_imm = 0; |
| 4162 | bool use_imm = rhs_location.IsConstant(); |
| 4163 | if (use_imm) { |
| 4164 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4165 | } else { |
| 4166 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4167 | } |
| 4168 | |
| 4169 | switch (cond) { |
| 4170 | case kCondEQ: |
| 4171 | case kCondNE: |
| 4172 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4173 | __ Addiu(dst, lhs, -rhs_imm); |
| 4174 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 4175 | __ Xori(dst, lhs, rhs_imm); |
| 4176 | } else { |
| 4177 | if (use_imm) { |
| 4178 | rhs_reg = TMP; |
| 4179 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4180 | } |
| 4181 | __ Xor(dst, lhs, rhs_reg); |
| 4182 | } |
| 4183 | return (cond == kCondEQ); |
| 4184 | |
| 4185 | case kCondLT: |
| 4186 | case kCondGE: |
| 4187 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4188 | __ Slti(dst, lhs, rhs_imm); |
| 4189 | } else { |
| 4190 | if (use_imm) { |
| 4191 | rhs_reg = TMP; |
| 4192 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4193 | } |
| 4194 | __ Slt(dst, lhs, rhs_reg); |
| 4195 | } |
| 4196 | return (cond == kCondGE); |
| 4197 | |
| 4198 | case kCondLE: |
| 4199 | case kCondGT: |
| 4200 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4201 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4202 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4203 | return (cond == kCondGT); |
| 4204 | } else { |
| 4205 | if (use_imm) { |
| 4206 | rhs_reg = TMP; |
| 4207 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4208 | } |
| 4209 | __ Slt(dst, rhs_reg, lhs); |
| 4210 | return (cond == kCondLE); |
| 4211 | } |
| 4212 | |
| 4213 | case kCondB: |
| 4214 | case kCondAE: |
| 4215 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4216 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4217 | // the comparison and thus lets us compare directly with |
| 4218 | // unsigned values in the ranges [0, 0x7fff] and |
| 4219 | // [0xffff8000, 0xffffffff]. |
| 4220 | __ Sltiu(dst, lhs, rhs_imm); |
| 4221 | } else { |
| 4222 | if (use_imm) { |
| 4223 | rhs_reg = TMP; |
| 4224 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4225 | } |
| 4226 | __ Sltu(dst, lhs, rhs_reg); |
| 4227 | } |
| 4228 | return (cond == kCondAE); |
| 4229 | |
| 4230 | case kCondBE: |
| 4231 | case kCondA: |
| 4232 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4233 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4234 | // Note that this only works if rhs + 1 does not overflow |
| 4235 | // to 0, hence the check above. |
| 4236 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4237 | // the comparison and thus lets us compare directly with |
| 4238 | // unsigned values in the ranges [0, 0x7fff] and |
| 4239 | // [0xffff8000, 0xffffffff]. |
| 4240 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4241 | return (cond == kCondA); |
| 4242 | } else { |
| 4243 | if (use_imm) { |
| 4244 | rhs_reg = TMP; |
| 4245 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4246 | } |
| 4247 | __ Sltu(dst, rhs_reg, lhs); |
| 4248 | return (cond == kCondBE); |
| 4249 | } |
| 4250 | } |
| 4251 | } |
| 4252 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4253 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 4254 | LocationSummary* locations, |
| 4255 | MipsLabel* label) { |
| 4256 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4257 | Location rhs_location = locations->InAt(1); |
| 4258 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4259 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4260 | bool use_imm = rhs_location.IsConstant(); |
| 4261 | if (use_imm) { |
| 4262 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4263 | } else { |
| 4264 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4265 | } |
| 4266 | |
| 4267 | if (use_imm && rhs_imm == 0) { |
| 4268 | switch (cond) { |
| 4269 | case kCondEQ: |
| 4270 | case kCondBE: // <= 0 if zero |
| 4271 | __ Beqz(lhs, label); |
| 4272 | break; |
| 4273 | case kCondNE: |
| 4274 | case kCondA: // > 0 if non-zero |
| 4275 | __ Bnez(lhs, label); |
| 4276 | break; |
| 4277 | case kCondLT: |
| 4278 | __ Bltz(lhs, label); |
| 4279 | break; |
| 4280 | case kCondGE: |
| 4281 | __ Bgez(lhs, label); |
| 4282 | break; |
| 4283 | case kCondLE: |
| 4284 | __ Blez(lhs, label); |
| 4285 | break; |
| 4286 | case kCondGT: |
| 4287 | __ Bgtz(lhs, label); |
| 4288 | break; |
| 4289 | case kCondB: // always false |
| 4290 | break; |
| 4291 | case kCondAE: // always true |
| 4292 | __ B(label); |
| 4293 | break; |
| 4294 | } |
| 4295 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4296 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4297 | if (isR6 || !use_imm) { |
| 4298 | if (use_imm) { |
| 4299 | rhs_reg = TMP; |
| 4300 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4301 | } |
| 4302 | switch (cond) { |
| 4303 | case kCondEQ: |
| 4304 | __ Beq(lhs, rhs_reg, label); |
| 4305 | break; |
| 4306 | case kCondNE: |
| 4307 | __ Bne(lhs, rhs_reg, label); |
| 4308 | break; |
| 4309 | case kCondLT: |
| 4310 | __ Blt(lhs, rhs_reg, label); |
| 4311 | break; |
| 4312 | case kCondGE: |
| 4313 | __ Bge(lhs, rhs_reg, label); |
| 4314 | break; |
| 4315 | case kCondLE: |
| 4316 | __ Bge(rhs_reg, lhs, label); |
| 4317 | break; |
| 4318 | case kCondGT: |
| 4319 | __ Blt(rhs_reg, lhs, label); |
| 4320 | break; |
| 4321 | case kCondB: |
| 4322 | __ Bltu(lhs, rhs_reg, label); |
| 4323 | break; |
| 4324 | case kCondAE: |
| 4325 | __ Bgeu(lhs, rhs_reg, label); |
| 4326 | break; |
| 4327 | case kCondBE: |
| 4328 | __ Bgeu(rhs_reg, lhs, label); |
| 4329 | break; |
| 4330 | case kCondA: |
| 4331 | __ Bltu(rhs_reg, lhs, label); |
| 4332 | break; |
| 4333 | } |
| 4334 | } else { |
| 4335 | // Special cases for more efficient comparison with constants on R2. |
| 4336 | switch (cond) { |
| 4337 | case kCondEQ: |
| 4338 | __ LoadConst32(TMP, rhs_imm); |
| 4339 | __ Beq(lhs, TMP, label); |
| 4340 | break; |
| 4341 | case kCondNE: |
| 4342 | __ LoadConst32(TMP, rhs_imm); |
| 4343 | __ Bne(lhs, TMP, label); |
| 4344 | break; |
| 4345 | case kCondLT: |
| 4346 | if (IsInt<16>(rhs_imm)) { |
| 4347 | __ Slti(TMP, lhs, rhs_imm); |
| 4348 | __ Bnez(TMP, label); |
| 4349 | } else { |
| 4350 | __ LoadConst32(TMP, rhs_imm); |
| 4351 | __ Blt(lhs, TMP, label); |
| 4352 | } |
| 4353 | break; |
| 4354 | case kCondGE: |
| 4355 | if (IsInt<16>(rhs_imm)) { |
| 4356 | __ Slti(TMP, lhs, rhs_imm); |
| 4357 | __ Beqz(TMP, label); |
| 4358 | } else { |
| 4359 | __ LoadConst32(TMP, rhs_imm); |
| 4360 | __ Bge(lhs, TMP, label); |
| 4361 | } |
| 4362 | break; |
| 4363 | case kCondLE: |
| 4364 | if (IsInt<16>(rhs_imm + 1)) { |
| 4365 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4366 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4367 | __ Bnez(TMP, label); |
| 4368 | } else { |
| 4369 | __ LoadConst32(TMP, rhs_imm); |
| 4370 | __ Bge(TMP, lhs, label); |
| 4371 | } |
| 4372 | break; |
| 4373 | case kCondGT: |
| 4374 | if (IsInt<16>(rhs_imm + 1)) { |
| 4375 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4376 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4377 | __ Beqz(TMP, label); |
| 4378 | } else { |
| 4379 | __ LoadConst32(TMP, rhs_imm); |
| 4380 | __ Blt(TMP, lhs, label); |
| 4381 | } |
| 4382 | break; |
| 4383 | case kCondB: |
| 4384 | if (IsInt<16>(rhs_imm)) { |
| 4385 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4386 | __ Bnez(TMP, label); |
| 4387 | } else { |
| 4388 | __ LoadConst32(TMP, rhs_imm); |
| 4389 | __ Bltu(lhs, TMP, label); |
| 4390 | } |
| 4391 | break; |
| 4392 | case kCondAE: |
| 4393 | if (IsInt<16>(rhs_imm)) { |
| 4394 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4395 | __ Beqz(TMP, label); |
| 4396 | } else { |
| 4397 | __ LoadConst32(TMP, rhs_imm); |
| 4398 | __ Bgeu(lhs, TMP, label); |
| 4399 | } |
| 4400 | break; |
| 4401 | case kCondBE: |
| 4402 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4403 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4404 | // Note that this only works if rhs + 1 does not overflow |
| 4405 | // to 0, hence the check above. |
| 4406 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4407 | __ Bnez(TMP, label); |
| 4408 | } else { |
| 4409 | __ LoadConst32(TMP, rhs_imm); |
| 4410 | __ Bgeu(TMP, lhs, label); |
| 4411 | } |
| 4412 | break; |
| 4413 | case kCondA: |
| 4414 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4415 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4416 | // Note that this only works if rhs + 1 does not overflow |
| 4417 | // to 0, hence the check above. |
| 4418 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4419 | __ Beqz(TMP, label); |
| 4420 | } else { |
| 4421 | __ LoadConst32(TMP, rhs_imm); |
| 4422 | __ Bltu(TMP, lhs, label); |
| 4423 | } |
| 4424 | break; |
| 4425 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4426 | } |
| 4427 | } |
| 4428 | } |
| 4429 | |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 4430 | void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond, |
| 4431 | LocationSummary* locations) { |
| 4432 | Register dst = locations->Out().AsRegister<Register>(); |
| 4433 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4434 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4435 | Location rhs_location = locations->InAt(1); |
| 4436 | Register rhs_high = ZERO; |
| 4437 | Register rhs_low = ZERO; |
| 4438 | int64_t imm = 0; |
| 4439 | uint32_t imm_high = 0; |
| 4440 | uint32_t imm_low = 0; |
| 4441 | bool use_imm = rhs_location.IsConstant(); |
| 4442 | if (use_imm) { |
| 4443 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4444 | imm_high = High32Bits(imm); |
| 4445 | imm_low = Low32Bits(imm); |
| 4446 | } else { |
| 4447 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4448 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4449 | } |
| 4450 | if (use_imm && imm == 0) { |
| 4451 | switch (cond) { |
| 4452 | case kCondEQ: |
| 4453 | case kCondBE: // <= 0 if zero |
| 4454 | __ Or(dst, lhs_high, lhs_low); |
| 4455 | __ Sltiu(dst, dst, 1); |
| 4456 | break; |
| 4457 | case kCondNE: |
| 4458 | case kCondA: // > 0 if non-zero |
| 4459 | __ Or(dst, lhs_high, lhs_low); |
| 4460 | __ Sltu(dst, ZERO, dst); |
| 4461 | break; |
| 4462 | case kCondLT: |
| 4463 | __ Slt(dst, lhs_high, ZERO); |
| 4464 | break; |
| 4465 | case kCondGE: |
| 4466 | __ Slt(dst, lhs_high, ZERO); |
| 4467 | __ Xori(dst, dst, 1); |
| 4468 | break; |
| 4469 | case kCondLE: |
| 4470 | __ Or(TMP, lhs_high, lhs_low); |
| 4471 | __ Sra(AT, lhs_high, 31); |
| 4472 | __ Sltu(dst, AT, TMP); |
| 4473 | __ Xori(dst, dst, 1); |
| 4474 | break; |
| 4475 | case kCondGT: |
| 4476 | __ Or(TMP, lhs_high, lhs_low); |
| 4477 | __ Sra(AT, lhs_high, 31); |
| 4478 | __ Sltu(dst, AT, TMP); |
| 4479 | break; |
| 4480 | case kCondB: // always false |
| 4481 | __ Andi(dst, dst, 0); |
| 4482 | break; |
| 4483 | case kCondAE: // always true |
| 4484 | __ Ori(dst, ZERO, 1); |
| 4485 | break; |
| 4486 | } |
| 4487 | } else if (use_imm) { |
| 4488 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4489 | switch (cond) { |
| 4490 | case kCondEQ: |
| 4491 | __ LoadConst32(TMP, imm_high); |
| 4492 | __ Xor(TMP, TMP, lhs_high); |
| 4493 | __ LoadConst32(AT, imm_low); |
| 4494 | __ Xor(AT, AT, lhs_low); |
| 4495 | __ Or(dst, TMP, AT); |
| 4496 | __ Sltiu(dst, dst, 1); |
| 4497 | break; |
| 4498 | case kCondNE: |
| 4499 | __ LoadConst32(TMP, imm_high); |
| 4500 | __ Xor(TMP, TMP, lhs_high); |
| 4501 | __ LoadConst32(AT, imm_low); |
| 4502 | __ Xor(AT, AT, lhs_low); |
| 4503 | __ Or(dst, TMP, AT); |
| 4504 | __ Sltu(dst, ZERO, dst); |
| 4505 | break; |
| 4506 | case kCondLT: |
| 4507 | case kCondGE: |
| 4508 | if (dst == lhs_low) { |
| 4509 | __ LoadConst32(TMP, imm_low); |
| 4510 | __ Sltu(dst, lhs_low, TMP); |
| 4511 | } |
| 4512 | __ LoadConst32(TMP, imm_high); |
| 4513 | __ Slt(AT, lhs_high, TMP); |
| 4514 | __ Slt(TMP, TMP, lhs_high); |
| 4515 | if (dst != lhs_low) { |
| 4516 | __ LoadConst32(dst, imm_low); |
| 4517 | __ Sltu(dst, lhs_low, dst); |
| 4518 | } |
| 4519 | __ Slt(dst, TMP, dst); |
| 4520 | __ Or(dst, dst, AT); |
| 4521 | if (cond == kCondGE) { |
| 4522 | __ Xori(dst, dst, 1); |
| 4523 | } |
| 4524 | break; |
| 4525 | case kCondGT: |
| 4526 | case kCondLE: |
| 4527 | if (dst == lhs_low) { |
| 4528 | __ LoadConst32(TMP, imm_low); |
| 4529 | __ Sltu(dst, TMP, lhs_low); |
| 4530 | } |
| 4531 | __ LoadConst32(TMP, imm_high); |
| 4532 | __ Slt(AT, TMP, lhs_high); |
| 4533 | __ Slt(TMP, lhs_high, TMP); |
| 4534 | if (dst != lhs_low) { |
| 4535 | __ LoadConst32(dst, imm_low); |
| 4536 | __ Sltu(dst, dst, lhs_low); |
| 4537 | } |
| 4538 | __ Slt(dst, TMP, dst); |
| 4539 | __ Or(dst, dst, AT); |
| 4540 | if (cond == kCondLE) { |
| 4541 | __ Xori(dst, dst, 1); |
| 4542 | } |
| 4543 | break; |
| 4544 | case kCondB: |
| 4545 | case kCondAE: |
| 4546 | if (dst == lhs_low) { |
| 4547 | __ LoadConst32(TMP, imm_low); |
| 4548 | __ Sltu(dst, lhs_low, TMP); |
| 4549 | } |
| 4550 | __ LoadConst32(TMP, imm_high); |
| 4551 | __ Sltu(AT, lhs_high, TMP); |
| 4552 | __ Sltu(TMP, TMP, lhs_high); |
| 4553 | if (dst != lhs_low) { |
| 4554 | __ LoadConst32(dst, imm_low); |
| 4555 | __ Sltu(dst, lhs_low, dst); |
| 4556 | } |
| 4557 | __ Slt(dst, TMP, dst); |
| 4558 | __ Or(dst, dst, AT); |
| 4559 | if (cond == kCondAE) { |
| 4560 | __ Xori(dst, dst, 1); |
| 4561 | } |
| 4562 | break; |
| 4563 | case kCondA: |
| 4564 | case kCondBE: |
| 4565 | if (dst == lhs_low) { |
| 4566 | __ LoadConst32(TMP, imm_low); |
| 4567 | __ Sltu(dst, TMP, lhs_low); |
| 4568 | } |
| 4569 | __ LoadConst32(TMP, imm_high); |
| 4570 | __ Sltu(AT, TMP, lhs_high); |
| 4571 | __ Sltu(TMP, lhs_high, TMP); |
| 4572 | if (dst != lhs_low) { |
| 4573 | __ LoadConst32(dst, imm_low); |
| 4574 | __ Sltu(dst, dst, lhs_low); |
| 4575 | } |
| 4576 | __ Slt(dst, TMP, dst); |
| 4577 | __ Or(dst, dst, AT); |
| 4578 | if (cond == kCondBE) { |
| 4579 | __ Xori(dst, dst, 1); |
| 4580 | } |
| 4581 | break; |
| 4582 | } |
| 4583 | } else { |
| 4584 | switch (cond) { |
| 4585 | case kCondEQ: |
| 4586 | __ Xor(TMP, lhs_high, rhs_high); |
| 4587 | __ Xor(AT, lhs_low, rhs_low); |
| 4588 | __ Or(dst, TMP, AT); |
| 4589 | __ Sltiu(dst, dst, 1); |
| 4590 | break; |
| 4591 | case kCondNE: |
| 4592 | __ Xor(TMP, lhs_high, rhs_high); |
| 4593 | __ Xor(AT, lhs_low, rhs_low); |
| 4594 | __ Or(dst, TMP, AT); |
| 4595 | __ Sltu(dst, ZERO, dst); |
| 4596 | break; |
| 4597 | case kCondLT: |
| 4598 | case kCondGE: |
| 4599 | __ Slt(TMP, rhs_high, lhs_high); |
| 4600 | __ Sltu(AT, lhs_low, rhs_low); |
| 4601 | __ Slt(TMP, TMP, AT); |
| 4602 | __ Slt(AT, lhs_high, rhs_high); |
| 4603 | __ Or(dst, AT, TMP); |
| 4604 | if (cond == kCondGE) { |
| 4605 | __ Xori(dst, dst, 1); |
| 4606 | } |
| 4607 | break; |
| 4608 | case kCondGT: |
| 4609 | case kCondLE: |
| 4610 | __ Slt(TMP, lhs_high, rhs_high); |
| 4611 | __ Sltu(AT, rhs_low, lhs_low); |
| 4612 | __ Slt(TMP, TMP, AT); |
| 4613 | __ Slt(AT, rhs_high, lhs_high); |
| 4614 | __ Or(dst, AT, TMP); |
| 4615 | if (cond == kCondLE) { |
| 4616 | __ Xori(dst, dst, 1); |
| 4617 | } |
| 4618 | break; |
| 4619 | case kCondB: |
| 4620 | case kCondAE: |
| 4621 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4622 | __ Sltu(AT, lhs_low, rhs_low); |
| 4623 | __ Slt(TMP, TMP, AT); |
| 4624 | __ Sltu(AT, lhs_high, rhs_high); |
| 4625 | __ Or(dst, AT, TMP); |
| 4626 | if (cond == kCondAE) { |
| 4627 | __ Xori(dst, dst, 1); |
| 4628 | } |
| 4629 | break; |
| 4630 | case kCondA: |
| 4631 | case kCondBE: |
| 4632 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4633 | __ Sltu(AT, rhs_low, lhs_low); |
| 4634 | __ Slt(TMP, TMP, AT); |
| 4635 | __ Sltu(AT, rhs_high, lhs_high); |
| 4636 | __ Or(dst, AT, TMP); |
| 4637 | if (cond == kCondBE) { |
| 4638 | __ Xori(dst, dst, 1); |
| 4639 | } |
| 4640 | break; |
| 4641 | } |
| 4642 | } |
| 4643 | } |
| 4644 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4645 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 4646 | LocationSummary* locations, |
| 4647 | MipsLabel* label) { |
| 4648 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4649 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4650 | Location rhs_location = locations->InAt(1); |
| 4651 | Register rhs_high = ZERO; |
| 4652 | Register rhs_low = ZERO; |
| 4653 | int64_t imm = 0; |
| 4654 | uint32_t imm_high = 0; |
| 4655 | uint32_t imm_low = 0; |
| 4656 | bool use_imm = rhs_location.IsConstant(); |
| 4657 | if (use_imm) { |
| 4658 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4659 | imm_high = High32Bits(imm); |
| 4660 | imm_low = Low32Bits(imm); |
| 4661 | } else { |
| 4662 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4663 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4664 | } |
| 4665 | |
| 4666 | if (use_imm && imm == 0) { |
| 4667 | switch (cond) { |
| 4668 | case kCondEQ: |
| 4669 | case kCondBE: // <= 0 if zero |
| 4670 | __ Or(TMP, lhs_high, lhs_low); |
| 4671 | __ Beqz(TMP, label); |
| 4672 | break; |
| 4673 | case kCondNE: |
| 4674 | case kCondA: // > 0 if non-zero |
| 4675 | __ Or(TMP, lhs_high, lhs_low); |
| 4676 | __ Bnez(TMP, label); |
| 4677 | break; |
| 4678 | case kCondLT: |
| 4679 | __ Bltz(lhs_high, label); |
| 4680 | break; |
| 4681 | case kCondGE: |
| 4682 | __ Bgez(lhs_high, label); |
| 4683 | break; |
| 4684 | case kCondLE: |
| 4685 | __ Or(TMP, lhs_high, lhs_low); |
| 4686 | __ Sra(AT, lhs_high, 31); |
| 4687 | __ Bgeu(AT, TMP, label); |
| 4688 | break; |
| 4689 | case kCondGT: |
| 4690 | __ Or(TMP, lhs_high, lhs_low); |
| 4691 | __ Sra(AT, lhs_high, 31); |
| 4692 | __ Bltu(AT, TMP, label); |
| 4693 | break; |
| 4694 | case kCondB: // always false |
| 4695 | break; |
| 4696 | case kCondAE: // always true |
| 4697 | __ B(label); |
| 4698 | break; |
| 4699 | } |
| 4700 | } else if (use_imm) { |
| 4701 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4702 | switch (cond) { |
| 4703 | case kCondEQ: |
| 4704 | __ LoadConst32(TMP, imm_high); |
| 4705 | __ Xor(TMP, TMP, lhs_high); |
| 4706 | __ LoadConst32(AT, imm_low); |
| 4707 | __ Xor(AT, AT, lhs_low); |
| 4708 | __ Or(TMP, TMP, AT); |
| 4709 | __ Beqz(TMP, label); |
| 4710 | break; |
| 4711 | case kCondNE: |
| 4712 | __ LoadConst32(TMP, imm_high); |
| 4713 | __ Xor(TMP, TMP, lhs_high); |
| 4714 | __ LoadConst32(AT, imm_low); |
| 4715 | __ Xor(AT, AT, lhs_low); |
| 4716 | __ Or(TMP, TMP, AT); |
| 4717 | __ Bnez(TMP, label); |
| 4718 | break; |
| 4719 | case kCondLT: |
| 4720 | __ LoadConst32(TMP, imm_high); |
| 4721 | __ Blt(lhs_high, TMP, label); |
| 4722 | __ Slt(TMP, TMP, lhs_high); |
| 4723 | __ LoadConst32(AT, imm_low); |
| 4724 | __ Sltu(AT, lhs_low, AT); |
| 4725 | __ Blt(TMP, AT, label); |
| 4726 | break; |
| 4727 | case kCondGE: |
| 4728 | __ LoadConst32(TMP, imm_high); |
| 4729 | __ Blt(TMP, lhs_high, label); |
| 4730 | __ Slt(TMP, lhs_high, TMP); |
| 4731 | __ LoadConst32(AT, imm_low); |
| 4732 | __ Sltu(AT, lhs_low, AT); |
| 4733 | __ Or(TMP, TMP, AT); |
| 4734 | __ Beqz(TMP, label); |
| 4735 | break; |
| 4736 | case kCondLE: |
| 4737 | __ LoadConst32(TMP, imm_high); |
| 4738 | __ Blt(lhs_high, TMP, label); |
| 4739 | __ Slt(TMP, TMP, lhs_high); |
| 4740 | __ LoadConst32(AT, imm_low); |
| 4741 | __ Sltu(AT, AT, lhs_low); |
| 4742 | __ Or(TMP, TMP, AT); |
| 4743 | __ Beqz(TMP, label); |
| 4744 | break; |
| 4745 | case kCondGT: |
| 4746 | __ LoadConst32(TMP, imm_high); |
| 4747 | __ Blt(TMP, lhs_high, label); |
| 4748 | __ Slt(TMP, lhs_high, TMP); |
| 4749 | __ LoadConst32(AT, imm_low); |
| 4750 | __ Sltu(AT, AT, lhs_low); |
| 4751 | __ Blt(TMP, AT, label); |
| 4752 | break; |
| 4753 | case kCondB: |
| 4754 | __ LoadConst32(TMP, imm_high); |
| 4755 | __ Bltu(lhs_high, TMP, label); |
| 4756 | __ Sltu(TMP, TMP, lhs_high); |
| 4757 | __ LoadConst32(AT, imm_low); |
| 4758 | __ Sltu(AT, lhs_low, AT); |
| 4759 | __ Blt(TMP, AT, label); |
| 4760 | break; |
| 4761 | case kCondAE: |
| 4762 | __ LoadConst32(TMP, imm_high); |
| 4763 | __ Bltu(TMP, lhs_high, label); |
| 4764 | __ Sltu(TMP, lhs_high, TMP); |
| 4765 | __ LoadConst32(AT, imm_low); |
| 4766 | __ Sltu(AT, lhs_low, AT); |
| 4767 | __ Or(TMP, TMP, AT); |
| 4768 | __ Beqz(TMP, label); |
| 4769 | break; |
| 4770 | case kCondBE: |
| 4771 | __ LoadConst32(TMP, imm_high); |
| 4772 | __ Bltu(lhs_high, TMP, label); |
| 4773 | __ Sltu(TMP, TMP, lhs_high); |
| 4774 | __ LoadConst32(AT, imm_low); |
| 4775 | __ Sltu(AT, AT, lhs_low); |
| 4776 | __ Or(TMP, TMP, AT); |
| 4777 | __ Beqz(TMP, label); |
| 4778 | break; |
| 4779 | case kCondA: |
| 4780 | __ LoadConst32(TMP, imm_high); |
| 4781 | __ Bltu(TMP, lhs_high, label); |
| 4782 | __ Sltu(TMP, lhs_high, TMP); |
| 4783 | __ LoadConst32(AT, imm_low); |
| 4784 | __ Sltu(AT, AT, lhs_low); |
| 4785 | __ Blt(TMP, AT, label); |
| 4786 | break; |
| 4787 | } |
| 4788 | } else { |
| 4789 | switch (cond) { |
| 4790 | case kCondEQ: |
| 4791 | __ Xor(TMP, lhs_high, rhs_high); |
| 4792 | __ Xor(AT, lhs_low, rhs_low); |
| 4793 | __ Or(TMP, TMP, AT); |
| 4794 | __ Beqz(TMP, label); |
| 4795 | break; |
| 4796 | case kCondNE: |
| 4797 | __ Xor(TMP, lhs_high, rhs_high); |
| 4798 | __ Xor(AT, lhs_low, rhs_low); |
| 4799 | __ Or(TMP, TMP, AT); |
| 4800 | __ Bnez(TMP, label); |
| 4801 | break; |
| 4802 | case kCondLT: |
| 4803 | __ Blt(lhs_high, rhs_high, label); |
| 4804 | __ Slt(TMP, rhs_high, lhs_high); |
| 4805 | __ Sltu(AT, lhs_low, rhs_low); |
| 4806 | __ Blt(TMP, AT, label); |
| 4807 | break; |
| 4808 | case kCondGE: |
| 4809 | __ Blt(rhs_high, lhs_high, label); |
| 4810 | __ Slt(TMP, lhs_high, rhs_high); |
| 4811 | __ Sltu(AT, lhs_low, rhs_low); |
| 4812 | __ Or(TMP, TMP, AT); |
| 4813 | __ Beqz(TMP, label); |
| 4814 | break; |
| 4815 | case kCondLE: |
| 4816 | __ Blt(lhs_high, rhs_high, label); |
| 4817 | __ Slt(TMP, rhs_high, lhs_high); |
| 4818 | __ Sltu(AT, rhs_low, lhs_low); |
| 4819 | __ Or(TMP, TMP, AT); |
| 4820 | __ Beqz(TMP, label); |
| 4821 | break; |
| 4822 | case kCondGT: |
| 4823 | __ Blt(rhs_high, lhs_high, label); |
| 4824 | __ Slt(TMP, lhs_high, rhs_high); |
| 4825 | __ Sltu(AT, rhs_low, lhs_low); |
| 4826 | __ Blt(TMP, AT, label); |
| 4827 | break; |
| 4828 | case kCondB: |
| 4829 | __ Bltu(lhs_high, rhs_high, label); |
| 4830 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4831 | __ Sltu(AT, lhs_low, rhs_low); |
| 4832 | __ Blt(TMP, AT, label); |
| 4833 | break; |
| 4834 | case kCondAE: |
| 4835 | __ Bltu(rhs_high, lhs_high, label); |
| 4836 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4837 | __ Sltu(AT, lhs_low, rhs_low); |
| 4838 | __ Or(TMP, TMP, AT); |
| 4839 | __ Beqz(TMP, label); |
| 4840 | break; |
| 4841 | case kCondBE: |
| 4842 | __ Bltu(lhs_high, rhs_high, label); |
| 4843 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4844 | __ Sltu(AT, rhs_low, lhs_low); |
| 4845 | __ Or(TMP, TMP, AT); |
| 4846 | __ Beqz(TMP, label); |
| 4847 | break; |
| 4848 | case kCondA: |
| 4849 | __ Bltu(rhs_high, lhs_high, label); |
| 4850 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4851 | __ Sltu(AT, rhs_low, lhs_low); |
| 4852 | __ Blt(TMP, AT, label); |
| 4853 | break; |
| 4854 | } |
| 4855 | } |
| 4856 | } |
| 4857 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4858 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 4859 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4860 | DataType::Type type, |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4861 | LocationSummary* locations) { |
| 4862 | Register dst = locations->Out().AsRegister<Register>(); |
| 4863 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4864 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 4865 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4866 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4867 | if (isR6) { |
| 4868 | switch (cond) { |
| 4869 | case kCondEQ: |
| 4870 | __ CmpEqS(FTMP, lhs, rhs); |
| 4871 | __ Mfc1(dst, FTMP); |
| 4872 | __ Andi(dst, dst, 1); |
| 4873 | break; |
| 4874 | case kCondNE: |
| 4875 | __ CmpEqS(FTMP, lhs, rhs); |
| 4876 | __ Mfc1(dst, FTMP); |
| 4877 | __ Addiu(dst, dst, 1); |
| 4878 | break; |
| 4879 | case kCondLT: |
| 4880 | if (gt_bias) { |
| 4881 | __ CmpLtS(FTMP, lhs, rhs); |
| 4882 | } else { |
| 4883 | __ CmpUltS(FTMP, lhs, rhs); |
| 4884 | } |
| 4885 | __ Mfc1(dst, FTMP); |
| 4886 | __ Andi(dst, dst, 1); |
| 4887 | break; |
| 4888 | case kCondLE: |
| 4889 | if (gt_bias) { |
| 4890 | __ CmpLeS(FTMP, lhs, rhs); |
| 4891 | } else { |
| 4892 | __ CmpUleS(FTMP, lhs, rhs); |
| 4893 | } |
| 4894 | __ Mfc1(dst, FTMP); |
| 4895 | __ Andi(dst, dst, 1); |
| 4896 | break; |
| 4897 | case kCondGT: |
| 4898 | if (gt_bias) { |
| 4899 | __ CmpUltS(FTMP, rhs, lhs); |
| 4900 | } else { |
| 4901 | __ CmpLtS(FTMP, rhs, lhs); |
| 4902 | } |
| 4903 | __ Mfc1(dst, FTMP); |
| 4904 | __ Andi(dst, dst, 1); |
| 4905 | break; |
| 4906 | case kCondGE: |
| 4907 | if (gt_bias) { |
| 4908 | __ CmpUleS(FTMP, rhs, lhs); |
| 4909 | } else { |
| 4910 | __ CmpLeS(FTMP, rhs, lhs); |
| 4911 | } |
| 4912 | __ Mfc1(dst, FTMP); |
| 4913 | __ Andi(dst, dst, 1); |
| 4914 | break; |
| 4915 | default: |
| 4916 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4917 | UNREACHABLE(); |
| 4918 | } |
| 4919 | } else { |
| 4920 | switch (cond) { |
| 4921 | case kCondEQ: |
| 4922 | __ CeqS(0, lhs, rhs); |
| 4923 | __ LoadConst32(dst, 1); |
| 4924 | __ Movf(dst, ZERO, 0); |
| 4925 | break; |
| 4926 | case kCondNE: |
| 4927 | __ CeqS(0, lhs, rhs); |
| 4928 | __ LoadConst32(dst, 1); |
| 4929 | __ Movt(dst, ZERO, 0); |
| 4930 | break; |
| 4931 | case kCondLT: |
| 4932 | if (gt_bias) { |
| 4933 | __ ColtS(0, lhs, rhs); |
| 4934 | } else { |
| 4935 | __ CultS(0, lhs, rhs); |
| 4936 | } |
| 4937 | __ LoadConst32(dst, 1); |
| 4938 | __ Movf(dst, ZERO, 0); |
| 4939 | break; |
| 4940 | case kCondLE: |
| 4941 | if (gt_bias) { |
| 4942 | __ ColeS(0, lhs, rhs); |
| 4943 | } else { |
| 4944 | __ CuleS(0, lhs, rhs); |
| 4945 | } |
| 4946 | __ LoadConst32(dst, 1); |
| 4947 | __ Movf(dst, ZERO, 0); |
| 4948 | break; |
| 4949 | case kCondGT: |
| 4950 | if (gt_bias) { |
| 4951 | __ CultS(0, rhs, lhs); |
| 4952 | } else { |
| 4953 | __ ColtS(0, rhs, lhs); |
| 4954 | } |
| 4955 | __ LoadConst32(dst, 1); |
| 4956 | __ Movf(dst, ZERO, 0); |
| 4957 | break; |
| 4958 | case kCondGE: |
| 4959 | if (gt_bias) { |
| 4960 | __ CuleS(0, rhs, lhs); |
| 4961 | } else { |
| 4962 | __ ColeS(0, rhs, lhs); |
| 4963 | } |
| 4964 | __ LoadConst32(dst, 1); |
| 4965 | __ Movf(dst, ZERO, 0); |
| 4966 | break; |
| 4967 | default: |
| 4968 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4969 | UNREACHABLE(); |
| 4970 | } |
| 4971 | } |
| 4972 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4973 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4974 | if (isR6) { |
| 4975 | switch (cond) { |
| 4976 | case kCondEQ: |
| 4977 | __ CmpEqD(FTMP, lhs, rhs); |
| 4978 | __ Mfc1(dst, FTMP); |
| 4979 | __ Andi(dst, dst, 1); |
| 4980 | break; |
| 4981 | case kCondNE: |
| 4982 | __ CmpEqD(FTMP, lhs, rhs); |
| 4983 | __ Mfc1(dst, FTMP); |
| 4984 | __ Addiu(dst, dst, 1); |
| 4985 | break; |
| 4986 | case kCondLT: |
| 4987 | if (gt_bias) { |
| 4988 | __ CmpLtD(FTMP, lhs, rhs); |
| 4989 | } else { |
| 4990 | __ CmpUltD(FTMP, lhs, rhs); |
| 4991 | } |
| 4992 | __ Mfc1(dst, FTMP); |
| 4993 | __ Andi(dst, dst, 1); |
| 4994 | break; |
| 4995 | case kCondLE: |
| 4996 | if (gt_bias) { |
| 4997 | __ CmpLeD(FTMP, lhs, rhs); |
| 4998 | } else { |
| 4999 | __ CmpUleD(FTMP, lhs, rhs); |
| 5000 | } |
| 5001 | __ Mfc1(dst, FTMP); |
| 5002 | __ Andi(dst, dst, 1); |
| 5003 | break; |
| 5004 | case kCondGT: |
| 5005 | if (gt_bias) { |
| 5006 | __ CmpUltD(FTMP, rhs, lhs); |
| 5007 | } else { |
| 5008 | __ CmpLtD(FTMP, rhs, lhs); |
| 5009 | } |
| 5010 | __ Mfc1(dst, FTMP); |
| 5011 | __ Andi(dst, dst, 1); |
| 5012 | break; |
| 5013 | case kCondGE: |
| 5014 | if (gt_bias) { |
| 5015 | __ CmpUleD(FTMP, rhs, lhs); |
| 5016 | } else { |
| 5017 | __ CmpLeD(FTMP, rhs, lhs); |
| 5018 | } |
| 5019 | __ Mfc1(dst, FTMP); |
| 5020 | __ Andi(dst, dst, 1); |
| 5021 | break; |
| 5022 | default: |
| 5023 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5024 | UNREACHABLE(); |
| 5025 | } |
| 5026 | } else { |
| 5027 | switch (cond) { |
| 5028 | case kCondEQ: |
| 5029 | __ CeqD(0, lhs, rhs); |
| 5030 | __ LoadConst32(dst, 1); |
| 5031 | __ Movf(dst, ZERO, 0); |
| 5032 | break; |
| 5033 | case kCondNE: |
| 5034 | __ CeqD(0, lhs, rhs); |
| 5035 | __ LoadConst32(dst, 1); |
| 5036 | __ Movt(dst, ZERO, 0); |
| 5037 | break; |
| 5038 | case kCondLT: |
| 5039 | if (gt_bias) { |
| 5040 | __ ColtD(0, lhs, rhs); |
| 5041 | } else { |
| 5042 | __ CultD(0, lhs, rhs); |
| 5043 | } |
| 5044 | __ LoadConst32(dst, 1); |
| 5045 | __ Movf(dst, ZERO, 0); |
| 5046 | break; |
| 5047 | case kCondLE: |
| 5048 | if (gt_bias) { |
| 5049 | __ ColeD(0, lhs, rhs); |
| 5050 | } else { |
| 5051 | __ CuleD(0, lhs, rhs); |
| 5052 | } |
| 5053 | __ LoadConst32(dst, 1); |
| 5054 | __ Movf(dst, ZERO, 0); |
| 5055 | break; |
| 5056 | case kCondGT: |
| 5057 | if (gt_bias) { |
| 5058 | __ CultD(0, rhs, lhs); |
| 5059 | } else { |
| 5060 | __ ColtD(0, rhs, lhs); |
| 5061 | } |
| 5062 | __ LoadConst32(dst, 1); |
| 5063 | __ Movf(dst, ZERO, 0); |
| 5064 | break; |
| 5065 | case kCondGE: |
| 5066 | if (gt_bias) { |
| 5067 | __ CuleD(0, rhs, lhs); |
| 5068 | } else { |
| 5069 | __ ColeD(0, rhs, lhs); |
| 5070 | } |
| 5071 | __ LoadConst32(dst, 1); |
| 5072 | __ Movf(dst, ZERO, 0); |
| 5073 | break; |
| 5074 | default: |
| 5075 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5076 | UNREACHABLE(); |
| 5077 | } |
| 5078 | } |
| 5079 | } |
| 5080 | } |
| 5081 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5082 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 5083 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5084 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5085 | LocationSummary* input_locations, |
| 5086 | int cc) { |
| 5087 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5088 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5089 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5090 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5091 | switch (cond) { |
| 5092 | case kCondEQ: |
| 5093 | __ CeqS(cc, lhs, rhs); |
| 5094 | return false; |
| 5095 | case kCondNE: |
| 5096 | __ CeqS(cc, lhs, rhs); |
| 5097 | return true; |
| 5098 | case kCondLT: |
| 5099 | if (gt_bias) { |
| 5100 | __ ColtS(cc, lhs, rhs); |
| 5101 | } else { |
| 5102 | __ CultS(cc, lhs, rhs); |
| 5103 | } |
| 5104 | return false; |
| 5105 | case kCondLE: |
| 5106 | if (gt_bias) { |
| 5107 | __ ColeS(cc, lhs, rhs); |
| 5108 | } else { |
| 5109 | __ CuleS(cc, lhs, rhs); |
| 5110 | } |
| 5111 | return false; |
| 5112 | case kCondGT: |
| 5113 | if (gt_bias) { |
| 5114 | __ CultS(cc, rhs, lhs); |
| 5115 | } else { |
| 5116 | __ ColtS(cc, rhs, lhs); |
| 5117 | } |
| 5118 | return false; |
| 5119 | case kCondGE: |
| 5120 | if (gt_bias) { |
| 5121 | __ CuleS(cc, rhs, lhs); |
| 5122 | } else { |
| 5123 | __ ColeS(cc, rhs, lhs); |
| 5124 | } |
| 5125 | return false; |
| 5126 | default: |
| 5127 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5128 | UNREACHABLE(); |
| 5129 | } |
| 5130 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5131 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5132 | switch (cond) { |
| 5133 | case kCondEQ: |
| 5134 | __ CeqD(cc, lhs, rhs); |
| 5135 | return false; |
| 5136 | case kCondNE: |
| 5137 | __ CeqD(cc, lhs, rhs); |
| 5138 | return true; |
| 5139 | case kCondLT: |
| 5140 | if (gt_bias) { |
| 5141 | __ ColtD(cc, lhs, rhs); |
| 5142 | } else { |
| 5143 | __ CultD(cc, lhs, rhs); |
| 5144 | } |
| 5145 | return false; |
| 5146 | case kCondLE: |
| 5147 | if (gt_bias) { |
| 5148 | __ ColeD(cc, lhs, rhs); |
| 5149 | } else { |
| 5150 | __ CuleD(cc, lhs, rhs); |
| 5151 | } |
| 5152 | return false; |
| 5153 | case kCondGT: |
| 5154 | if (gt_bias) { |
| 5155 | __ CultD(cc, rhs, lhs); |
| 5156 | } else { |
| 5157 | __ ColtD(cc, rhs, lhs); |
| 5158 | } |
| 5159 | return false; |
| 5160 | case kCondGE: |
| 5161 | if (gt_bias) { |
| 5162 | __ CuleD(cc, rhs, lhs); |
| 5163 | } else { |
| 5164 | __ ColeD(cc, rhs, lhs); |
| 5165 | } |
| 5166 | return false; |
| 5167 | default: |
| 5168 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5169 | UNREACHABLE(); |
| 5170 | } |
| 5171 | } |
| 5172 | } |
| 5173 | |
| 5174 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 5175 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5176 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5177 | LocationSummary* input_locations, |
| 5178 | FRegister dst) { |
| 5179 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5180 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5181 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5182 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5183 | switch (cond) { |
| 5184 | case kCondEQ: |
| 5185 | __ CmpEqS(dst, lhs, rhs); |
| 5186 | return false; |
| 5187 | case kCondNE: |
| 5188 | __ CmpEqS(dst, lhs, rhs); |
| 5189 | return true; |
| 5190 | case kCondLT: |
| 5191 | if (gt_bias) { |
| 5192 | __ CmpLtS(dst, lhs, rhs); |
| 5193 | } else { |
| 5194 | __ CmpUltS(dst, lhs, rhs); |
| 5195 | } |
| 5196 | return false; |
| 5197 | case kCondLE: |
| 5198 | if (gt_bias) { |
| 5199 | __ CmpLeS(dst, lhs, rhs); |
| 5200 | } else { |
| 5201 | __ CmpUleS(dst, lhs, rhs); |
| 5202 | } |
| 5203 | return false; |
| 5204 | case kCondGT: |
| 5205 | if (gt_bias) { |
| 5206 | __ CmpUltS(dst, rhs, lhs); |
| 5207 | } else { |
| 5208 | __ CmpLtS(dst, rhs, lhs); |
| 5209 | } |
| 5210 | return false; |
| 5211 | case kCondGE: |
| 5212 | if (gt_bias) { |
| 5213 | __ CmpUleS(dst, rhs, lhs); |
| 5214 | } else { |
| 5215 | __ CmpLeS(dst, rhs, lhs); |
| 5216 | } |
| 5217 | return false; |
| 5218 | default: |
| 5219 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5220 | UNREACHABLE(); |
| 5221 | } |
| 5222 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5223 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5224 | switch (cond) { |
| 5225 | case kCondEQ: |
| 5226 | __ CmpEqD(dst, lhs, rhs); |
| 5227 | return false; |
| 5228 | case kCondNE: |
| 5229 | __ CmpEqD(dst, lhs, rhs); |
| 5230 | return true; |
| 5231 | case kCondLT: |
| 5232 | if (gt_bias) { |
| 5233 | __ CmpLtD(dst, lhs, rhs); |
| 5234 | } else { |
| 5235 | __ CmpUltD(dst, lhs, rhs); |
| 5236 | } |
| 5237 | return false; |
| 5238 | case kCondLE: |
| 5239 | if (gt_bias) { |
| 5240 | __ CmpLeD(dst, lhs, rhs); |
| 5241 | } else { |
| 5242 | __ CmpUleD(dst, lhs, rhs); |
| 5243 | } |
| 5244 | return false; |
| 5245 | case kCondGT: |
| 5246 | if (gt_bias) { |
| 5247 | __ CmpUltD(dst, rhs, lhs); |
| 5248 | } else { |
| 5249 | __ CmpLtD(dst, rhs, lhs); |
| 5250 | } |
| 5251 | return false; |
| 5252 | case kCondGE: |
| 5253 | if (gt_bias) { |
| 5254 | __ CmpUleD(dst, rhs, lhs); |
| 5255 | } else { |
| 5256 | __ CmpLeD(dst, rhs, lhs); |
| 5257 | } |
| 5258 | return false; |
| 5259 | default: |
| 5260 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5261 | UNREACHABLE(); |
| 5262 | } |
| 5263 | } |
| 5264 | } |
| 5265 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5266 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 5267 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5268 | DataType::Type type, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5269 | LocationSummary* locations, |
| 5270 | MipsLabel* label) { |
| 5271 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5272 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5273 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5274 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5275 | if (isR6) { |
| 5276 | switch (cond) { |
| 5277 | case kCondEQ: |
| 5278 | __ CmpEqS(FTMP, lhs, rhs); |
| 5279 | __ Bc1nez(FTMP, label); |
| 5280 | break; |
| 5281 | case kCondNE: |
| 5282 | __ CmpEqS(FTMP, lhs, rhs); |
| 5283 | __ Bc1eqz(FTMP, label); |
| 5284 | break; |
| 5285 | case kCondLT: |
| 5286 | if (gt_bias) { |
| 5287 | __ CmpLtS(FTMP, lhs, rhs); |
| 5288 | } else { |
| 5289 | __ CmpUltS(FTMP, lhs, rhs); |
| 5290 | } |
| 5291 | __ Bc1nez(FTMP, label); |
| 5292 | break; |
| 5293 | case kCondLE: |
| 5294 | if (gt_bias) { |
| 5295 | __ CmpLeS(FTMP, lhs, rhs); |
| 5296 | } else { |
| 5297 | __ CmpUleS(FTMP, lhs, rhs); |
| 5298 | } |
| 5299 | __ Bc1nez(FTMP, label); |
| 5300 | break; |
| 5301 | case kCondGT: |
| 5302 | if (gt_bias) { |
| 5303 | __ CmpUltS(FTMP, rhs, lhs); |
| 5304 | } else { |
| 5305 | __ CmpLtS(FTMP, rhs, lhs); |
| 5306 | } |
| 5307 | __ Bc1nez(FTMP, label); |
| 5308 | break; |
| 5309 | case kCondGE: |
| 5310 | if (gt_bias) { |
| 5311 | __ CmpUleS(FTMP, rhs, lhs); |
| 5312 | } else { |
| 5313 | __ CmpLeS(FTMP, rhs, lhs); |
| 5314 | } |
| 5315 | __ Bc1nez(FTMP, label); |
| 5316 | break; |
| 5317 | default: |
| 5318 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5319 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5320 | } |
| 5321 | } else { |
| 5322 | switch (cond) { |
| 5323 | case kCondEQ: |
| 5324 | __ CeqS(0, lhs, rhs); |
| 5325 | __ Bc1t(0, label); |
| 5326 | break; |
| 5327 | case kCondNE: |
| 5328 | __ CeqS(0, lhs, rhs); |
| 5329 | __ Bc1f(0, label); |
| 5330 | break; |
| 5331 | case kCondLT: |
| 5332 | if (gt_bias) { |
| 5333 | __ ColtS(0, lhs, rhs); |
| 5334 | } else { |
| 5335 | __ CultS(0, lhs, rhs); |
| 5336 | } |
| 5337 | __ Bc1t(0, label); |
| 5338 | break; |
| 5339 | case kCondLE: |
| 5340 | if (gt_bias) { |
| 5341 | __ ColeS(0, lhs, rhs); |
| 5342 | } else { |
| 5343 | __ CuleS(0, lhs, rhs); |
| 5344 | } |
| 5345 | __ Bc1t(0, label); |
| 5346 | break; |
| 5347 | case kCondGT: |
| 5348 | if (gt_bias) { |
| 5349 | __ CultS(0, rhs, lhs); |
| 5350 | } else { |
| 5351 | __ ColtS(0, rhs, lhs); |
| 5352 | } |
| 5353 | __ Bc1t(0, label); |
| 5354 | break; |
| 5355 | case kCondGE: |
| 5356 | if (gt_bias) { |
| 5357 | __ CuleS(0, rhs, lhs); |
| 5358 | } else { |
| 5359 | __ ColeS(0, rhs, lhs); |
| 5360 | } |
| 5361 | __ Bc1t(0, label); |
| 5362 | break; |
| 5363 | default: |
| 5364 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5365 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5366 | } |
| 5367 | } |
| 5368 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5369 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5370 | if (isR6) { |
| 5371 | switch (cond) { |
| 5372 | case kCondEQ: |
| 5373 | __ CmpEqD(FTMP, lhs, rhs); |
| 5374 | __ Bc1nez(FTMP, label); |
| 5375 | break; |
| 5376 | case kCondNE: |
| 5377 | __ CmpEqD(FTMP, lhs, rhs); |
| 5378 | __ Bc1eqz(FTMP, label); |
| 5379 | break; |
| 5380 | case kCondLT: |
| 5381 | if (gt_bias) { |
| 5382 | __ CmpLtD(FTMP, lhs, rhs); |
| 5383 | } else { |
| 5384 | __ CmpUltD(FTMP, lhs, rhs); |
| 5385 | } |
| 5386 | __ Bc1nez(FTMP, label); |
| 5387 | break; |
| 5388 | case kCondLE: |
| 5389 | if (gt_bias) { |
| 5390 | __ CmpLeD(FTMP, lhs, rhs); |
| 5391 | } else { |
| 5392 | __ CmpUleD(FTMP, lhs, rhs); |
| 5393 | } |
| 5394 | __ Bc1nez(FTMP, label); |
| 5395 | break; |
| 5396 | case kCondGT: |
| 5397 | if (gt_bias) { |
| 5398 | __ CmpUltD(FTMP, rhs, lhs); |
| 5399 | } else { |
| 5400 | __ CmpLtD(FTMP, rhs, lhs); |
| 5401 | } |
| 5402 | __ Bc1nez(FTMP, label); |
| 5403 | break; |
| 5404 | case kCondGE: |
| 5405 | if (gt_bias) { |
| 5406 | __ CmpUleD(FTMP, rhs, lhs); |
| 5407 | } else { |
| 5408 | __ CmpLeD(FTMP, rhs, lhs); |
| 5409 | } |
| 5410 | __ Bc1nez(FTMP, label); |
| 5411 | break; |
| 5412 | default: |
| 5413 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5414 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5415 | } |
| 5416 | } else { |
| 5417 | switch (cond) { |
| 5418 | case kCondEQ: |
| 5419 | __ CeqD(0, lhs, rhs); |
| 5420 | __ Bc1t(0, label); |
| 5421 | break; |
| 5422 | case kCondNE: |
| 5423 | __ CeqD(0, lhs, rhs); |
| 5424 | __ Bc1f(0, label); |
| 5425 | break; |
| 5426 | case kCondLT: |
| 5427 | if (gt_bias) { |
| 5428 | __ ColtD(0, lhs, rhs); |
| 5429 | } else { |
| 5430 | __ CultD(0, lhs, rhs); |
| 5431 | } |
| 5432 | __ Bc1t(0, label); |
| 5433 | break; |
| 5434 | case kCondLE: |
| 5435 | if (gt_bias) { |
| 5436 | __ ColeD(0, lhs, rhs); |
| 5437 | } else { |
| 5438 | __ CuleD(0, lhs, rhs); |
| 5439 | } |
| 5440 | __ Bc1t(0, label); |
| 5441 | break; |
| 5442 | case kCondGT: |
| 5443 | if (gt_bias) { |
| 5444 | __ CultD(0, rhs, lhs); |
| 5445 | } else { |
| 5446 | __ ColtD(0, rhs, lhs); |
| 5447 | } |
| 5448 | __ Bc1t(0, label); |
| 5449 | break; |
| 5450 | case kCondGE: |
| 5451 | if (gt_bias) { |
| 5452 | __ CuleD(0, rhs, lhs); |
| 5453 | } else { |
| 5454 | __ ColeD(0, rhs, lhs); |
| 5455 | } |
| 5456 | __ Bc1t(0, label); |
| 5457 | break; |
| 5458 | default: |
| 5459 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5460 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5461 | } |
| 5462 | } |
| 5463 | } |
| 5464 | } |
| 5465 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5466 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5467 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5468 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5469 | MipsLabel* false_target) { |
| 5470 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5471 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5472 | if (true_target == nullptr && false_target == nullptr) { |
| 5473 | // Nothing to do. The code always falls through. |
| 5474 | return; |
| 5475 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5476 | // Constant condition, statically compared against "true" (integer value 1). |
| 5477 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5478 | if (true_target != nullptr) { |
| 5479 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5480 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5481 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5482 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5483 | if (false_target != nullptr) { |
| 5484 | __ B(false_target); |
| 5485 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5486 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5487 | return; |
| 5488 | } |
| 5489 | |
| 5490 | // The following code generates these patterns: |
| 5491 | // (1) true_target == nullptr && false_target != nullptr |
| 5492 | // - opposite condition true => branch to false_target |
| 5493 | // (2) true_target != nullptr && false_target == nullptr |
| 5494 | // - condition true => branch to true_target |
| 5495 | // (3) true_target != nullptr && false_target != nullptr |
| 5496 | // - condition true => branch to true_target |
| 5497 | // - branch to false_target |
| 5498 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5499 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5500 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5501 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5502 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5503 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 5504 | } else { |
| 5505 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 5506 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5507 | } else { |
| 5508 | // The condition instruction has not been materialized, use its inputs as |
| 5509 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5510 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5511 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5512 | LocationSummary* locations = cond->GetLocations(); |
| 5513 | IfCondition if_cond = condition->GetCondition(); |
| 5514 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5515 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5516 | if (true_target == nullptr) { |
| 5517 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5518 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5521 | switch (type) { |
| 5522 | default: |
| 5523 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 5524 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5525 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5526 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 5527 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5528 | case DataType::Type::kFloat32: |
| 5529 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5530 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 5531 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5532 | } |
| 5533 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5534 | |
| 5535 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 5536 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 5537 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5538 | __ B(false_target); |
| 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5543 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5544 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5545 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5546 | } |
| 5547 | } |
| 5548 | |
| 5549 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5550 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 5551 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 5552 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 5553 | nullptr : codegen_->GetLabelOf(true_successor); |
| 5554 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 5555 | nullptr : codegen_->GetLabelOf(false_successor); |
| 5556 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5557 | } |
| 5558 | |
| 5559 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5560 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5561 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 5562 | InvokeRuntimeCallingConvention calling_convention; |
| 5563 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5564 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5565 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5566 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5568 | } |
| 5569 | } |
| 5570 | |
| 5571 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 5572 | SlowPathCodeMIPS* slow_path = |
| 5573 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5574 | GenerateTestAndBranch(deoptimize, |
| 5575 | /* condition_input_index */ 0, |
| 5576 | slow_path->GetEntryLabel(), |
| 5577 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5578 | } |
| 5579 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5580 | // This function returns true if a conditional move can be generated for HSelect. |
| 5581 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 5582 | // branches and regular moves. |
| 5583 | // |
| 5584 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 5585 | // |
| 5586 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 5587 | // are two distinct tasks, this function does both because they share quite a bit |
| 5588 | // of common logic. |
| 5589 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 5590 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 5591 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5592 | HCondition* condition = cond->AsCondition(); |
| 5593 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5594 | DataType::Type cond_type = |
| 5595 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 5596 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5597 | |
| 5598 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 5599 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 5600 | bool is_true_value_zero_constant = |
| 5601 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 5602 | bool is_false_value_zero_constant = |
| 5603 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 5604 | |
| 5605 | bool can_move_conditionally = false; |
| 5606 | bool use_const_for_false_in = false; |
| 5607 | bool use_const_for_true_in = false; |
| 5608 | |
| 5609 | if (!cond->IsConstant()) { |
| 5610 | switch (cond_type) { |
| 5611 | default: |
| 5612 | switch (dst_type) { |
| 5613 | default: |
| 5614 | // Moving int on int condition. |
| 5615 | if (is_r6) { |
| 5616 | if (is_true_value_zero_constant) { |
| 5617 | // seleqz out_reg, false_reg, cond_reg |
| 5618 | can_move_conditionally = true; |
| 5619 | use_const_for_true_in = true; |
| 5620 | } else if (is_false_value_zero_constant) { |
| 5621 | // selnez out_reg, true_reg, cond_reg |
| 5622 | can_move_conditionally = true; |
| 5623 | use_const_for_false_in = true; |
| 5624 | } else if (materialized) { |
| 5625 | // Not materializing unmaterialized int conditions |
| 5626 | // to keep the instruction count low. |
| 5627 | // selnez AT, true_reg, cond_reg |
| 5628 | // seleqz TMP, false_reg, cond_reg |
| 5629 | // or out_reg, AT, TMP |
| 5630 | can_move_conditionally = true; |
| 5631 | } |
| 5632 | } else { |
| 5633 | // movn out_reg, true_reg/ZERO, cond_reg |
| 5634 | can_move_conditionally = true; |
| 5635 | use_const_for_true_in = is_true_value_zero_constant; |
| 5636 | } |
| 5637 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5638 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5639 | // Moving long on int condition. |
| 5640 | if (is_r6) { |
| 5641 | if (is_true_value_zero_constant) { |
| 5642 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 5643 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 5644 | can_move_conditionally = true; |
| 5645 | use_const_for_true_in = true; |
| 5646 | } else if (is_false_value_zero_constant) { |
| 5647 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 5648 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 5649 | can_move_conditionally = true; |
| 5650 | use_const_for_false_in = true; |
| 5651 | } |
| 5652 | // Other long conditional moves would generate 6+ instructions, |
| 5653 | // which is too many. |
| 5654 | } else { |
| 5655 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 5656 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 5657 | can_move_conditionally = true; |
| 5658 | use_const_for_true_in = is_true_value_zero_constant; |
| 5659 | } |
| 5660 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5661 | case DataType::Type::kFloat32: |
| 5662 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5663 | // Moving float/double on int condition. |
| 5664 | if (is_r6) { |
| 5665 | if (materialized) { |
| 5666 | // Not materializing unmaterialized int conditions |
| 5667 | // to keep the instruction count low. |
| 5668 | can_move_conditionally = true; |
| 5669 | if (is_true_value_zero_constant) { |
| 5670 | // sltu TMP, ZERO, cond_reg |
| 5671 | // mtc1 TMP, temp_cond_reg |
| 5672 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5673 | use_const_for_true_in = true; |
| 5674 | } else if (is_false_value_zero_constant) { |
| 5675 | // sltu TMP, ZERO, cond_reg |
| 5676 | // mtc1 TMP, temp_cond_reg |
| 5677 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5678 | use_const_for_false_in = true; |
| 5679 | } else { |
| 5680 | // sltu TMP, ZERO, cond_reg |
| 5681 | // mtc1 TMP, temp_cond_reg |
| 5682 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5683 | // mov.fmt out_reg, temp_cond_reg |
| 5684 | } |
| 5685 | } |
| 5686 | } else { |
| 5687 | // movn.fmt out_reg, true_reg, cond_reg |
| 5688 | can_move_conditionally = true; |
| 5689 | } |
| 5690 | break; |
| 5691 | } |
| 5692 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5693 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5694 | // We don't materialize long comparison now |
| 5695 | // and use conditional branches instead. |
| 5696 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5697 | case DataType::Type::kFloat32: |
| 5698 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5699 | switch (dst_type) { |
| 5700 | default: |
| 5701 | // Moving int on float/double condition. |
| 5702 | if (is_r6) { |
| 5703 | if (is_true_value_zero_constant) { |
| 5704 | // mfc1 TMP, temp_cond_reg |
| 5705 | // seleqz out_reg, false_reg, TMP |
| 5706 | can_move_conditionally = true; |
| 5707 | use_const_for_true_in = true; |
| 5708 | } else if (is_false_value_zero_constant) { |
| 5709 | // mfc1 TMP, temp_cond_reg |
| 5710 | // selnez out_reg, true_reg, TMP |
| 5711 | can_move_conditionally = true; |
| 5712 | use_const_for_false_in = true; |
| 5713 | } else { |
| 5714 | // mfc1 TMP, temp_cond_reg |
| 5715 | // selnez AT, true_reg, TMP |
| 5716 | // seleqz TMP, false_reg, TMP |
| 5717 | // or out_reg, AT, TMP |
| 5718 | can_move_conditionally = true; |
| 5719 | } |
| 5720 | } else { |
| 5721 | // movt out_reg, true_reg/ZERO, cc |
| 5722 | can_move_conditionally = true; |
| 5723 | use_const_for_true_in = is_true_value_zero_constant; |
| 5724 | } |
| 5725 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5726 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5727 | // Moving long on float/double condition. |
| 5728 | if (is_r6) { |
| 5729 | if (is_true_value_zero_constant) { |
| 5730 | // mfc1 TMP, temp_cond_reg |
| 5731 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 5732 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 5733 | can_move_conditionally = true; |
| 5734 | use_const_for_true_in = true; |
| 5735 | } else if (is_false_value_zero_constant) { |
| 5736 | // mfc1 TMP, temp_cond_reg |
| 5737 | // selnez out_reg_lo, true_reg_lo, TMP |
| 5738 | // selnez out_reg_hi, true_reg_hi, TMP |
| 5739 | can_move_conditionally = true; |
| 5740 | use_const_for_false_in = true; |
| 5741 | } |
| 5742 | // Other long conditional moves would generate 6+ instructions, |
| 5743 | // which is too many. |
| 5744 | } else { |
| 5745 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 5746 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 5747 | can_move_conditionally = true; |
| 5748 | use_const_for_true_in = is_true_value_zero_constant; |
| 5749 | } |
| 5750 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5751 | case DataType::Type::kFloat32: |
| 5752 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5753 | // Moving float/double on float/double condition. |
| 5754 | if (is_r6) { |
| 5755 | can_move_conditionally = true; |
| 5756 | if (is_true_value_zero_constant) { |
| 5757 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5758 | use_const_for_true_in = true; |
| 5759 | } else if (is_false_value_zero_constant) { |
| 5760 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5761 | use_const_for_false_in = true; |
| 5762 | } else { |
| 5763 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5764 | // mov.fmt out_reg, temp_cond_reg |
| 5765 | } |
| 5766 | } else { |
| 5767 | // movt.fmt out_reg, true_reg, cc |
| 5768 | can_move_conditionally = true; |
| 5769 | } |
| 5770 | break; |
| 5771 | } |
| 5772 | break; |
| 5773 | } |
| 5774 | } |
| 5775 | |
| 5776 | if (can_move_conditionally) { |
| 5777 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 5778 | } else { |
| 5779 | DCHECK(!use_const_for_false_in); |
| 5780 | DCHECK(!use_const_for_true_in); |
| 5781 | } |
| 5782 | |
| 5783 | if (locations_to_set != nullptr) { |
| 5784 | if (use_const_for_false_in) { |
| 5785 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 5786 | } else { |
| 5787 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5788 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5789 | ? Location::RequiresFpuRegister() |
| 5790 | : Location::RequiresRegister()); |
| 5791 | } |
| 5792 | if (use_const_for_true_in) { |
| 5793 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 5794 | } else { |
| 5795 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5796 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5797 | ? Location::RequiresFpuRegister() |
| 5798 | : Location::RequiresRegister()); |
| 5799 | } |
| 5800 | if (materialized) { |
| 5801 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 5802 | } |
| 5803 | // On R6 we don't require the output to be the same as the |
| 5804 | // first input for conditional moves unlike on R2. |
| 5805 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 5806 | if (is_out_same_as_first_in) { |
| 5807 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 5808 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5809 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5810 | ? Location::RequiresFpuRegister() |
| 5811 | : Location::RequiresRegister()); |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | return can_move_conditionally; |
| 5816 | } |
| 5817 | |
| 5818 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 5819 | LocationSummary* locations = select->GetLocations(); |
| 5820 | Location dst = locations->Out(); |
| 5821 | Location src = locations->InAt(1); |
| 5822 | Register src_reg = ZERO; |
| 5823 | Register src_reg_high = ZERO; |
| 5824 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5825 | Register cond_reg = TMP; |
| 5826 | int cond_cc = 0; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5827 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5828 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5829 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5830 | |
| 5831 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 5832 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 5833 | } else { |
| 5834 | HCondition* condition = cond->AsCondition(); |
| 5835 | LocationSummary* cond_locations = cond->GetLocations(); |
| 5836 | IfCondition if_cond = condition->GetCondition(); |
| 5837 | cond_type = condition->InputAt(0)->GetType(); |
| 5838 | switch (cond_type) { |
| 5839 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5840 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5841 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 5842 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5843 | case DataType::Type::kFloat32: |
| 5844 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5845 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 5846 | condition->IsGtBias(), |
| 5847 | cond_type, |
| 5848 | cond_locations, |
| 5849 | cond_cc); |
| 5850 | break; |
| 5851 | } |
| 5852 | } |
| 5853 | |
| 5854 | DCHECK(dst.Equals(locations->InAt(0))); |
| 5855 | if (src.IsRegister()) { |
| 5856 | src_reg = src.AsRegister<Register>(); |
| 5857 | } else if (src.IsRegisterPair()) { |
| 5858 | src_reg = src.AsRegisterPairLow<Register>(); |
| 5859 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 5860 | } else if (src.IsConstant()) { |
| 5861 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 5862 | } |
| 5863 | |
| 5864 | switch (cond_type) { |
| 5865 | default: |
| 5866 | switch (dst_type) { |
| 5867 | default: |
| 5868 | if (cond_inverted) { |
| 5869 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 5870 | } else { |
| 5871 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 5872 | } |
| 5873 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5874 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5875 | if (cond_inverted) { |
| 5876 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 5877 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 5878 | } else { |
| 5879 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 5880 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 5881 | } |
| 5882 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5883 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5884 | if (cond_inverted) { |
| 5885 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5886 | } else { |
| 5887 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5888 | } |
| 5889 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5890 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5891 | if (cond_inverted) { |
| 5892 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5893 | } else { |
| 5894 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5895 | } |
| 5896 | break; |
| 5897 | } |
| 5898 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5899 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5900 | LOG(FATAL) << "Unreachable"; |
| 5901 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5902 | case DataType::Type::kFloat32: |
| 5903 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5904 | switch (dst_type) { |
| 5905 | default: |
| 5906 | if (cond_inverted) { |
| 5907 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 5908 | } else { |
| 5909 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 5910 | } |
| 5911 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5912 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5913 | if (cond_inverted) { |
| 5914 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 5915 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 5916 | } else { |
| 5917 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 5918 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 5919 | } |
| 5920 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5921 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5922 | if (cond_inverted) { |
| 5923 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5924 | } else { |
| 5925 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5926 | } |
| 5927 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5928 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5929 | if (cond_inverted) { |
| 5930 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5931 | } else { |
| 5932 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5933 | } |
| 5934 | break; |
| 5935 | } |
| 5936 | break; |
| 5937 | } |
| 5938 | } |
| 5939 | |
| 5940 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 5941 | LocationSummary* locations = select->GetLocations(); |
| 5942 | Location dst = locations->Out(); |
| 5943 | Location false_src = locations->InAt(0); |
| 5944 | Location true_src = locations->InAt(1); |
| 5945 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5946 | Register cond_reg = TMP; |
| 5947 | FRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5948 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5949 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5950 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5951 | |
| 5952 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 5953 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 5954 | } else { |
| 5955 | HCondition* condition = cond->AsCondition(); |
| 5956 | LocationSummary* cond_locations = cond->GetLocations(); |
| 5957 | IfCondition if_cond = condition->GetCondition(); |
| 5958 | cond_type = condition->InputAt(0)->GetType(); |
| 5959 | switch (cond_type) { |
| 5960 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5961 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5962 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 5963 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5964 | case DataType::Type::kFloat32: |
| 5965 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5966 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 5967 | condition->IsGtBias(), |
| 5968 | cond_type, |
| 5969 | cond_locations, |
| 5970 | fcond_reg); |
| 5971 | break; |
| 5972 | } |
| 5973 | } |
| 5974 | |
| 5975 | if (true_src.IsConstant()) { |
| 5976 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 5977 | } |
| 5978 | if (false_src.IsConstant()) { |
| 5979 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 5980 | } |
| 5981 | |
| 5982 | switch (dst_type) { |
| 5983 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5984 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5985 | __ Mfc1(cond_reg, fcond_reg); |
| 5986 | } |
| 5987 | if (true_src.IsConstant()) { |
| 5988 | if (cond_inverted) { |
| 5989 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 5990 | } else { |
| 5991 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 5992 | } |
| 5993 | } else if (false_src.IsConstant()) { |
| 5994 | if (cond_inverted) { |
| 5995 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 5996 | } else { |
| 5997 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 5998 | } |
| 5999 | } else { |
| 6000 | DCHECK_NE(cond_reg, AT); |
| 6001 | if (cond_inverted) { |
| 6002 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6003 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6004 | } else { |
| 6005 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6006 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6007 | } |
| 6008 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 6009 | } |
| 6010 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6011 | case DataType::Type::kInt64: { |
| 6012 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6013 | __ Mfc1(cond_reg, fcond_reg); |
| 6014 | } |
| 6015 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 6016 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 6017 | if (true_src.IsConstant()) { |
| 6018 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 6019 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 6020 | if (cond_inverted) { |
| 6021 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6022 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6023 | } else { |
| 6024 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6025 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6026 | } |
| 6027 | } else { |
| 6028 | DCHECK(false_src.IsConstant()); |
| 6029 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 6030 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 6031 | if (cond_inverted) { |
| 6032 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6033 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6034 | } else { |
| 6035 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6036 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6037 | } |
| 6038 | } |
| 6039 | break; |
| 6040 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6041 | case DataType::Type::kFloat32: { |
| 6042 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6043 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6044 | __ Sltu(TMP, ZERO, cond_reg); |
| 6045 | __ Mtc1(TMP, fcond_reg); |
| 6046 | } |
| 6047 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6048 | if (true_src.IsConstant()) { |
| 6049 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6050 | if (cond_inverted) { |
| 6051 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6052 | } else { |
| 6053 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6054 | } |
| 6055 | } else if (false_src.IsConstant()) { |
| 6056 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6057 | if (cond_inverted) { |
| 6058 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6059 | } else { |
| 6060 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6061 | } |
| 6062 | } else { |
| 6063 | if (cond_inverted) { |
| 6064 | __ SelS(fcond_reg, |
| 6065 | true_src.AsFpuRegister<FRegister>(), |
| 6066 | false_src.AsFpuRegister<FRegister>()); |
| 6067 | } else { |
| 6068 | __ SelS(fcond_reg, |
| 6069 | false_src.AsFpuRegister<FRegister>(), |
| 6070 | true_src.AsFpuRegister<FRegister>()); |
| 6071 | } |
| 6072 | __ MovS(dst_reg, fcond_reg); |
| 6073 | } |
| 6074 | break; |
| 6075 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6076 | case DataType::Type::kFloat64: { |
| 6077 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6078 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6079 | __ Sltu(TMP, ZERO, cond_reg); |
| 6080 | __ Mtc1(TMP, fcond_reg); |
| 6081 | } |
| 6082 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6083 | if (true_src.IsConstant()) { |
| 6084 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6085 | if (cond_inverted) { |
| 6086 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6087 | } else { |
| 6088 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6089 | } |
| 6090 | } else if (false_src.IsConstant()) { |
| 6091 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6092 | if (cond_inverted) { |
| 6093 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6094 | } else { |
| 6095 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6096 | } |
| 6097 | } else { |
| 6098 | if (cond_inverted) { |
| 6099 | __ SelD(fcond_reg, |
| 6100 | true_src.AsFpuRegister<FRegister>(), |
| 6101 | false_src.AsFpuRegister<FRegister>()); |
| 6102 | } else { |
| 6103 | __ SelD(fcond_reg, |
| 6104 | false_src.AsFpuRegister<FRegister>(), |
| 6105 | true_src.AsFpuRegister<FRegister>()); |
| 6106 | } |
| 6107 | __ MovD(dst_reg, fcond_reg); |
| 6108 | } |
| 6109 | break; |
| 6110 | } |
| 6111 | } |
| 6112 | } |
| 6113 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6114 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6115 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6116 | LocationSummary(flag, LocationSummary::kNoCall); |
| 6117 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6118 | } |
| 6119 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6120 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 6121 | __ LoadFromOffset(kLoadWord, |
| 6122 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 6123 | SP, |
| 6124 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6125 | } |
| 6126 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6127 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6128 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6129 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6133 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6134 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 6135 | if (is_r6) { |
| 6136 | GenConditionalMoveR6(select); |
| 6137 | } else { |
| 6138 | GenConditionalMoveR2(select); |
| 6139 | } |
| 6140 | } else { |
| 6141 | LocationSummary* locations = select->GetLocations(); |
| 6142 | MipsLabel false_target; |
| 6143 | GenerateTestAndBranch(select, |
| 6144 | /* condition_input_index */ 2, |
| 6145 | /* true_target */ nullptr, |
| 6146 | &false_target); |
| 6147 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 6148 | __ Bind(&false_target); |
| 6149 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6150 | } |
| 6151 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6152 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6153 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6154 | } |
| 6155 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 6156 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 6157 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | void CodeGeneratorMIPS::GenerateNop() { |
| 6161 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6164 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6165 | DataType::Type field_type = field_info.GetFieldType(); |
| 6166 | 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] | 6167 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6168 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6169 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6170 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6171 | instruction, |
| 6172 | generate_volatile |
| 6173 | ? LocationSummary::kCallOnMainOnly |
| 6174 | : (object_field_get_with_read_barrier |
| 6175 | ? LocationSummary::kCallOnSlowPath |
| 6176 | : LocationSummary::kNoCall)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6177 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6178 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6179 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6180 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6181 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6182 | if (generate_volatile) { |
| 6183 | InvokeRuntimeCallingConvention calling_convention; |
| 6184 | // need A0 to hold base + offset |
| 6185 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6186 | if (field_type == DataType::Type::kInt64) { |
| 6187 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6188 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6189 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6190 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6191 | // 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] | 6192 | Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6193 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 6194 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 6195 | } |
| 6196 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6197 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6198 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6199 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6200 | // The output overlaps in the case of an object field get with |
| 6201 | // read barriers enabled: we do not want the move to overwrite the |
| 6202 | // object's location, as we need it to emit the read barrier. |
| 6203 | locations->SetOut(Location::RequiresRegister(), |
| 6204 | object_field_get_with_read_barrier |
| 6205 | ? Location::kOutputOverlap |
| 6206 | : Location::kNoOutputOverlap); |
| 6207 | } |
| 6208 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6209 | // We need a temporary register for the read barrier marking slow |
| 6210 | // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6211 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6212 | locations->AddTemp(Location::RequiresRegister()); |
| 6213 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6214 | } |
| 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 6219 | const FieldInfo& field_info, |
| 6220 | uint32_t dex_pc) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6221 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6222 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6223 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6224 | Location obj_loc = locations->InAt(0); |
| 6225 | Register obj = obj_loc.AsRegister<Register>(); |
| 6226 | Location dst_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6227 | LoadOperandType load_type = kLoadUnsignedByte; |
| 6228 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6229 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6230 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6231 | |
| 6232 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6233 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6234 | case DataType::Type::kUint8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6235 | load_type = kLoadUnsignedByte; |
| 6236 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6237 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6238 | load_type = kLoadSignedByte; |
| 6239 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6240 | case DataType::Type::kUint16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6241 | load_type = kLoadUnsignedHalfword; |
| 6242 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6243 | case DataType::Type::kInt16: |
| 6244 | load_type = kLoadSignedHalfword; |
| 6245 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6246 | case DataType::Type::kInt32: |
| 6247 | case DataType::Type::kFloat32: |
| 6248 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6249 | load_type = kLoadWord; |
| 6250 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6251 | case DataType::Type::kInt64: |
| 6252 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6253 | load_type = kLoadDoubleword; |
| 6254 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6255 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6256 | LOG(FATAL) << "Unreachable type " << type; |
| 6257 | UNREACHABLE(); |
| 6258 | } |
| 6259 | |
| 6260 | if (is_volatile && load_type == kLoadDoubleword) { |
| 6261 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6262 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6263 | // Do implicit Null check |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6264 | __ LoadFromOffset(kLoadWord, |
| 6265 | ZERO, |
| 6266 | locations->GetTemp(0).AsRegister<Register>(), |
| 6267 | 0, |
| 6268 | null_checker); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6269 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6270 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6271 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6272 | // FP results are returned in core registers. Need to move them. |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6273 | if (dst_loc.IsFpuRegister()) { |
| 6274 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6275 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6276 | dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6277 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6278 | DCHECK(dst_loc.IsDoubleStackSlot()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6279 | __ StoreToOffset(kStoreWord, |
| 6280 | locations->GetTemp(1).AsRegister<Register>(), |
| 6281 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6282 | dst_loc.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6283 | __ StoreToOffset(kStoreWord, |
| 6284 | locations->GetTemp(2).AsRegister<Register>(), |
| 6285 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6286 | dst_loc.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6287 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6288 | } |
| 6289 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6290 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6291 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 6292 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6293 | Location temp_loc = |
| 6294 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6295 | // Note that a potential implicit null check is handled in this |
| 6296 | // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call. |
| 6297 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6298 | dst_loc, |
| 6299 | obj, |
| 6300 | offset, |
| 6301 | temp_loc, |
| 6302 | /* needs_null_check */ true); |
| 6303 | if (is_volatile) { |
| 6304 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6305 | } |
| 6306 | } else { |
| 6307 | __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker); |
| 6308 | if (is_volatile) { |
| 6309 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6310 | } |
| 6311 | // If read barriers are enabled, emit read barriers other than |
| 6312 | // Baker's using a slow path (and also unpoison the loaded |
| 6313 | // reference, if heap poisoning is enabled). |
| 6314 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 6315 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6316 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6317 | Register dst; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6318 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6319 | DCHECK(dst_loc.IsRegisterPair()); |
| 6320 | dst = dst_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6321 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6322 | DCHECK(dst_loc.IsRegister()); |
| 6323 | dst = dst_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6324 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6325 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6326 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6327 | DCHECK(dst_loc.IsFpuRegister()); |
| 6328 | FRegister dst = dst_loc.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6329 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6330 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6331 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6332 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6333 | } |
| 6334 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6335 | } |
| 6336 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6337 | // Memory barriers, in the case of references, are handled in the |
| 6338 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6339 | if (is_volatile && (type != DataType::Type::kReference)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6340 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6345 | DataType::Type field_type = field_info.GetFieldType(); |
| 6346 | 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] | 6347 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6348 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6349 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6350 | |
| 6351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6352 | if (generate_volatile) { |
| 6353 | InvokeRuntimeCallingConvention calling_convention; |
| 6354 | // need A0 to hold base + offset |
| 6355 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6356 | if (field_type == DataType::Type::kInt64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6357 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6358 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6359 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6360 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6361 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6362 | // Pass FP parameters in core registers. |
| 6363 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 6364 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 6365 | } |
| 6366 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6367 | if (DataType::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6368 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6369 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6370 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6371 | } |
| 6372 | } |
| 6373 | } |
| 6374 | |
| 6375 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 6376 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6377 | uint32_t dex_pc, |
| 6378 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6379 | DataType::Type type = field_info.GetFieldType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6380 | LocationSummary* locations = instruction->GetLocations(); |
| 6381 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6382 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6383 | StoreOperandType store_type = kStoreByte; |
| 6384 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6385 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6386 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6387 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6388 | |
| 6389 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6390 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6391 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6392 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6393 | store_type = kStoreByte; |
| 6394 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6395 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6396 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6397 | store_type = kStoreHalfword; |
| 6398 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6399 | case DataType::Type::kInt32: |
| 6400 | case DataType::Type::kFloat32: |
| 6401 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6402 | store_type = kStoreWord; |
| 6403 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6404 | case DataType::Type::kInt64: |
| 6405 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6406 | store_type = kStoreDoubleword; |
| 6407 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6408 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6409 | LOG(FATAL) << "Unreachable type " << type; |
| 6410 | UNREACHABLE(); |
| 6411 | } |
| 6412 | |
| 6413 | if (is_volatile) { |
| 6414 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 6415 | } |
| 6416 | |
| 6417 | if (is_volatile && store_type == kStoreDoubleword) { |
| 6418 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6419 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6420 | // Do implicit Null check. |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6421 | __ LoadFromOffset(kLoadWord, |
| 6422 | ZERO, |
| 6423 | locations->GetTemp(0).AsRegister<Register>(), |
| 6424 | 0, |
| 6425 | null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6426 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6427 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6428 | if (value_location.IsFpuRegister()) { |
| 6429 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 6430 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6431 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6432 | value_location.AsFpuRegister<FRegister>()); |
| 6433 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6434 | __ LoadFromOffset(kLoadWord, |
| 6435 | locations->GetTemp(1).AsRegister<Register>(), |
| 6436 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6437 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6438 | __ LoadFromOffset(kLoadWord, |
| 6439 | locations->GetTemp(2).AsRegister<Register>(), |
| 6440 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6441 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6442 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6443 | DCHECK(value_location.IsConstant()); |
| 6444 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 6445 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6446 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 6447 | locations->GetTemp(1).AsRegister<Register>(), |
| 6448 | value); |
| 6449 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6450 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6451 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6452 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 6453 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6454 | if (value_location.IsConstant()) { |
| 6455 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 6456 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6457 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6458 | Register src; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6459 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6460 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6461 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6462 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6463 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6464 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 6465 | // Note that in the case where `value` is a null reference, |
| 6466 | // we do not enter this block, as a null reference does not |
| 6467 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6468 | DCHECK_EQ(type, DataType::Type::kReference); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6469 | __ PoisonHeapReference(TMP, src); |
| 6470 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 6471 | } else { |
| 6472 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 6473 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6474 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6475 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6476 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6477 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6478 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6479 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6480 | } |
| 6481 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6482 | } |
| 6483 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6484 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6485 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6486 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | if (is_volatile) { |
| 6490 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 6491 | } |
| 6492 | } |
| 6493 | |
| 6494 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6495 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6496 | } |
| 6497 | |
| 6498 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6499 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6500 | } |
| 6501 | |
| 6502 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6503 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6504 | } |
| 6505 | |
| 6506 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6507 | HandleFieldSet(instruction, |
| 6508 | instruction->GetFieldInfo(), |
| 6509 | instruction->GetDexPc(), |
| 6510 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6511 | } |
| 6512 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6513 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister( |
| 6514 | HInstruction* instruction, |
| 6515 | Location out, |
| 6516 | uint32_t offset, |
| 6517 | Location maybe_temp, |
| 6518 | ReadBarrierOption read_barrier_option) { |
| 6519 | Register out_reg = out.AsRegister<Register>(); |
| 6520 | if (read_barrier_option == kWithReadBarrier) { |
| 6521 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6522 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 6523 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6524 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6525 | if (kUseBakerReadBarrier) { |
| 6526 | // Load with fast path based Baker's read barrier. |
| 6527 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6528 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6529 | out, |
| 6530 | out_reg, |
| 6531 | offset, |
| 6532 | maybe_temp, |
| 6533 | /* needs_null_check */ false); |
| 6534 | } else { |
| 6535 | // Load with slow path based read barrier. |
| 6536 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6537 | // in the following move operation, as we will need it for the |
| 6538 | // read barrier below. |
| 6539 | __ Move(maybe_temp.AsRegister<Register>(), out_reg); |
| 6540 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6541 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6542 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6543 | } |
| 6544 | } else { |
| 6545 | // Plain load with no read barrier. |
| 6546 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6547 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6548 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6549 | } |
| 6550 | } |
| 6551 | |
| 6552 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters( |
| 6553 | HInstruction* instruction, |
| 6554 | Location out, |
| 6555 | Location obj, |
| 6556 | uint32_t offset, |
| 6557 | Location maybe_temp, |
| 6558 | ReadBarrierOption read_barrier_option) { |
| 6559 | Register out_reg = out.AsRegister<Register>(); |
| 6560 | Register obj_reg = obj.AsRegister<Register>(); |
| 6561 | if (read_barrier_option == kWithReadBarrier) { |
| 6562 | CHECK(kEmitCompilerReadBarrier); |
| 6563 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6564 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6565 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6566 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6567 | // Load with fast path based Baker's read barrier. |
| 6568 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6569 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6570 | out, |
| 6571 | obj_reg, |
| 6572 | offset, |
| 6573 | maybe_temp, |
| 6574 | /* needs_null_check */ false); |
| 6575 | } else { |
| 6576 | // Load with slow path based read barrier. |
| 6577 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6578 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6579 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6580 | } |
| 6581 | } else { |
| 6582 | // Plain load with no read barrier. |
| 6583 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6584 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6585 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6586 | } |
| 6587 | } |
| 6588 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6589 | static inline int GetBakerMarkThunkNumber(Register reg) { |
| 6590 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal"); |
| 6591 | if (reg >= V0 && reg <= T7) { // 14 consequtive regs. |
| 6592 | return reg - V0; |
| 6593 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 6594 | return 14 + (reg - S2); |
| 6595 | } else if (reg == FP) { // One more. |
| 6596 | return 20; |
| 6597 | } |
| 6598 | LOG(FATAL) << "Unexpected register " << reg; |
| 6599 | UNREACHABLE(); |
| 6600 | } |
| 6601 | |
| 6602 | static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) { |
| 6603 | int num = GetBakerMarkThunkNumber(reg) + |
| 6604 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 6605 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 6606 | } |
| 6607 | |
| 6608 | static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) { |
| 6609 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 6610 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 6611 | } |
| 6612 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6613 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6614 | Location root, |
| 6615 | Register obj, |
| 6616 | uint32_t offset, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6617 | ReadBarrierOption read_barrier_option, |
| 6618 | MipsLabel* label_low) { |
| 6619 | bool reordering; |
| 6620 | if (label_low != nullptr) { |
| 6621 | DCHECK_EQ(offset, 0x5678u); |
| 6622 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6623 | Register root_reg = root.AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6624 | if (read_barrier_option == kWithReadBarrier) { |
| 6625 | DCHECK(kEmitCompilerReadBarrier); |
| 6626 | if (kUseBakerReadBarrier) { |
| 6627 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6628 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6629 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 6630 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6631 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6632 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6633 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6634 | // vice versa. |
| 6635 | // |
| 6636 | // We use thunks for the slow path. That thunk checks the reference |
| 6637 | // and jumps to the entrypoint if needed. |
| 6638 | // |
| 6639 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6640 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6641 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6642 | // if (temp != nullptr) { |
| 6643 | // temp = &gc_root_thunk<root_reg> |
| 6644 | // root = temp(root) |
| 6645 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6646 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6647 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6648 | const int32_t entry_point_offset = |
| 6649 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6650 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 6651 | int16_t offset_low = Low16Bits(offset); |
| 6652 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 6653 | // extension in lw. |
| 6654 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 6655 | Register base = short_offset ? obj : TMP; |
| 6656 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6657 | // threads are suspended or running a checkpoint. |
| 6658 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6659 | reordering = __ SetReorder(false); |
| 6660 | if (!short_offset) { |
| 6661 | DCHECK(!label_low); |
| 6662 | __ AddUpper(base, obj, offset_high); |
| 6663 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6664 | MipsLabel skip_call; |
| 6665 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6666 | if (label_low != nullptr) { |
| 6667 | DCHECK(short_offset); |
| 6668 | __ Bind(label_low); |
| 6669 | } |
| 6670 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6671 | __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction |
| 6672 | // in delay slot. |
| 6673 | if (isR6) { |
| 6674 | __ Jialc(T9, thunk_disp); |
| 6675 | } else { |
| 6676 | __ Addiu(T9, T9, thunk_disp); |
| 6677 | __ Jalr(T9); |
| 6678 | __ Nop(); |
| 6679 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6680 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6681 | __ SetReorder(reordering); |
| 6682 | } else { |
| 6683 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6684 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6685 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 6686 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 6687 | // is false, and vice versa. |
| 6688 | // |
| 6689 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6690 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6691 | // if (temp != null) { |
| 6692 | // root = temp(root) |
| 6693 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6694 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6695 | if (label_low != nullptr) { |
| 6696 | reordering = __ SetReorder(false); |
| 6697 | __ Bind(label_low); |
| 6698 | } |
| 6699 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6700 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6701 | if (label_low != nullptr) { |
| 6702 | __ SetReorder(reordering); |
| 6703 | } |
| 6704 | static_assert( |
| 6705 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6706 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6707 | "have different sizes."); |
| 6708 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6709 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6710 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6711 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6712 | // Slow path marking the GC root `root`. |
| 6713 | Location temp = Location::RegisterLocation(T9); |
| 6714 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6715 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6716 | instruction, |
| 6717 | root, |
| 6718 | /*entrypoint*/ temp); |
| 6719 | codegen_->AddSlowPath(slow_path); |
| 6720 | |
| 6721 | const int32_t entry_point_offset = |
| 6722 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1); |
| 6723 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6724 | // threads are suspended or running a checkpoint. |
| 6725 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 6726 | __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 6727 | __ Bind(slow_path->GetExitLabel()); |
| 6728 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6729 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6730 | if (label_low != nullptr) { |
| 6731 | reordering = __ SetReorder(false); |
| 6732 | __ Bind(label_low); |
| 6733 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6734 | // GC root loaded through a slow path for read barriers other |
| 6735 | // than Baker's. |
| 6736 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6737 | __ Addiu32(root_reg, obj, offset); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6738 | if (label_low != nullptr) { |
| 6739 | __ SetReorder(reordering); |
| 6740 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6741 | // /* mirror::Object* */ root = root->Read() |
| 6742 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6743 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6744 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6745 | if (label_low != nullptr) { |
| 6746 | reordering = __ SetReorder(false); |
| 6747 | __ Bind(label_low); |
| 6748 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6749 | // Plain GC root load with no read barrier. |
| 6750 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6751 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6752 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6753 | // do not have to unpoison `root_reg` here. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6754 | if (label_low != nullptr) { |
| 6755 | __ SetReorder(reordering); |
| 6756 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6757 | } |
| 6758 | } |
| 6759 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6760 | void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6761 | Location ref, |
| 6762 | Register obj, |
| 6763 | uint32_t offset, |
| 6764 | Location temp, |
| 6765 | bool needs_null_check) { |
| 6766 | DCHECK(kEmitCompilerReadBarrier); |
| 6767 | DCHECK(kUseBakerReadBarrier); |
| 6768 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6769 | if (kBakerReadBarrierThunksEnableForFields) { |
| 6770 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6771 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6772 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6773 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6774 | // vice versa. |
| 6775 | // |
| 6776 | // We use thunks for the slow path. That thunk checks the reference |
| 6777 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6778 | // it issues a load-load memory barrier and returns to the original |
| 6779 | // reference load. |
| 6780 | // |
| 6781 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6782 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6783 | // if (temp != nullptr) { |
| 6784 | // temp = &field_array_thunk<holder_reg> |
| 6785 | // temp() |
| 6786 | // } |
| 6787 | // not_gray_return_address: |
| 6788 | // // If the offset is too large to fit into the lw instruction, we |
| 6789 | // // use an adjusted base register (TMP) here. This register |
| 6790 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 6791 | // // and the thunk benefits from it. |
| 6792 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 6793 | // gray_return_address: |
| 6794 | |
| 6795 | DCHECK(temp.IsInvalid()); |
| 6796 | bool isR6 = GetInstructionSetFeatures().IsR6(); |
| 6797 | int16_t offset_low = Low16Bits(offset); |
| 6798 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw. |
| 6799 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 6800 | bool reordering = __ SetReorder(false); |
| 6801 | const int32_t entry_point_offset = |
| 6802 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6803 | // There may have or may have not been a null check if the field offset is smaller than |
| 6804 | // the page size. |
| 6805 | // There must've been a null check in case it's actually a load from an array. |
| 6806 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 6807 | // do it than not. |
| 6808 | if (instruction->IsArrayGet()) { |
| 6809 | DCHECK(!needs_null_check); |
| 6810 | } |
| 6811 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 6812 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6813 | // threads are suspended or running a checkpoint. |
| 6814 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6815 | Register ref_reg = ref.AsRegister<Register>(); |
| 6816 | Register base = short_offset ? obj : TMP; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6817 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6818 | if (short_offset) { |
| 6819 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6820 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6821 | __ Nop(); // In forbidden slot. |
| 6822 | __ Jialc(T9, thunk_disp); |
| 6823 | } else { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6824 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6825 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 6826 | __ Jalr(T9); |
| 6827 | __ Nop(); // In delay slot. |
| 6828 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6829 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6830 | } else { |
| 6831 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6832 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6833 | __ Aui(base, obj, offset_high); // In delay slot. |
| 6834 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6835 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6836 | } else { |
| 6837 | __ Lui(base, offset_high); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6838 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6839 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 6840 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6841 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6842 | __ Addu(base, base, obj); // In delay slot. |
| 6843 | } |
| 6844 | } |
| 6845 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6846 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction. |
| 6847 | if (needs_null_check) { |
| 6848 | MaybeRecordImplicitNullCheck(instruction); |
| 6849 | } |
| 6850 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6851 | __ SetReorder(reordering); |
| 6852 | return; |
| 6853 | } |
| 6854 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6855 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6856 | Location no_index = Location::NoLocation(); |
| 6857 | ScaleFactor no_scale_factor = TIMES_1; |
| 6858 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6859 | ref, |
| 6860 | obj, |
| 6861 | offset, |
| 6862 | no_index, |
| 6863 | no_scale_factor, |
| 6864 | temp, |
| 6865 | needs_null_check); |
| 6866 | } |
| 6867 | |
| 6868 | void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6869 | Location ref, |
| 6870 | Register obj, |
| 6871 | uint32_t data_offset, |
| 6872 | Location index, |
| 6873 | Location temp, |
| 6874 | bool needs_null_check) { |
| 6875 | DCHECK(kEmitCompilerReadBarrier); |
| 6876 | DCHECK(kUseBakerReadBarrier); |
| 6877 | |
| 6878 | static_assert( |
| 6879 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6880 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6881 | ScaleFactor scale_factor = TIMES_4; |
| 6882 | |
| 6883 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 6884 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6885 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6886 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6887 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6888 | // vice versa. |
| 6889 | // |
| 6890 | // We use thunks for the slow path. That thunk checks the reference |
| 6891 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6892 | // it issues a load-load memory barrier and returns to the original |
| 6893 | // reference load. |
| 6894 | // |
| 6895 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6896 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6897 | // if (temp != nullptr) { |
| 6898 | // temp = &field_array_thunk<holder_reg> |
| 6899 | // temp() |
| 6900 | // } |
| 6901 | // not_gray_return_address: |
| 6902 | // // The element address is pre-calculated in the TMP register before the |
| 6903 | // // thunk invocation and the thunk benefits from it. |
| 6904 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 6905 | // gray_return_address: |
| 6906 | |
| 6907 | DCHECK(temp.IsInvalid()); |
| 6908 | DCHECK(index.IsValid()); |
| 6909 | bool reordering = __ SetReorder(false); |
| 6910 | const int32_t entry_point_offset = |
| 6911 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6912 | // We will not do the explicit null check in the thunk as some form of a null check |
| 6913 | // must've been done earlier. |
| 6914 | DCHECK(!needs_null_check); |
| 6915 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 6916 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6917 | // threads are suspended or running a checkpoint. |
| 6918 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6919 | Register ref_reg = ref.AsRegister<Register>(); |
| 6920 | Register index_reg = index.IsRegisterPair() |
| 6921 | ? index.AsRegisterPairLow<Register>() |
| 6922 | : index.AsRegister<Register>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6923 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6924 | if (GetInstructionSetFeatures().IsR6()) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6925 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6926 | __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 6927 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6928 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6929 | } else { |
| 6930 | __ Sll(TMP, index_reg, scale_factor); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6931 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6932 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 6933 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6934 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6935 | __ Addu(TMP, TMP, obj); // In delay slot. |
| 6936 | } |
| 6937 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 6938 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 6939 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction. |
| 6940 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6941 | __ SetReorder(reordering); |
| 6942 | return; |
| 6943 | } |
| 6944 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6945 | // /* HeapReference<Object> */ ref = |
| 6946 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6947 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6948 | ref, |
| 6949 | obj, |
| 6950 | data_offset, |
| 6951 | index, |
| 6952 | scale_factor, |
| 6953 | temp, |
| 6954 | needs_null_check); |
| 6955 | } |
| 6956 | |
| 6957 | void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6958 | Location ref, |
| 6959 | Register obj, |
| 6960 | uint32_t offset, |
| 6961 | Location index, |
| 6962 | ScaleFactor scale_factor, |
| 6963 | Location temp, |
| 6964 | bool needs_null_check, |
| 6965 | bool always_update_field) { |
| 6966 | DCHECK(kEmitCompilerReadBarrier); |
| 6967 | DCHECK(kUseBakerReadBarrier); |
| 6968 | |
| 6969 | // In slow path based read barriers, the read barrier call is |
| 6970 | // inserted after the original load. However, in fast path based |
| 6971 | // Baker's read barriers, we need to perform the load of |
| 6972 | // mirror::Object::monitor_ *before* the original reference load. |
| 6973 | // This load-load ordering is required by the read barrier. |
| 6974 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6975 | // |
| 6976 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6977 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6978 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6979 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6980 | // if (is_gray) { |
| 6981 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6982 | // } |
| 6983 | // |
| 6984 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6985 | // slightly more complex as it performs additional checks that we do |
| 6986 | // not do here for performance reasons. |
| 6987 | |
| 6988 | Register ref_reg = ref.AsRegister<Register>(); |
| 6989 | Register temp_reg = temp.AsRegister<Register>(); |
| 6990 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6991 | |
| 6992 | // /* int32_t */ monitor = obj->monitor_ |
| 6993 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6994 | if (needs_null_check) { |
| 6995 | MaybeRecordImplicitNullCheck(instruction); |
| 6996 | } |
| 6997 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6998 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6999 | "art::LockWord and int32_t have different sizes."); |
| 7000 | |
| 7001 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 7002 | |
| 7003 | // The actual reference load. |
| 7004 | if (index.IsValid()) { |
| 7005 | // Load types involving an "index": ArrayGet, |
| 7006 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7007 | // intrinsics. |
| 7008 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7009 | if (index.IsConstant()) { |
| 7010 | size_t computed_offset = |
| 7011 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 7012 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7013 | } else { |
| 7014 | // Handle the special case of the |
| 7015 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7016 | // intrinsics, which use a register pair as index ("long |
| 7017 | // offset"), of which only the low part contains data. |
| 7018 | Register index_reg = index.IsRegisterPair() |
| 7019 | ? index.AsRegisterPairLow<Register>() |
| 7020 | : index.AsRegister<Register>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7021 | __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7022 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset); |
| 7023 | } |
| 7024 | } else { |
| 7025 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7026 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7027 | } |
| 7028 | |
| 7029 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7030 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7031 | |
| 7032 | // Slow path marking the object `ref` when it is gray. |
| 7033 | SlowPathCodeMIPS* slow_path; |
| 7034 | if (always_update_field) { |
| 7035 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address |
| 7036 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7037 | // `field_offset` is a register pair (of which only the lower half |
| 7038 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7039 | // to be null in this code path. |
| 7040 | DCHECK_EQ(offset, 0u); |
| 7041 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7042 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7043 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction, |
| 7044 | ref, |
| 7045 | obj, |
| 7046 | /* field_offset */ index, |
| 7047 | temp_reg); |
| 7048 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7049 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7050 | } |
| 7051 | AddSlowPath(slow_path); |
| 7052 | |
| 7053 | // if (rb_state == ReadBarrier::GrayState()) |
| 7054 | // ref = ReadBarrier::Mark(ref); |
| 7055 | // Given the numeric representation, it's enough to check the low bit of the |
| 7056 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 7057 | // performing a branch on less than zero. |
| 7058 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7059 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7060 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 7061 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 7062 | __ Bltz(temp_reg, slow_path->GetEntryLabel()); |
| 7063 | __ Bind(slow_path->GetExitLabel()); |
| 7064 | } |
| 7065 | |
| 7066 | void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7067 | Location out, |
| 7068 | Location ref, |
| 7069 | Location obj, |
| 7070 | uint32_t offset, |
| 7071 | Location index) { |
| 7072 | DCHECK(kEmitCompilerReadBarrier); |
| 7073 | |
| 7074 | // Insert a slow path based read barrier *after* the reference load. |
| 7075 | // |
| 7076 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7077 | // reference will be carried out by the runtime within the slow |
| 7078 | // path. |
| 7079 | // |
| 7080 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7081 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7082 | // not used by the artReadBarrierSlow entry point. |
| 7083 | // |
| 7084 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7085 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7086 | ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index); |
| 7087 | AddSlowPath(slow_path); |
| 7088 | |
| 7089 | __ B(slow_path->GetEntryLabel()); |
| 7090 | __ Bind(slow_path->GetExitLabel()); |
| 7091 | } |
| 7092 | |
| 7093 | void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7094 | Location out, |
| 7095 | Location ref, |
| 7096 | Location obj, |
| 7097 | uint32_t offset, |
| 7098 | Location index) { |
| 7099 | if (kEmitCompilerReadBarrier) { |
| 7100 | // Baker's read barriers shall be handled by the fast path |
| 7101 | // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier). |
| 7102 | DCHECK(!kUseBakerReadBarrier); |
| 7103 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7104 | // by the runtime within the slow path. |
| 7105 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 7106 | } else if (kPoisonHeapReferences) { |
| 7107 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7108 | } |
| 7109 | } |
| 7110 | |
| 7111 | void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7112 | Location out, |
| 7113 | Location root) { |
| 7114 | DCHECK(kEmitCompilerReadBarrier); |
| 7115 | |
| 7116 | // Insert a slow path based read barrier *after* the GC root load. |
| 7117 | // |
| 7118 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7119 | // not need to do anything special for this here. |
| 7120 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7121 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7122 | AddSlowPath(slow_path); |
| 7123 | |
| 7124 | __ B(slow_path->GetEntryLabel()); |
| 7125 | __ Bind(slow_path->GetExitLabel()); |
| 7126 | } |
| 7127 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7128 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7129 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7130 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7131 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7132 | switch (type_check_kind) { |
| 7133 | case TypeCheckKind::kExactCheck: |
| 7134 | case TypeCheckKind::kAbstractClassCheck: |
| 7135 | case TypeCheckKind::kClassHierarchyCheck: |
| 7136 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7137 | call_kind = |
| 7138 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7139 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7140 | break; |
| 7141 | case TypeCheckKind::kArrayCheck: |
| 7142 | case TypeCheckKind::kUnresolvedCheck: |
| 7143 | case TypeCheckKind::kInterfaceCheck: |
| 7144 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7145 | break; |
| 7146 | } |
| 7147 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7148 | LocationSummary* locations = |
| 7149 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7150 | if (baker_read_barrier_slow_path) { |
| 7151 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7152 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7153 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7154 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7155 | // The output does overlap inputs. |
| 7156 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 7157 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7158 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7159 | } |
| 7160 | |
| 7161 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7162 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7163 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7164 | Location obj_loc = locations->InAt(0); |
| 7165 | Register obj = obj_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7166 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7167 | Location out_loc = locations->Out(); |
| 7168 | Register out = out_loc.AsRegister<Register>(); |
| 7169 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7170 | DCHECK_LE(num_temps, 1u); |
| 7171 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7172 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7173 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7174 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7175 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7176 | MipsLabel done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7177 | SlowPathCodeMIPS* slow_path = nullptr; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7178 | |
| 7179 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7180 | // Avoid this check if we know `obj` is not null. |
| 7181 | if (instruction->MustDoNullCheck()) { |
| 7182 | __ Move(out, ZERO); |
| 7183 | __ Beqz(obj, &done); |
| 7184 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7185 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7186 | switch (type_check_kind) { |
| 7187 | case TypeCheckKind::kExactCheck: { |
| 7188 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7189 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7190 | out_loc, |
| 7191 | obj_loc, |
| 7192 | class_offset, |
| 7193 | maybe_temp_loc, |
| 7194 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7195 | // Classes must be equal for the instanceof to succeed. |
| 7196 | __ Xor(out, out, cls); |
| 7197 | __ Sltiu(out, out, 1); |
| 7198 | break; |
| 7199 | } |
| 7200 | |
| 7201 | case TypeCheckKind::kAbstractClassCheck: { |
| 7202 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7203 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7204 | out_loc, |
| 7205 | obj_loc, |
| 7206 | class_offset, |
| 7207 | maybe_temp_loc, |
| 7208 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7209 | // If the class is abstract, we eagerly fetch the super class of the |
| 7210 | // object to avoid doing a comparison we know will fail. |
| 7211 | MipsLabel loop; |
| 7212 | __ Bind(&loop); |
| 7213 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7214 | GenerateReferenceLoadOneRegister(instruction, |
| 7215 | out_loc, |
| 7216 | super_offset, |
| 7217 | maybe_temp_loc, |
| 7218 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7219 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7220 | __ Beqz(out, &done); |
| 7221 | __ Bne(out, cls, &loop); |
| 7222 | __ LoadConst32(out, 1); |
| 7223 | break; |
| 7224 | } |
| 7225 | |
| 7226 | case TypeCheckKind::kClassHierarchyCheck: { |
| 7227 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7228 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7229 | out_loc, |
| 7230 | obj_loc, |
| 7231 | class_offset, |
| 7232 | maybe_temp_loc, |
| 7233 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7234 | // Walk over the class hierarchy to find a match. |
| 7235 | MipsLabel loop, success; |
| 7236 | __ Bind(&loop); |
| 7237 | __ Beq(out, cls, &success); |
| 7238 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7239 | GenerateReferenceLoadOneRegister(instruction, |
| 7240 | out_loc, |
| 7241 | super_offset, |
| 7242 | maybe_temp_loc, |
| 7243 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7244 | __ Bnez(out, &loop); |
| 7245 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7246 | __ B(&done); |
| 7247 | __ Bind(&success); |
| 7248 | __ LoadConst32(out, 1); |
| 7249 | break; |
| 7250 | } |
| 7251 | |
| 7252 | case TypeCheckKind::kArrayObjectCheck: { |
| 7253 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7254 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7255 | out_loc, |
| 7256 | obj_loc, |
| 7257 | class_offset, |
| 7258 | maybe_temp_loc, |
| 7259 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7260 | // Do an exact check. |
| 7261 | MipsLabel success; |
| 7262 | __ Beq(out, cls, &success); |
| 7263 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7264 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7265 | GenerateReferenceLoadOneRegister(instruction, |
| 7266 | out_loc, |
| 7267 | component_offset, |
| 7268 | maybe_temp_loc, |
| 7269 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7270 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7271 | __ Beqz(out, &done); |
| 7272 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7273 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 7274 | __ Sltiu(out, out, 1); |
| 7275 | __ B(&done); |
| 7276 | __ Bind(&success); |
| 7277 | __ LoadConst32(out, 1); |
| 7278 | break; |
| 7279 | } |
| 7280 | |
| 7281 | case TypeCheckKind::kArrayCheck: { |
| 7282 | // No read barrier since the slow path will retry upon failure. |
| 7283 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7284 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7285 | out_loc, |
| 7286 | obj_loc, |
| 7287 | class_offset, |
| 7288 | maybe_temp_loc, |
| 7289 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7290 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7291 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7292 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7293 | codegen_->AddSlowPath(slow_path); |
| 7294 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 7295 | __ LoadConst32(out, 1); |
| 7296 | break; |
| 7297 | } |
| 7298 | |
| 7299 | case TypeCheckKind::kUnresolvedCheck: |
| 7300 | case TypeCheckKind::kInterfaceCheck: { |
| 7301 | // Note that we indeed only call on slow path, but we always go |
| 7302 | // into the slow path for the unresolved and interface check |
| 7303 | // cases. |
| 7304 | // |
| 7305 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7306 | // entry point without resorting to a type checking slow path |
| 7307 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7308 | // require to assign fixed registers for the inputs of this |
| 7309 | // HInstanceOf instruction (following the runtime calling |
| 7310 | // convention), which might be cluttered by the potential first |
| 7311 | // read barrier emission at the beginning of this method. |
| 7312 | // |
| 7313 | // TODO: Introduce a new runtime entry point taking the object |
| 7314 | // to test (instead of its class) as argument, and let it deal |
| 7315 | // with the read barrier issues. This will let us refactor this |
| 7316 | // case of the `switch` code as it was previously (with a direct |
| 7317 | // call to the runtime not using a type checking slow path). |
| 7318 | // This should also be beneficial for the other cases above. |
| 7319 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7320 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7321 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7322 | codegen_->AddSlowPath(slow_path); |
| 7323 | __ B(slow_path->GetEntryLabel()); |
| 7324 | break; |
| 7325 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7326 | } |
| 7327 | |
| 7328 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7329 | |
| 7330 | if (slow_path != nullptr) { |
| 7331 | __ Bind(slow_path->GetExitLabel()); |
| 7332 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7336 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7337 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7338 | } |
| 7339 | |
| 7340 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 7341 | // Will be generated at use site. |
| 7342 | } |
| 7343 | |
| 7344 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7345 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7346 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7347 | } |
| 7348 | |
| 7349 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 7350 | // Will be generated at use site. |
| 7351 | } |
| 7352 | |
| 7353 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 7354 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 7355 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 7356 | } |
| 7357 | |
| 7358 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7359 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7360 | // 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] | 7361 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7362 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7363 | } |
| 7364 | |
| 7365 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7366 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 7367 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7368 | Location receiver = invoke->GetLocations()->InAt(0); |
| 7369 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7370 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7371 | |
| 7372 | // Set the hidden argument. |
| 7373 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 7374 | invoke->GetDexMethodIndex()); |
| 7375 | |
| 7376 | // temp = object->GetClass(); |
| 7377 | if (receiver.IsStackSlot()) { |
| 7378 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 7379 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 7380 | } else { |
| 7381 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 7382 | } |
| 7383 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7384 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7385 | // emit a read barrier for the previous class reference load. |
| 7386 | // However this is not required in practice, as this is an |
| 7387 | // intermediate/temporary reference and because the current |
| 7388 | // concurrent copying collector keeps the from-space memory |
| 7389 | // intact/accessible until the end of the marking phase (the |
| 7390 | // concurrent copying collector may not in the future). |
| 7391 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 7392 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 7393 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 7394 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7395 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7396 | // temp = temp->GetImtEntryAt(method_offset); |
| 7397 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7398 | // T9 = temp->GetEntryPoint(); |
| 7399 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7400 | // T9(); |
| 7401 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7402 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7403 | DCHECK(!codegen_->IsLeafMethod()); |
| 7404 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7405 | } |
| 7406 | |
| 7407 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7408 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7409 | if (intrinsic.TryDispatch(invoke)) { |
| 7410 | return; |
| 7411 | } |
| 7412 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7413 | HandleInvoke(invoke); |
| 7414 | } |
| 7415 | |
| 7416 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7417 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7418 | // art::PrepareForRegisterAllocation. |
| 7419 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7420 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7421 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7422 | bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
| 7423 | bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7424 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7425 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7426 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7427 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 7428 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 7429 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7430 | return; |
| 7431 | } |
| 7432 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7433 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7434 | |
| 7435 | // Add the extra input register if either the dex cache array base register |
| 7436 | // or the PC-relative base register for accessing literals is needed. |
| 7437 | if (has_extra_input) { |
| 7438 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 7439 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7440 | } |
| 7441 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 7442 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7443 | HandleInvoke(invoke); |
| 7444 | } |
| 7445 | |
| 7446 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7447 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 7448 | } |
| 7449 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7450 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7451 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7452 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 7453 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7454 | return true; |
| 7455 | } |
| 7456 | return false; |
| 7457 | } |
| 7458 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7459 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7460 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7461 | switch (desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7462 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7463 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7464 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7465 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7466 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7467 | case HLoadString::LoadKind::kJitTableAddress: |
| 7468 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7469 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7470 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7471 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7472 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7473 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7474 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7475 | } |
| 7476 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7477 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 7478 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7479 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7480 | case HLoadClass::LoadKind::kInvalid: |
| 7481 | LOG(FATAL) << "UNREACHABLE"; |
| 7482 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7483 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7484 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7485 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7486 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7487 | case HLoadClass::LoadKind::kBssEntry: |
| 7488 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7489 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7490 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7491 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7492 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7493 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7494 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7495 | break; |
| 7496 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7497 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7498 | } |
| 7499 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7500 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7501 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7502 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7503 | CHECK(!GetGraph()->HasIrreducibleLoops()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7504 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7505 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7506 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7507 | return location.AsRegister<Register>(); |
| 7508 | } |
| 7509 | // For intrinsics we allow any location, so it may be on the stack. |
| 7510 | if (!location.IsRegister()) { |
| 7511 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7512 | return temp; |
| 7513 | } |
| 7514 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7515 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7516 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7517 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7518 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7519 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7520 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7521 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7522 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7523 | return temp; |
| 7524 | } |
| 7525 | return location.AsRegister<Register>(); |
| 7526 | } |
| 7527 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7528 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 7529 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 7530 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7531 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7532 | } |
| 7533 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7534 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall( |
| 7535 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7536 | // 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] | 7537 | 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] | 7538 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 7539 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7540 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7541 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 7542 | Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7543 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 7544 | : ZERO; |
| 7545 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7546 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7547 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7548 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7549 | uint32_t offset = |
| 7550 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7551 | __ LoadFromOffset(kLoadWord, |
| 7552 | temp.AsRegister<Register>(), |
| 7553 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7554 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7555 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7556 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7557 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7558 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7559 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7560 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 7561 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7562 | PcRelativePatchInfo* info_high = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 7563 | PcRelativePatchInfo* info_low = |
| 7564 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), info_high); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7565 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7566 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7567 | __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7568 | break; |
| 7569 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7570 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7571 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7572 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7573 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7574 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7575 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7576 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 7577 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7578 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7579 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7580 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7581 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7582 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7583 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 7584 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 7585 | return; // No code pointer retrieval; the runtime performs the call directly. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7586 | } |
| 7587 | } |
| 7588 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7589 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7590 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7591 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7592 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7593 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7594 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 7595 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7596 | T9, |
| 7597 | callee_method.AsRegister<Register>(), |
| 7598 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7599 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7600 | // T9() |
| 7601 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7602 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7603 | break; |
| 7604 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7605 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 7606 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7607 | DCHECK(!IsLeafMethod()); |
| 7608 | } |
| 7609 | |
| 7610 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7611 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7612 | // art::PrepareForRegisterAllocation. |
| 7613 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7614 | |
| 7615 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7616 | return; |
| 7617 | } |
| 7618 | |
| 7619 | LocationSummary* locations = invoke->GetLocations(); |
| 7620 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 7621 | locations->HasTemps() |
| 7622 | ? locations->GetTemp(0) |
| 7623 | : Location::NoLocation()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7624 | } |
| 7625 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7626 | void CodeGeneratorMIPS::GenerateVirtualCall( |
| 7627 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7628 | // Use the calling convention instead of the location of the receiver, as |
| 7629 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7630 | // slow path, the arguments have been moved to the right place, so here we are |
| 7631 | // guaranteed that the receiver is the first register of the calling convention. |
| 7632 | InvokeDexCallingConvention calling_convention; |
| 7633 | Register receiver = calling_convention.GetRegisterAt(0); |
| 7634 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7635 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7636 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7637 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 7638 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7639 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7640 | |
| 7641 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7642 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7643 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7644 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7645 | // emit a read barrier for the previous class reference load. |
| 7646 | // However this is not required in practice, as this is an |
| 7647 | // intermediate/temporary reference and because the current |
| 7648 | // concurrent copying collector keeps the from-space memory |
| 7649 | // intact/accessible until the end of the marking phase (the |
| 7650 | // concurrent copying collector may not in the future). |
| 7651 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7652 | // temp = temp->GetMethodAt(method_offset); |
| 7653 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7654 | // T9 = temp->GetEntryPoint(); |
| 7655 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7656 | // T9(); |
| 7657 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7658 | __ NopIfNoReordering(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7659 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 7663 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7664 | return; |
| 7665 | } |
| 7666 | |
| 7667 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7668 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7669 | } |
| 7670 | |
| 7671 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7672 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7673 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7674 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7675 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7676 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7677 | return; |
| 7678 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7679 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7680 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7681 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7682 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7683 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7684 | ? LocationSummary::kCallOnSlowPath |
| 7685 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7686 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7687 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 7688 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7689 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7690 | switch (load_kind) { |
| 7691 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7692 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7693 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7694 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7695 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7696 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7697 | break; |
| 7698 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7699 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 7700 | if (load_kind != HLoadClass::LoadKind::kBootImageAddress) { |
| 7701 | codegen_->ClobberRA(); |
| 7702 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7703 | break; |
| 7704 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7705 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7706 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7707 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7708 | break; |
| 7709 | default: |
| 7710 | break; |
| 7711 | } |
| 7712 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7713 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7714 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7715 | // Rely on the type resolution or initialization and marking to save everything we need. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7716 | // Request a temp to hold the BSS entry location for the slow path. |
| 7717 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7718 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7719 | InvokeRuntimeCallingConvention calling_convention; |
| 7720 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7721 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7722 | } else { |
| 7723 | // For non-Baker read barriers we have a temp-clobbering call. |
| 7724 | } |
| 7725 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7726 | } |
| 7727 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7728 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7729 | // move. |
| 7730 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7731 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7732 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7733 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 7734 | return; |
| 7735 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7736 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 7737 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7738 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7739 | Location out_loc = locations->Out(); |
| 7740 | Register out = out_loc.AsRegister<Register>(); |
| 7741 | Register base_or_current_method_reg; |
| 7742 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7743 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7744 | switch (load_kind) { |
| 7745 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7746 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7747 | case HLoadClass::LoadKind::kBootImageAddress: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7748 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7749 | case HLoadClass::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7750 | base_or_current_method_reg = |
| 7751 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7752 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7753 | case HLoadClass::LoadKind::kReferrersClass: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7754 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7755 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 7756 | break; |
| 7757 | default: |
| 7758 | base_or_current_method_reg = ZERO; |
| 7759 | break; |
| 7760 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7761 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7762 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7763 | ? kWithoutReadBarrier |
| 7764 | : kCompilerReadBarrierOption; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7765 | bool generate_null_check = false; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7766 | CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = nullptr; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7767 | switch (load_kind) { |
| 7768 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7769 | DCHECK(!cls->CanCallRuntime()); |
| 7770 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7771 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7772 | GenerateGcRootFieldLoad(cls, |
| 7773 | out_loc, |
| 7774 | base_or_current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7775 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7776 | read_barrier_option); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7777 | break; |
| 7778 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7779 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7780 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7781 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7782 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7783 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7784 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7785 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7786 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 7787 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7788 | base_or_current_method_reg); |
| 7789 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7790 | break; |
| 7791 | } |
| 7792 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7793 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7794 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7795 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7796 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7797 | if (isR6 || !has_irreducible_loops) { |
| 7798 | __ LoadLiteral(out, |
| 7799 | base_or_current_method_reg, |
| 7800 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7801 | } else { |
| 7802 | __ LoadConst32(out, address); |
| 7803 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7804 | break; |
| 7805 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7806 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 7807 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7808 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 7809 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7810 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7811 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 7812 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 7813 | out, |
| 7814 | base_or_current_method_reg); |
| 7815 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 7816 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 7817 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 7818 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 7819 | if (masked_hash != 0) { |
| 7820 | __ Addiu(out, out, -masked_hash); |
| 7821 | } |
| 7822 | break; |
| 7823 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7824 | case HLoadClass::LoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7825 | bss_info_high = codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7826 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7827 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7828 | constexpr bool non_baker_read_barrier = kUseReadBarrier && !kUseBakerReadBarrier; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7829 | Register temp = non_baker_read_barrier ? out : locations->GetTemp(0).AsRegister<Register>(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7830 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, |
| 7831 | temp, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7832 | base_or_current_method_reg); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7833 | GenerateGcRootFieldLoad(cls, |
| 7834 | out_loc, |
| 7835 | temp, |
| 7836 | /* placeholder */ 0x5678, |
| 7837 | read_barrier_option, |
| 7838 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7839 | generate_null_check = true; |
| 7840 | break; |
| 7841 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7842 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7843 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 7844 | cls->GetTypeIndex(), |
| 7845 | cls->GetClass()); |
| 7846 | bool reordering = __ SetReorder(false); |
| 7847 | __ Bind(&info->high_label); |
| 7848 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7849 | __ SetReorder(reordering); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7850 | GenerateGcRootFieldLoad(cls, |
| 7851 | out_loc, |
| 7852 | out, |
| 7853 | /* placeholder */ 0x5678, |
| 7854 | read_barrier_option, |
| 7855 | &info->low_label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7856 | break; |
| 7857 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7858 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7859 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7860 | LOG(FATAL) << "UNREACHABLE"; |
| 7861 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7862 | } |
| 7863 | |
| 7864 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7865 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7866 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7867 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck(), bss_info_high); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7868 | codegen_->AddSlowPath(slow_path); |
| 7869 | if (generate_null_check) { |
| 7870 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 7871 | } |
| 7872 | if (cls->MustGenerateClinitCheck()) { |
| 7873 | GenerateClassInitializationCheck(slow_path, out); |
| 7874 | } else { |
| 7875 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7876 | } |
| 7877 | } |
| 7878 | } |
| 7879 | |
| 7880 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7881 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7882 | } |
| 7883 | |
| 7884 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 7885 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7886 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7887 | locations->SetOut(Location::RequiresRegister()); |
| 7888 | } |
| 7889 | |
| 7890 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 7891 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 7892 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 7893 | } |
| 7894 | |
| 7895 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7896 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7897 | } |
| 7898 | |
| 7899 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7900 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 7901 | } |
| 7902 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7903 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 7904 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7905 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7906 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7907 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7908 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7909 | switch (load_kind) { |
| 7910 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7911 | case HLoadString::LoadKind::kBootImageAddress: |
| 7912 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7913 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7914 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7915 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7916 | break; |
| 7917 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7918 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 7919 | if (load_kind != HLoadString::LoadKind::kBootImageAddress) { |
| 7920 | codegen_->ClobberRA(); |
| 7921 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7922 | break; |
| 7923 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7924 | FALLTHROUGH_INTENDED; |
| 7925 | // We need an extra register for PC-relative dex cache accesses. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7926 | case HLoadString::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7927 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7928 | break; |
| 7929 | default: |
| 7930 | break; |
| 7931 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7932 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 7933 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7934 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 7935 | } else { |
| 7936 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7937 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7938 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7939 | // Rely on the pResolveString and marking to save everything we need. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7940 | // Request a temp to hold the BSS entry location for the slow path. |
| 7941 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7942 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7943 | InvokeRuntimeCallingConvention calling_convention; |
| 7944 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7945 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7946 | } else { |
| 7947 | // For non-Baker read barriers we have a temp-clobbering call. |
| 7948 | } |
| 7949 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 7950 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7951 | } |
| 7952 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7953 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7954 | // move. |
| 7955 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7956 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7957 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7958 | Location out_loc = locations->Out(); |
| 7959 | Register out = out_loc.AsRegister<Register>(); |
| 7960 | Register base_or_current_method_reg; |
| 7961 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7962 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7963 | switch (load_kind) { |
| 7964 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7965 | case HLoadString::LoadKind::kBootImageAddress: |
| 7966 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7967 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7968 | case HLoadString::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7969 | base_or_current_method_reg = |
| 7970 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7971 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7972 | default: |
| 7973 | base_or_current_method_reg = ZERO; |
| 7974 | break; |
| 7975 | } |
| 7976 | |
| 7977 | switch (load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7978 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7979 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7980 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7981 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7982 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7983 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7984 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 7985 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7986 | base_or_current_method_reg); |
| 7987 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7988 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7989 | } |
| 7990 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7991 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7992 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7993 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7994 | if (isR6 || !has_irreducible_loops) { |
| 7995 | __ LoadLiteral(out, |
| 7996 | base_or_current_method_reg, |
| 7997 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7998 | } else { |
| 7999 | __ LoadConst32(out, address); |
| 8000 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8001 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8002 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8003 | case HLoadString::LoadKind::kBootImageInternTable: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8004 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8005 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8006 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8007 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8008 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8009 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8010 | out, |
| 8011 | base_or_current_method_reg); |
| 8012 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8013 | return; |
| 8014 | } |
| 8015 | case HLoadString::LoadKind::kBssEntry: { |
| 8016 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8017 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 8018 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 8019 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8020 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8021 | constexpr bool non_baker_read_barrier = kUseReadBarrier && !kUseBakerReadBarrier; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8022 | Register temp = non_baker_read_barrier ? out : locations->GetTemp(0).AsRegister<Register>(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8023 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8024 | temp, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8025 | base_or_current_method_reg); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8026 | GenerateGcRootFieldLoad(load, |
| 8027 | out_loc, |
| 8028 | temp, |
| 8029 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8030 | kCompilerReadBarrierOption, |
| 8031 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8032 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8033 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load, info_high); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8034 | codegen_->AddSlowPath(slow_path); |
| 8035 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8036 | __ Bind(slow_path->GetExitLabel()); |
| 8037 | return; |
| 8038 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8039 | case HLoadString::LoadKind::kJitTableAddress: { |
| 8040 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 8041 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 8042 | load->GetStringIndex(), |
| 8043 | load->GetString()); |
| 8044 | bool reordering = __ SetReorder(false); |
| 8045 | __ Bind(&info->high_label); |
| 8046 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8047 | __ SetReorder(reordering); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8048 | GenerateGcRootFieldLoad(load, |
| 8049 | out_loc, |
| 8050 | out, |
| 8051 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8052 | kCompilerReadBarrierOption, |
| 8053 | &info->low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8054 | return; |
| 8055 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8056 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8057 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8058 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 8059 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8060 | // 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] | 8061 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8062 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8063 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8064 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8065 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 8066 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8067 | } |
| 8068 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8069 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8070 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8071 | locations->SetOut(Location::ConstantLocation(constant)); |
| 8072 | } |
| 8073 | |
| 8074 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 8075 | // Will be generated at use site. |
| 8076 | } |
| 8077 | |
| 8078 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8079 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8080 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8081 | InvokeRuntimeCallingConvention calling_convention; |
| 8082 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8083 | } |
| 8084 | |
| 8085 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8086 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8087 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8088 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8089 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8090 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8091 | } |
| 8092 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8093 | } |
| 8094 | |
| 8095 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 8096 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8097 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8098 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8099 | case DataType::Type::kInt32: |
| 8100 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8101 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8102 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8103 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8104 | break; |
| 8105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8106 | case DataType::Type::kFloat32: |
| 8107 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8108 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8109 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8110 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8111 | break; |
| 8112 | |
| 8113 | default: |
| 8114 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 8115 | } |
| 8116 | } |
| 8117 | |
| 8118 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8119 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8120 | LocationSummary* locations = instruction->GetLocations(); |
| 8121 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 8122 | |
| 8123 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8124 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8125 | Register dst = locations->Out().AsRegister<Register>(); |
| 8126 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 8127 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 8128 | |
| 8129 | if (isR6) { |
| 8130 | __ MulR6(dst, lhs, rhs); |
| 8131 | } else { |
| 8132 | __ MulR2(dst, lhs, rhs); |
| 8133 | } |
| 8134 | break; |
| 8135 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8136 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8137 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8138 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8139 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8140 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8141 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8142 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8143 | |
| 8144 | // Extra checks to protect caused by the existance of A1_A2. |
| 8145 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 8146 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 8147 | DCHECK_NE(dst_high, lhs_low); |
| 8148 | DCHECK_NE(dst_high, rhs_low); |
| 8149 | |
| 8150 | // A_B * C_D |
| 8151 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 8152 | // dst_lo: [ low(B*D) ] |
| 8153 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 8154 | |
| 8155 | if (isR6) { |
| 8156 | __ MulR6(TMP, lhs_high, rhs_low); |
| 8157 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 8158 | __ Addu(dst_high, dst_high, TMP); |
| 8159 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 8160 | __ Addu(dst_high, dst_high, TMP); |
| 8161 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 8162 | } else { |
| 8163 | __ MulR2(TMP, lhs_high, rhs_low); |
| 8164 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 8165 | __ Addu(dst_high, dst_high, TMP); |
| 8166 | __ MultuR2(lhs_low, rhs_low); |
| 8167 | __ Mfhi(TMP); |
| 8168 | __ Addu(dst_high, dst_high, TMP); |
| 8169 | __ Mflo(dst_low); |
| 8170 | } |
| 8171 | break; |
| 8172 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8173 | case DataType::Type::kFloat32: |
| 8174 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8175 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8176 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8177 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8178 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8179 | __ MulS(dst, lhs, rhs); |
| 8180 | } else { |
| 8181 | __ MulD(dst, lhs, rhs); |
| 8182 | } |
| 8183 | break; |
| 8184 | } |
| 8185 | default: |
| 8186 | LOG(FATAL) << "Unexpected mul type " << type; |
| 8187 | } |
| 8188 | } |
| 8189 | |
| 8190 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 8191 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8192 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8193 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8194 | case DataType::Type::kInt32: |
| 8195 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8196 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8197 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8198 | break; |
| 8199 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8200 | case DataType::Type::kFloat32: |
| 8201 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8202 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8203 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8204 | break; |
| 8205 | |
| 8206 | default: |
| 8207 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 8208 | } |
| 8209 | } |
| 8210 | |
| 8211 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8212 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8213 | LocationSummary* locations = instruction->GetLocations(); |
| 8214 | |
| 8215 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8216 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8217 | Register dst = locations->Out().AsRegister<Register>(); |
| 8218 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8219 | __ Subu(dst, ZERO, src); |
| 8220 | break; |
| 8221 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8222 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8223 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8224 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8225 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8226 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8227 | __ Subu(dst_low, ZERO, src_low); |
| 8228 | __ Sltu(TMP, ZERO, dst_low); |
| 8229 | __ Subu(dst_high, ZERO, src_high); |
| 8230 | __ Subu(dst_high, dst_high, TMP); |
| 8231 | break; |
| 8232 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8233 | case DataType::Type::kFloat32: |
| 8234 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8235 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8236 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8237 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8238 | __ NegS(dst, src); |
| 8239 | } else { |
| 8240 | __ NegD(dst, src); |
| 8241 | } |
| 8242 | break; |
| 8243 | } |
| 8244 | default: |
| 8245 | LOG(FATAL) << "Unexpected neg type " << type; |
| 8246 | } |
| 8247 | } |
| 8248 | |
| 8249 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8250 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8251 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8252 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8253 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8254 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8255 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8256 | } |
| 8257 | |
| 8258 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8259 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8260 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8261 | QuickEntrypointEnum entrypoint = |
| 8262 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 8263 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8264 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8265 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8266 | } |
| 8267 | |
| 8268 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8269 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8270 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8271 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8272 | if (instruction->IsStringAlloc()) { |
| 8273 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8274 | } else { |
| 8275 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8276 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8277 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8278 | } |
| 8279 | |
| 8280 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8281 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8282 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8283 | if (instruction->IsStringAlloc()) { |
| 8284 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 8285 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8286 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8287 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 8288 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 8289 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8290 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8291 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 8292 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8293 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 8294 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8295 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8296 | } |
| 8297 | |
| 8298 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8299 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8300 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8301 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8302 | } |
| 8303 | |
| 8304 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8305 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8306 | LocationSummary* locations = instruction->GetLocations(); |
| 8307 | |
| 8308 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8309 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8310 | Register dst = locations->Out().AsRegister<Register>(); |
| 8311 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8312 | __ Nor(dst, src, ZERO); |
| 8313 | break; |
| 8314 | } |
| 8315 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8316 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8317 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8318 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8319 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8320 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8321 | __ Nor(dst_high, src_high, ZERO); |
| 8322 | __ Nor(dst_low, src_low, ZERO); |
| 8323 | break; |
| 8324 | } |
| 8325 | |
| 8326 | default: |
| 8327 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 8328 | } |
| 8329 | } |
| 8330 | |
| 8331 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8332 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8333 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8334 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8335 | } |
| 8336 | |
| 8337 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 8338 | LocationSummary* locations = instruction->GetLocations(); |
| 8339 | __ Xori(locations->Out().AsRegister<Register>(), |
| 8340 | locations->InAt(0).AsRegister<Register>(), |
| 8341 | 1); |
| 8342 | } |
| 8343 | |
| 8344 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 8345 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 8346 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8347 | } |
| 8348 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8349 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 8350 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8351 | return; |
| 8352 | } |
| 8353 | Location obj = instruction->GetLocations()->InAt(0); |
| 8354 | |
| 8355 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8356 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8357 | } |
| 8358 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8359 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8360 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8361 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8362 | |
| 8363 | Location obj = instruction->GetLocations()->InAt(0); |
| 8364 | |
| 8365 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8366 | } |
| 8367 | |
| 8368 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8369 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8370 | } |
| 8371 | |
| 8372 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 8373 | HandleBinaryOp(instruction); |
| 8374 | } |
| 8375 | |
| 8376 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 8377 | HandleBinaryOp(instruction); |
| 8378 | } |
| 8379 | |
| 8380 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 8381 | LOG(FATAL) << "Unreachable"; |
| 8382 | } |
| 8383 | |
| 8384 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 8385 | if (instruction->GetNext()->IsSuspendCheck() && |
| 8386 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 8387 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 8388 | // The back edge will generate the suspend check. |
| 8389 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 8390 | } |
| 8391 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8392 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 8393 | } |
| 8394 | |
| 8395 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8396 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8397 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 8398 | if (location.IsStackSlot()) { |
| 8399 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8400 | } else if (location.IsDoubleStackSlot()) { |
| 8401 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8402 | } |
| 8403 | locations->SetOut(location); |
| 8404 | } |
| 8405 | |
| 8406 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 8407 | ATTRIBUTE_UNUSED) { |
| 8408 | // Nothing to do, the parameter is already at its location. |
| 8409 | } |
| 8410 | |
| 8411 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 8412 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8413 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8414 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8415 | } |
| 8416 | |
| 8417 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 8418 | ATTRIBUTE_UNUSED) { |
| 8419 | // Nothing to do, the method is already at its location. |
| 8420 | } |
| 8421 | |
| 8422 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8423 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8424 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8425 | locations->SetInAt(i, Location::Any()); |
| 8426 | } |
| 8427 | locations->SetOut(Location::Any()); |
| 8428 | } |
| 8429 | |
| 8430 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 8431 | LOG(FATAL) << "Unreachable"; |
| 8432 | } |
| 8433 | |
| 8434 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8435 | DataType::Type type = rem->GetResultType(); |
| 8436 | LocationSummary::CallKind call_kind = (type == DataType::Type::kInt32) |
| 8437 | ? LocationSummary::kNoCall |
| 8438 | : LocationSummary::kCallOnMainOnly; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8439 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8440 | |
| 8441 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8442 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8443 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8444 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8445 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8446 | break; |
| 8447 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8448 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8449 | InvokeRuntimeCallingConvention calling_convention; |
| 8450 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8451 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8452 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 8453 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 8454 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8455 | break; |
| 8456 | } |
| 8457 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8458 | case DataType::Type::kFloat32: |
| 8459 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8460 | InvokeRuntimeCallingConvention calling_convention; |
| 8461 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8462 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 8463 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8464 | break; |
| 8465 | } |
| 8466 | |
| 8467 | default: |
| 8468 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8469 | } |
| 8470 | } |
| 8471 | |
| 8472 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8473 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8474 | |
| 8475 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8476 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8477 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8478 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8479 | case DataType::Type::kInt64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8480 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8481 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 8482 | break; |
| 8483 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8484 | case DataType::Type::kFloat32: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8485 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8486 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8487 | break; |
| 8488 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8489 | case DataType::Type::kFloat64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8490 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8491 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8492 | break; |
| 8493 | } |
| 8494 | default: |
| 8495 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8496 | } |
| 8497 | } |
| 8498 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8499 | void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 8500 | constructor_fence->SetLocations(nullptr); |
| 8501 | } |
| 8502 | |
| 8503 | void InstructionCodeGeneratorMIPS::VisitConstructorFence( |
| 8504 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 8505 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 8506 | } |
| 8507 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8508 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8509 | memory_barrier->SetLocations(nullptr); |
| 8510 | } |
| 8511 | |
| 8512 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8513 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 8514 | } |
| 8515 | |
| 8516 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8517 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8518 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8519 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 8520 | } |
| 8521 | |
| 8522 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 8523 | codegen_->GenerateFrameExit(); |
| 8524 | } |
| 8525 | |
| 8526 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 8527 | ret->SetLocations(nullptr); |
| 8528 | } |
| 8529 | |
| 8530 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 8531 | codegen_->GenerateFrameExit(); |
| 8532 | } |
| 8533 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8534 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 8535 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8536 | } |
| 8537 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8538 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 8539 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8540 | } |
| 8541 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8542 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 8543 | HandleShift(shl); |
| 8544 | } |
| 8545 | |
| 8546 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 8547 | HandleShift(shl); |
| 8548 | } |
| 8549 | |
| 8550 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 8551 | HandleShift(shr); |
| 8552 | } |
| 8553 | |
| 8554 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 8555 | HandleShift(shr); |
| 8556 | } |
| 8557 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8558 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 8559 | HandleBinaryOp(instruction); |
| 8560 | } |
| 8561 | |
| 8562 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 8563 | HandleBinaryOp(instruction); |
| 8564 | } |
| 8565 | |
| 8566 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8567 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 8568 | } |
| 8569 | |
| 8570 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8571 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 8572 | } |
| 8573 | |
| 8574 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 8575 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 8576 | } |
| 8577 | |
| 8578 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 8579 | HandleFieldSet(instruction, |
| 8580 | instruction->GetFieldInfo(), |
| 8581 | instruction->GetDexPc(), |
| 8582 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8583 | } |
| 8584 | |
| 8585 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 8586 | HUnresolvedInstanceFieldGet* instruction) { |
| 8587 | FieldAccessCallingConventionMIPS calling_convention; |
| 8588 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8589 | instruction->GetFieldType(), |
| 8590 | calling_convention); |
| 8591 | } |
| 8592 | |
| 8593 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 8594 | HUnresolvedInstanceFieldGet* instruction) { |
| 8595 | FieldAccessCallingConventionMIPS calling_convention; |
| 8596 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8597 | instruction->GetFieldType(), |
| 8598 | instruction->GetFieldIndex(), |
| 8599 | instruction->GetDexPc(), |
| 8600 | calling_convention); |
| 8601 | } |
| 8602 | |
| 8603 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 8604 | HUnresolvedInstanceFieldSet* instruction) { |
| 8605 | FieldAccessCallingConventionMIPS calling_convention; |
| 8606 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8607 | instruction->GetFieldType(), |
| 8608 | calling_convention); |
| 8609 | } |
| 8610 | |
| 8611 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 8612 | HUnresolvedInstanceFieldSet* instruction) { |
| 8613 | FieldAccessCallingConventionMIPS calling_convention; |
| 8614 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8615 | instruction->GetFieldType(), |
| 8616 | instruction->GetFieldIndex(), |
| 8617 | instruction->GetDexPc(), |
| 8618 | calling_convention); |
| 8619 | } |
| 8620 | |
| 8621 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 8622 | HUnresolvedStaticFieldGet* instruction) { |
| 8623 | FieldAccessCallingConventionMIPS calling_convention; |
| 8624 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8625 | instruction->GetFieldType(), |
| 8626 | calling_convention); |
| 8627 | } |
| 8628 | |
| 8629 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 8630 | HUnresolvedStaticFieldGet* instruction) { |
| 8631 | FieldAccessCallingConventionMIPS calling_convention; |
| 8632 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8633 | instruction->GetFieldType(), |
| 8634 | instruction->GetFieldIndex(), |
| 8635 | instruction->GetDexPc(), |
| 8636 | calling_convention); |
| 8637 | } |
| 8638 | |
| 8639 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 8640 | HUnresolvedStaticFieldSet* instruction) { |
| 8641 | FieldAccessCallingConventionMIPS calling_convention; |
| 8642 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8643 | instruction->GetFieldType(), |
| 8644 | calling_convention); |
| 8645 | } |
| 8646 | |
| 8647 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 8648 | HUnresolvedStaticFieldSet* instruction) { |
| 8649 | FieldAccessCallingConventionMIPS calling_convention; |
| 8650 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8651 | instruction->GetFieldType(), |
| 8652 | instruction->GetFieldIndex(), |
| 8653 | instruction->GetDexPc(), |
| 8654 | calling_convention); |
| 8655 | } |
| 8656 | |
| 8657 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8658 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8659 | instruction, LocationSummary::kCallOnSlowPath); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 8660 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 8661 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 8662 | // registers in full width (since the runtime only saves/restores lower part). |
| 8663 | locations->SetCustomSlowPathCallerSaves( |
| 8664 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8665 | } |
| 8666 | |
| 8667 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 8668 | HBasicBlock* block = instruction->GetBlock(); |
| 8669 | if (block->GetLoopInformation() != nullptr) { |
| 8670 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 8671 | // The back edge will generate the suspend check. |
| 8672 | return; |
| 8673 | } |
| 8674 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 8675 | // The goto will generate the suspend check. |
| 8676 | return; |
| 8677 | } |
| 8678 | GenerateSuspendCheck(instruction, nullptr); |
| 8679 | } |
| 8680 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8681 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8682 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8683 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8684 | InvokeRuntimeCallingConvention calling_convention; |
| 8685 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8686 | } |
| 8687 | |
| 8688 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8689 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8690 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 8691 | } |
| 8692 | |
| 8693 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8694 | DataType::Type input_type = conversion->GetInputType(); |
| 8695 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8696 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 8697 | << input_type << " -> " << result_type; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8698 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8699 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8700 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 8701 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8702 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 8703 | } |
| 8704 | |
| 8705 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8706 | if (!isR6 && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8707 | ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) || |
| 8708 | (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 8709 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8710 | } |
| 8711 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8712 | LocationSummary* locations = |
| 8713 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8714 | |
| 8715 | if (call_kind == LocationSummary::kNoCall) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8716 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8717 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8718 | } else { |
| 8719 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8720 | } |
| 8721 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8722 | if (DataType::IsFloatingPointType(result_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8723 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8724 | } else { |
| 8725 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8726 | } |
| 8727 | } else { |
| 8728 | InvokeRuntimeCallingConvention calling_convention; |
| 8729 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8730 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8731 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8732 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8733 | DCHECK_EQ(input_type, DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8734 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8735 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8736 | } |
| 8737 | |
| 8738 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 8739 | } |
| 8740 | } |
| 8741 | |
| 8742 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 8743 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8744 | DataType::Type result_type = conversion->GetResultType(); |
| 8745 | DataType::Type input_type = conversion->GetInputType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8746 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8747 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8748 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8749 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 8750 | << input_type << " -> " << result_type; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8751 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8752 | if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8753 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8754 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8755 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8756 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 8757 | if (dst_low != src) { |
| 8758 | __ Move(dst_low, src); |
| 8759 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8760 | __ Sra(dst_high, src, 31); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8761 | } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8762 | Register dst = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8763 | Register src = (input_type == DataType::Type::kInt64) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8764 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 8765 | : locations->InAt(0).AsRegister<Register>(); |
| 8766 | |
| 8767 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8768 | case DataType::Type::kUint8: |
| 8769 | __ Andi(dst, src, 0xFF); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8770 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8771 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8772 | if (has_sign_extension) { |
| 8773 | __ Seb(dst, src); |
| 8774 | } else { |
| 8775 | __ Sll(dst, src, 24); |
| 8776 | __ Sra(dst, dst, 24); |
| 8777 | } |
| 8778 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8779 | case DataType::Type::kUint16: |
| 8780 | __ Andi(dst, src, 0xFFFF); |
| 8781 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8782 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8783 | if (has_sign_extension) { |
| 8784 | __ Seh(dst, src); |
| 8785 | } else { |
| 8786 | __ Sll(dst, src, 16); |
| 8787 | __ Sra(dst, dst, 16); |
| 8788 | } |
| 8789 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8790 | case DataType::Type::kInt32: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 8791 | if (dst != src) { |
| 8792 | __ Move(dst, src); |
| 8793 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8794 | break; |
| 8795 | |
| 8796 | default: |
| 8797 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 8798 | << " to " << result_type; |
| 8799 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8800 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| 8801 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8802 | if (isR6) { |
| 8803 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 8804 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 8805 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8806 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8807 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8808 | __ Mtc1(src_low, FTMP); |
| 8809 | __ Mthc1(src_high, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8810 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8811 | __ Cvtsl(dst, FTMP); |
| 8812 | } else { |
| 8813 | __ Cvtdl(dst, FTMP); |
| 8814 | } |
| 8815 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8816 | QuickEntrypointEnum entrypoint = |
| 8817 | (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8818 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8819 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8820 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 8821 | } else { |
| 8822 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 8823 | } |
| 8824 | } |
| 8825 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8826 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8827 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8828 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8829 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8830 | __ Cvtsw(dst, FTMP); |
| 8831 | } else { |
| 8832 | __ Cvtdw(dst, FTMP); |
| 8833 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8834 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8835 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 8836 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8837 | |
| 8838 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 8839 | // value of the output type if the input is outside of the range after the truncation or |
| 8840 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 8841 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 8842 | // |
| 8843 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 8844 | // value when the input is either a NaN or is outside of the range of the output type |
| 8845 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 8846 | // the same result. |
| 8847 | // |
| 8848 | // The code takes care of the different behaviors by first comparing the input to the |
| 8849 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 8850 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 8851 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 8852 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 8853 | // in order to return either zero or the minimum value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8854 | if (result_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8855 | if (isR6) { |
| 8856 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 8857 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 8858 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8859 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8860 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8861 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8862 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8863 | __ TruncLS(FTMP, src); |
| 8864 | } else { |
| 8865 | __ TruncLD(FTMP, src); |
| 8866 | } |
| 8867 | __ Mfc1(dst_low, FTMP); |
| 8868 | __ Mfhc1(dst_high, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8869 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8870 | QuickEntrypointEnum entrypoint = |
| 8871 | (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8872 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8873 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8874 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 8875 | } else { |
| 8876 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 8877 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8878 | } |
| 8879 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8880 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8881 | Register dst = locations->Out().AsRegister<Register>(); |
| 8882 | MipsLabel truncate; |
| 8883 | MipsLabel done; |
| 8884 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8885 | if (!isR6) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8886 | if (input_type == DataType::Type::kFloat32) { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8887 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 8888 | __ LoadConst32(TMP, min_val); |
| 8889 | __ Mtc1(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8890 | } else { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8891 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 8892 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 8893 | __ Mtc1(ZERO, FTMP); |
| 8894 | __ MoveToFpuHigh(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8895 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8896 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8897 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8898 | __ ColeS(0, FTMP, src); |
| 8899 | } else { |
| 8900 | __ ColeD(0, FTMP, src); |
| 8901 | } |
| 8902 | __ Bc1t(0, &truncate); |
| 8903 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8904 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8905 | __ CeqS(0, src, src); |
| 8906 | } else { |
| 8907 | __ CeqD(0, src, src); |
| 8908 | } |
| 8909 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 8910 | __ Movf(dst, ZERO, 0); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8911 | |
| 8912 | __ B(&done); |
| 8913 | |
| 8914 | __ Bind(&truncate); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8915 | } |
| 8916 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8917 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8918 | __ TruncWS(FTMP, src); |
| 8919 | } else { |
| 8920 | __ TruncWD(FTMP, src); |
| 8921 | } |
| 8922 | __ Mfc1(dst, FTMP); |
| 8923 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8924 | if (!isR6) { |
| 8925 | __ Bind(&done); |
| 8926 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8927 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8928 | } else if (DataType::IsFloatingPointType(result_type) && |
| 8929 | DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8930 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8931 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8932 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8933 | __ Cvtsd(dst, src); |
| 8934 | } else { |
| 8935 | __ Cvtds(dst, src); |
| 8936 | } |
| 8937 | } else { |
| 8938 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 8939 | << " to " << result_type; |
| 8940 | } |
| 8941 | } |
| 8942 | |
| 8943 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 8944 | HandleShift(ushr); |
| 8945 | } |
| 8946 | |
| 8947 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 8948 | HandleShift(ushr); |
| 8949 | } |
| 8950 | |
| 8951 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 8952 | HandleBinaryOp(instruction); |
| 8953 | } |
| 8954 | |
| 8955 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 8956 | HandleBinaryOp(instruction); |
| 8957 | } |
| 8958 | |
| 8959 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 8960 | // Nothing to do, this should be removed during prepare for register allocator. |
| 8961 | LOG(FATAL) << "Unreachable"; |
| 8962 | } |
| 8963 | |
| 8964 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 8965 | // Nothing to do, this should be removed during prepare for register allocator. |
| 8966 | LOG(FATAL) << "Unreachable"; |
| 8967 | } |
| 8968 | |
| 8969 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8970 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8971 | } |
| 8972 | |
| 8973 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8974 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8975 | } |
| 8976 | |
| 8977 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8978 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8979 | } |
| 8980 | |
| 8981 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8982 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8983 | } |
| 8984 | |
| 8985 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8986 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8987 | } |
| 8988 | |
| 8989 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8990 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8991 | } |
| 8992 | |
| 8993 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8994 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8995 | } |
| 8996 | |
| 8997 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8998 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8999 | } |
| 9000 | |
| 9001 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9002 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9003 | } |
| 9004 | |
| 9005 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9006 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9007 | } |
| 9008 | |
| 9009 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9010 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9011 | } |
| 9012 | |
| 9013 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9014 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9015 | } |
| 9016 | |
| 9017 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9018 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9019 | } |
| 9020 | |
| 9021 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9022 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9023 | } |
| 9024 | |
| 9025 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* 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::VisitBelowOrEqual(HBelowOrEqual* 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::VisitAbove(HAbove* 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::VisitAbove(HAbove* 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::VisitAboveOrEqual(HAboveOrEqual* 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::VisitAboveOrEqual(HAboveOrEqual* 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 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9049 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9050 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9051 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9052 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9053 | if (!codegen_->GetInstructionSetFeatures().IsR6()) { |
| 9054 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9055 | if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) { |
| 9056 | // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL |
| 9057 | // instruction to simulate PC-relative addressing when accessing the jump table. |
| 9058 | // NAL clobbers RA. Make sure RA is preserved. |
| 9059 | codegen_->ClobberRA(); |
| 9060 | } |
| 9061 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9062 | } |
| 9063 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9064 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 9065 | int32_t lower_bound, |
| 9066 | uint32_t num_entries, |
| 9067 | HBasicBlock* switch_block, |
| 9068 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9069 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9070 | Register temp_reg = TMP; |
| 9071 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 9072 | // Jump to default if index is negative |
| 9073 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 9074 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 9075 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 9076 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9077 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9078 | // Jump to successors[0] if value == lower_bound. |
| 9079 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 9080 | int32_t last_index = 0; |
| 9081 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9082 | __ Addiu(temp_reg, temp_reg, -2); |
| 9083 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9084 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9085 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9086 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9087 | } |
| 9088 | if (num_entries - last_index == 2) { |
| 9089 | // The last missing case_value. |
| 9090 | __ Addiu(temp_reg, temp_reg, -1); |
| 9091 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9092 | } |
| 9093 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9094 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9095 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9096 | __ B(codegen_->GetLabelOf(default_block)); |
| 9097 | } |
| 9098 | } |
| 9099 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9100 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 9101 | Register constant_area, |
| 9102 | int32_t lower_bound, |
| 9103 | uint32_t num_entries, |
| 9104 | HBasicBlock* switch_block, |
| 9105 | HBasicBlock* default_block) { |
| 9106 | // Create a jump table. |
| 9107 | std::vector<MipsLabel*> labels(num_entries); |
| 9108 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 9109 | for (uint32_t i = 0; i < num_entries; i++) { |
| 9110 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 9111 | } |
| 9112 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 9113 | |
| 9114 | // Is the value in range? |
| 9115 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 9116 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 9117 | __ Sltiu(AT, TMP, num_entries); |
| 9118 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 9119 | } else { |
| 9120 | __ LoadConst32(AT, num_entries); |
| 9121 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 9122 | } |
| 9123 | |
| 9124 | // We are in the range of the table. |
| 9125 | // Load the target address from the jump table, indexing by the value. |
| 9126 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 9127 | __ ShiftAndAdd(TMP, TMP, AT, 2, TMP); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9128 | __ Lw(TMP, TMP, 0); |
| 9129 | // Compute the absolute target address by adding the table start address |
| 9130 | // (the table contains offsets to targets relative to its start). |
| 9131 | __ Addu(TMP, TMP, AT); |
| 9132 | // And jump. |
| 9133 | __ Jr(TMP); |
| 9134 | __ NopIfNoReordering(); |
| 9135 | } |
| 9136 | |
| 9137 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9138 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9139 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9140 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9141 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9142 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9143 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9144 | |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9145 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9146 | // R6 uses PC-relative addressing to access the jump table. |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9147 | // |
| 9148 | // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available) |
| 9149 | // to access the jump table and it is implemented by changing HPackedSwitch to |
| 9150 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see |
| 9151 | // VisitMipsPackedSwitch()). |
| 9152 | // |
| 9153 | // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of |
| 9154 | // irreducible loops), R2 uses the NAL instruction to simulate PC-relative |
| 9155 | // addressing. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9156 | GenTableBasedPackedSwitch(value_reg, |
| 9157 | ZERO, |
| 9158 | lower_bound, |
| 9159 | num_entries, |
| 9160 | switch_block, |
| 9161 | default_block); |
| 9162 | } else { |
| 9163 | GenPackedSwitchWithCompares(value_reg, |
| 9164 | lower_bound, |
| 9165 | num_entries, |
| 9166 | switch_block, |
| 9167 | default_block); |
| 9168 | } |
| 9169 | } |
| 9170 | |
| 9171 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9172 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9173 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9174 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9175 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 9176 | locations->SetInAt(1, Location::RequiresRegister()); |
| 9177 | } |
| 9178 | |
| 9179 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9180 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9181 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9182 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9183 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9184 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 9185 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9186 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9187 | |
| 9188 | // This is an R2-only path. HPackedSwitch has been changed to |
| 9189 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 9190 | // required to address the jump table relative to PC. |
| 9191 | GenTableBasedPackedSwitch(value_reg, |
| 9192 | constant_area, |
| 9193 | lower_bound, |
| 9194 | num_entries, |
| 9195 | switch_block, |
| 9196 | default_block); |
| 9197 | } |
| 9198 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9199 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 9200 | HMipsComputeBaseMethodAddress* insn) { |
| 9201 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9202 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9203 | locations->SetOut(Location::RequiresRegister()); |
| 9204 | } |
| 9205 | |
| 9206 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 9207 | HMipsComputeBaseMethodAddress* insn) { |
| 9208 | LocationSummary* locations = insn->GetLocations(); |
| 9209 | Register reg = locations->Out().AsRegister<Register>(); |
| 9210 | |
| 9211 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 9212 | |
| 9213 | // Generate a dummy PC-relative call to obtain PC. |
| 9214 | __ Nal(); |
| 9215 | // Grab the return address off RA. |
| 9216 | __ Move(reg, RA); |
| 9217 | |
| 9218 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 9219 | __ BindPcRelBaseLabel(); |
| 9220 | } |
| 9221 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9222 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9223 | // The trampoline uses the same calling convention as dex calling conventions, |
| 9224 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 9225 | // the method_idx. |
| 9226 | HandleInvoke(invoke); |
| 9227 | } |
| 9228 | |
| 9229 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9230 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 9231 | } |
| 9232 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9233 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9234 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9235 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9236 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9237 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9238 | } |
| 9239 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9240 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9241 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 9242 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9243 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9244 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9245 | __ LoadFromOffset(kLoadWord, |
| 9246 | locations->Out().AsRegister<Register>(), |
| 9247 | locations->InAt(0).AsRegister<Register>(), |
| 9248 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9249 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9250 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 9251 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 9252 | __ LoadFromOffset(kLoadWord, |
| 9253 | locations->Out().AsRegister<Register>(), |
| 9254 | locations->InAt(0).AsRegister<Register>(), |
| 9255 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9256 | __ LoadFromOffset(kLoadWord, |
| 9257 | locations->Out().AsRegister<Register>(), |
| 9258 | locations->Out().AsRegister<Register>(), |
| 9259 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9260 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9261 | } |
| 9262 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 9263 | void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9264 | ATTRIBUTE_UNUSED) { |
| 9265 | LOG(FATAL) << "Unreachable"; |
| 9266 | } |
| 9267 | |
| 9268 | void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9269 | ATTRIBUTE_UNUSED) { |
| 9270 | LOG(FATAL) << "Unreachable"; |
| 9271 | } |
| 9272 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9273 | #undef __ |
| 9274 | #undef QUICK_ENTRY_POINT |
| 9275 | |
| 9276 | } // namespace mips |
| 9277 | } // namespace art |