Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [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_mips64.h" |
| 18 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 19 | #include "arch/mips64/asm_support_mips64.h" |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 21 | #include "class_table.h" |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 23 | #include "compiled_method.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
| 25 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 26 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 28 | #include "intrinsics.h" |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 29 | #include "intrinsics_mips64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 30 | #include "linker/linker_patch.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
| 32 | #include "mirror/class-inl.h" |
| 33 | #include "offsets.h" |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 34 | #include "stack_map_stream.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 35 | #include "thread.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 36 | #include "utils/assembler.h" |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 37 | #include "utils/mips64/assembler_mips64.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 38 | #include "utils/stack_checks.h" |
| 39 | |
| 40 | namespace art { |
| 41 | namespace mips64 { |
| 42 | |
| 43 | static constexpr int kCurrentMethodStackOffset = 0; |
| 44 | static constexpr GpuRegister kMethodRegisterArgument = A0; |
| 45 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 46 | // Flags controlling the use of thunks for Baker read barriers. |
| 47 | constexpr bool kBakerReadBarrierThunksEnableForFields = true; |
| 48 | constexpr bool kBakerReadBarrierThunksEnableForArrays = true; |
| 49 | constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true; |
| 50 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 51 | Location Mips64ReturnLocation(DataType::Type return_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 52 | switch (return_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 53 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 54 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 55 | case DataType::Type::kInt8: |
| 56 | case DataType::Type::kUint16: |
| 57 | case DataType::Type::kInt16: |
| 58 | case DataType::Type::kInt32: |
| 59 | case DataType::Type::kReference: |
| 60 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 61 | return Location::RegisterLocation(V0); |
| 62 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 63 | case DataType::Type::kFloat32: |
| 64 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 65 | return Location::FpuRegisterLocation(F0); |
| 66 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 67 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 68 | return Location(); |
| 69 | } |
| 70 | UNREACHABLE(); |
| 71 | } |
| 72 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 73 | Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(DataType::Type type) const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 74 | return Mips64ReturnLocation(type); |
| 75 | } |
| 76 | |
| 77 | Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const { |
| 78 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 79 | } |
| 80 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 81 | Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 82 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 83 | if (type == DataType::Type::kVoid) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 84 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 85 | } |
| 86 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 87 | if (DataType::IsFloatingPointType(type) && |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 88 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 89 | next_location = Location::FpuRegisterLocation( |
| 90 | calling_convention.GetFpuRegisterAt(float_index_++)); |
| 91 | gp_index_++; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 92 | } else if (!DataType::IsFloatingPointType(type) && |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 93 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 94 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++)); |
| 95 | float_index_++; |
| 96 | } else { |
| 97 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 98 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 99 | : Location::StackSlot(stack_offset); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 103 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 104 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 105 | return next_location; |
| 106 | } |
| 107 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 108 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 109 | return Mips64ReturnLocation(type); |
| 110 | } |
| 111 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 112 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 113 | #define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 114 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 115 | |
| 116 | class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 117 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 118 | explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 119 | |
| 120 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 121 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 122 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 123 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 124 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 125 | // Live registers will be restored in the catch block if caught. |
| 126 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 127 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 128 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 129 | // move resolver. |
| 130 | InvokeRuntimeCallingConvention calling_convention; |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 131 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 132 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 133 | DataType::Type::kInt32, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 134 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 135 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 136 | DataType::Type::kInt32); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 137 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 138 | ? kQuickThrowStringBounds |
| 139 | : kQuickThrowArrayBounds; |
| 140 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 141 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 142 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 143 | } |
| 144 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 145 | bool IsFatal() const OVERRIDE { return true; } |
| 146 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 147 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; } |
| 148 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 149 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 150 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64); |
| 151 | }; |
| 152 | |
| 153 | class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 154 | public: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 155 | explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) |
| 156 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 157 | |
| 158 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 159 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 160 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 161 | mips64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 162 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 163 | } |
| 164 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 165 | bool IsFatal() const OVERRIDE { return true; } |
| 166 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 167 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; } |
| 168 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 169 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 170 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64); |
| 171 | }; |
| 172 | |
| 173 | class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 174 | public: |
| 175 | LoadClassSlowPathMIPS64(HLoadClass* cls, |
| 176 | HInstruction* at, |
| 177 | uint32_t dex_pc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 178 | bool do_clinit) |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 179 | : SlowPathCodeMIPS64(at), |
| 180 | cls_(cls), |
| 181 | dex_pc_(dex_pc), |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 182 | do_clinit_(do_clinit) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 183 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 184 | } |
| 185 | |
| 186 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 187 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 188 | Location out = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 189 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 190 | InvokeRuntimeCallingConvention calling_convention; |
| 191 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 192 | __ Bind(GetEntryLabel()); |
| 193 | SaveLiveRegisters(codegen, locations); |
| 194 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 195 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 196 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 197 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 198 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 199 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 200 | if (do_clinit_) { |
| 201 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 202 | } else { |
| 203 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 204 | } |
| 205 | |
| 206 | // Move the class to the desired location. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 207 | if (out.IsValid()) { |
| 208 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 209 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 210 | mips64_codegen->MoveLocation(out, |
| 211 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 212 | type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 213 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 214 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 215 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 216 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 219 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; } |
| 220 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 221 | private: |
| 222 | // The class this slow path will load. |
| 223 | HLoadClass* const cls_; |
| 224 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 225 | // The dex PC of `at_`. |
| 226 | const uint32_t dex_pc_; |
| 227 | |
| 228 | // Whether to initialize the class. |
| 229 | const bool do_clinit_; |
| 230 | |
| 231 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64); |
| 232 | }; |
| 233 | |
| 234 | class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 235 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 236 | explicit LoadStringSlowPathMIPS64(HLoadString* instruction) |
| 237 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 238 | |
| 239 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 240 | DCHECK(instruction_->IsLoadString()); |
| 241 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 242 | LocationSummary* locations = instruction_->GetLocations(); |
| 243 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 244 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 245 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 246 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 247 | __ Bind(GetEntryLabel()); |
| 248 | SaveLiveRegisters(codegen, locations); |
| 249 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 250 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 251 | mips64_codegen->InvokeRuntime(kQuickResolveString, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 252 | instruction_, |
| 253 | instruction_->GetDexPc(), |
| 254 | this); |
| 255 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 256 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 257 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 258 | mips64_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 259 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 260 | type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 261 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 262 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 263 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 266 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; } |
| 267 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 268 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 269 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64); |
| 270 | }; |
| 271 | |
| 272 | class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 273 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 274 | explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 275 | |
| 276 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 277 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 278 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 279 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 280 | // Live registers will be restored in the catch block if caught. |
| 281 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 282 | } |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 283 | mips64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 284 | instruction_, |
| 285 | instruction_->GetDexPc(), |
| 286 | this); |
| 287 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 288 | } |
| 289 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 290 | bool IsFatal() const OVERRIDE { return true; } |
| 291 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 292 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; } |
| 293 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 294 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 295 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64); |
| 296 | }; |
| 297 | |
| 298 | class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 299 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 300 | SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 301 | : SlowPathCodeMIPS64(instruction), successor_(successor) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 302 | |
| 303 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 304 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 305 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 306 | __ Bind(GetEntryLabel()); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 307 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 308 | mips64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 309 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 310 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 311 | if (successor_ == nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 312 | __ Bc(GetReturnLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 313 | } else { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 314 | __ Bc(mips64_codegen->GetLabelOf(successor_)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 318 | Mips64Label* GetReturnLabel() { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 319 | DCHECK(successor_ == nullptr); |
| 320 | return &return_label_; |
| 321 | } |
| 322 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 323 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; } |
| 324 | |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 325 | HBasicBlock* GetSuccessor() const { |
| 326 | return successor_; |
| 327 | } |
| 328 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 329 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 330 | // If not null, the block to branch to after the suspend check. |
| 331 | HBasicBlock* const successor_; |
| 332 | |
| 333 | // If `successor_` is null, the label to branch to after the suspend check. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 334 | Mips64Label return_label_; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 335 | |
| 336 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64); |
| 337 | }; |
| 338 | |
| 339 | class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 340 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 341 | explicit TypeCheckSlowPathMIPS64(HInstruction* instruction, bool is_fatal) |
| 342 | : SlowPathCodeMIPS64(instruction), is_fatal_(is_fatal) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 343 | |
| 344 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 345 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 346 | |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 347 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 348 | DCHECK(instruction_->IsCheckCast() |
| 349 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 350 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 351 | |
| 352 | __ Bind(GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 353 | if (!is_fatal_) { |
| 354 | SaveLiveRegisters(codegen, locations); |
| 355 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 356 | |
| 357 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 358 | // move resolver. |
| 359 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 360 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 361 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 362 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 363 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 364 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 365 | DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 366 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 367 | mips64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 368 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 369 | DataType::Type ret_type = instruction_->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 370 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 371 | mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 372 | } else { |
| 373 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 374 | mips64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 375 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 378 | if (!is_fatal_) { |
| 379 | RestoreLiveRegisters(codegen, locations); |
| 380 | __ Bc(GetExitLabel()); |
| 381 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 384 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; } |
| 385 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 386 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 387 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 388 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 389 | const bool is_fatal_; |
| 390 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 391 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64); |
| 392 | }; |
| 393 | |
| 394 | class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 395 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 396 | explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 397 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 398 | |
| 399 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 400 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 401 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 402 | LocationSummary* locations = instruction_->GetLocations(); |
| 403 | SaveLiveRegisters(codegen, locations); |
| 404 | InvokeRuntimeCallingConvention calling_convention; |
| 405 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 406 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 407 | mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 408 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 411 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; } |
| 412 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 413 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 414 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64); |
| 415 | }; |
| 416 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 417 | class ArraySetSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 418 | public: |
| 419 | explicit ArraySetSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {} |
| 420 | |
| 421 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 422 | LocationSummary* locations = instruction_->GetLocations(); |
| 423 | __ Bind(GetEntryLabel()); |
| 424 | SaveLiveRegisters(codegen, locations); |
| 425 | |
| 426 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 427 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 428 | parallel_move.AddMove( |
| 429 | locations->InAt(0), |
| 430 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 431 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 432 | nullptr); |
| 433 | parallel_move.AddMove( |
| 434 | locations->InAt(1), |
| 435 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 436 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 437 | nullptr); |
| 438 | parallel_move.AddMove( |
| 439 | locations->InAt(2), |
| 440 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 441 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 442 | nullptr); |
| 443 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 444 | |
| 445 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 446 | mips64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 447 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 448 | RestoreLiveRegisters(codegen, locations); |
| 449 | __ Bc(GetExitLabel()); |
| 450 | } |
| 451 | |
| 452 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS64"; } |
| 453 | |
| 454 | private: |
| 455 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS64); |
| 456 | }; |
| 457 | |
| 458 | // Slow path marking an object reference `ref` during a read |
| 459 | // barrier. The field `obj.field` in the object `obj` holding this |
| 460 | // reference does not get updated by this slow path after marking (see |
| 461 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 below for that). |
| 462 | // |
| 463 | // This means that after the execution of this slow path, `ref` will |
| 464 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 465 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 466 | // probably still be a from-space reference (unless it gets updated by |
| 467 | // another thread, or if another thread installed another object |
| 468 | // reference (different from `ref`) in `obj.field`). |
| 469 | // |
| 470 | // If `entrypoint` is a valid location it is assumed to already be |
| 471 | // holding the entrypoint. The case where the entrypoint is passed in |
| 472 | // is for the GcRoot read barrier. |
| 473 | class ReadBarrierMarkSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 474 | public: |
| 475 | ReadBarrierMarkSlowPathMIPS64(HInstruction* instruction, |
| 476 | Location ref, |
| 477 | Location entrypoint = Location::NoLocation()) |
| 478 | : SlowPathCodeMIPS64(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 479 | DCHECK(kEmitCompilerReadBarrier); |
| 480 | } |
| 481 | |
| 482 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 483 | |
| 484 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 485 | LocationSummary* locations = instruction_->GetLocations(); |
| 486 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 487 | DCHECK(locations->CanCall()); |
| 488 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 489 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 490 | instruction_->IsStaticFieldGet() || |
| 491 | instruction_->IsArrayGet() || |
| 492 | instruction_->IsArraySet() || |
| 493 | instruction_->IsLoadClass() || |
| 494 | instruction_->IsLoadString() || |
| 495 | instruction_->IsInstanceOf() || |
| 496 | instruction_->IsCheckCast() || |
| 497 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 498 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 499 | << "Unexpected instruction in read barrier marking slow path: " |
| 500 | << instruction_->DebugName(); |
| 501 | |
| 502 | __ Bind(GetEntryLabel()); |
| 503 | // No need to save live registers; it's taken care of by the |
| 504 | // entrypoint. Also, there is no need to update the stack mask, |
| 505 | // as this runtime call will not trigger a garbage collection. |
| 506 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 507 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 508 | (S2 <= ref_reg && ref_reg <= S7) || |
| 509 | (ref_reg == S8)) << ref_reg; |
| 510 | // "Compact" slow path, saving two moves. |
| 511 | // |
| 512 | // Instead of using the standard runtime calling convention (input |
| 513 | // and output in A0 and V0 respectively): |
| 514 | // |
| 515 | // A0 <- ref |
| 516 | // V0 <- ReadBarrierMark(A0) |
| 517 | // ref <- V0 |
| 518 | // |
| 519 | // we just use rX (the register containing `ref`) as input and output |
| 520 | // of a dedicated entrypoint: |
| 521 | // |
| 522 | // rX <- ReadBarrierMarkRegX(rX) |
| 523 | // |
| 524 | if (entrypoint_.IsValid()) { |
| 525 | mips64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 526 | DCHECK_EQ(entrypoint_.AsRegister<GpuRegister>(), T9); |
| 527 | __ Jalr(entrypoint_.AsRegister<GpuRegister>()); |
| 528 | __ Nop(); |
| 529 | } else { |
| 530 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 531 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 532 | // This runtime call does not require a stack map. |
| 533 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 534 | instruction_, |
| 535 | this); |
| 536 | } |
| 537 | __ Bc(GetExitLabel()); |
| 538 | } |
| 539 | |
| 540 | private: |
| 541 | // The location (register) of the marked object reference. |
| 542 | const Location ref_; |
| 543 | |
| 544 | // The location of the entrypoint if already loaded. |
| 545 | const Location entrypoint_; |
| 546 | |
| 547 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS64); |
| 548 | }; |
| 549 | |
| 550 | // Slow path marking an object reference `ref` during a read barrier, |
| 551 | // and if needed, atomically updating the field `obj.field` in the |
| 552 | // object `obj` holding this reference after marking (contrary to |
| 553 | // ReadBarrierMarkSlowPathMIPS64 above, which never tries to update |
| 554 | // `obj.field`). |
| 555 | // |
| 556 | // This means that after the execution of this slow path, both `ref` |
| 557 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 558 | // hold the same to-space reference (unless another thread installed |
| 559 | // another object reference (different from `ref`) in `obj.field`). |
| 560 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 561 | public: |
| 562 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(HInstruction* instruction, |
| 563 | Location ref, |
| 564 | GpuRegister obj, |
| 565 | Location field_offset, |
| 566 | GpuRegister temp1) |
| 567 | : SlowPathCodeMIPS64(instruction), |
| 568 | ref_(ref), |
| 569 | obj_(obj), |
| 570 | field_offset_(field_offset), |
| 571 | temp1_(temp1) { |
| 572 | DCHECK(kEmitCompilerReadBarrier); |
| 573 | } |
| 574 | |
| 575 | const char* GetDescription() const OVERRIDE { |
| 576 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS64"; |
| 577 | } |
| 578 | |
| 579 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 580 | LocationSummary* locations = instruction_->GetLocations(); |
| 581 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 582 | DCHECK(locations->CanCall()); |
| 583 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 584 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 585 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 586 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 587 | << instruction_->DebugName(); |
| 588 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 589 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 590 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
| 591 | |
| 592 | __ Bind(GetEntryLabel()); |
| 593 | |
| 594 | // Save the old reference. |
| 595 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 596 | // are used by the code that follows, but we need the old reference after |
| 597 | // the call to the ReadBarrierMarkRegX entry point. |
| 598 | DCHECK_NE(temp1_, AT); |
| 599 | DCHECK_NE(temp1_, TMP); |
| 600 | __ Move(temp1_, ref_reg); |
| 601 | |
| 602 | // No need to save live registers; it's taken care of by the |
| 603 | // entrypoint. Also, there is no need to update the stack mask, |
| 604 | // as this runtime call will not trigger a garbage collection. |
| 605 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 606 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 607 | (S2 <= ref_reg && ref_reg <= S7) || |
| 608 | (ref_reg == S8)) << ref_reg; |
| 609 | // "Compact" slow path, saving two moves. |
| 610 | // |
| 611 | // Instead of using the standard runtime calling convention (input |
| 612 | // and output in A0 and V0 respectively): |
| 613 | // |
| 614 | // A0 <- ref |
| 615 | // V0 <- ReadBarrierMark(A0) |
| 616 | // ref <- V0 |
| 617 | // |
| 618 | // we just use rX (the register containing `ref`) as input and output |
| 619 | // of a dedicated entrypoint: |
| 620 | // |
| 621 | // rX <- ReadBarrierMarkRegX(rX) |
| 622 | // |
| 623 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 624 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 625 | // This runtime call does not require a stack map. |
| 626 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 627 | instruction_, |
| 628 | this); |
| 629 | |
| 630 | // If the new reference is different from the old reference, |
| 631 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 632 | // |
| 633 | // Note that this field could also hold a different object, if |
| 634 | // another thread had concurrently changed it. In that case, the |
| 635 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 636 | // field as-is. |
| 637 | Mips64Label done; |
| 638 | __ Beqc(temp1_, ref_reg, &done); |
| 639 | |
| 640 | // Update the the holder's field atomically. This may fail if |
| 641 | // mutator updates before us, but it's OK. This is achieved |
| 642 | // using a strong compare-and-set (CAS) operation with relaxed |
| 643 | // memory synchronization ordering, where the expected value is |
| 644 | // the old reference and the desired value is the new reference. |
| 645 | |
| 646 | // Convenience aliases. |
| 647 | GpuRegister base = obj_; |
| 648 | GpuRegister offset = field_offset_.AsRegister<GpuRegister>(); |
| 649 | GpuRegister expected = temp1_; |
| 650 | GpuRegister value = ref_reg; |
| 651 | GpuRegister tmp_ptr = TMP; // Pointer to actual memory. |
| 652 | GpuRegister tmp = AT; // Value in memory. |
| 653 | |
| 654 | __ Daddu(tmp_ptr, base, offset); |
| 655 | |
| 656 | if (kPoisonHeapReferences) { |
| 657 | __ PoisonHeapReference(expected); |
| 658 | // Do not poison `value` if it is the same register as |
| 659 | // `expected`, which has just been poisoned. |
| 660 | if (value != expected) { |
| 661 | __ PoisonHeapReference(value); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | // do { |
| 666 | // tmp = [r_ptr] - expected; |
| 667 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 668 | |
| 669 | Mips64Label loop_head, exit_loop; |
| 670 | __ Bind(&loop_head); |
| 671 | __ Ll(tmp, tmp_ptr); |
| 672 | // The LL instruction sign-extends the 32-bit value, but |
| 673 | // 32-bit references must be zero-extended. Zero-extend `tmp`. |
| 674 | __ Dext(tmp, tmp, 0, 32); |
| 675 | __ Bnec(tmp, expected, &exit_loop); |
| 676 | __ Move(tmp, value); |
| 677 | __ Sc(tmp, tmp_ptr); |
| 678 | __ Beqzc(tmp, &loop_head); |
| 679 | __ Bind(&exit_loop); |
| 680 | |
| 681 | if (kPoisonHeapReferences) { |
| 682 | __ UnpoisonHeapReference(expected); |
| 683 | // Do not unpoison `value` if it is the same register as |
| 684 | // `expected`, which has just been unpoisoned. |
| 685 | if (value != expected) { |
| 686 | __ UnpoisonHeapReference(value); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | __ Bind(&done); |
| 691 | __ Bc(GetExitLabel()); |
| 692 | } |
| 693 | |
| 694 | private: |
| 695 | // The location (register) of the marked object reference. |
| 696 | const Location ref_; |
| 697 | // The register containing the object holding the marked object reference field. |
| 698 | const GpuRegister obj_; |
| 699 | // The location of the offset of the marked reference field within `obj_`. |
| 700 | Location field_offset_; |
| 701 | |
| 702 | const GpuRegister temp1_; |
| 703 | |
| 704 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS64); |
| 705 | }; |
| 706 | |
| 707 | // Slow path generating a read barrier for a heap reference. |
| 708 | class ReadBarrierForHeapReferenceSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 709 | public: |
| 710 | ReadBarrierForHeapReferenceSlowPathMIPS64(HInstruction* instruction, |
| 711 | Location out, |
| 712 | Location ref, |
| 713 | Location obj, |
| 714 | uint32_t offset, |
| 715 | Location index) |
| 716 | : SlowPathCodeMIPS64(instruction), |
| 717 | out_(out), |
| 718 | ref_(ref), |
| 719 | obj_(obj), |
| 720 | offset_(offset), |
| 721 | index_(index) { |
| 722 | DCHECK(kEmitCompilerReadBarrier); |
| 723 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 724 | // has been overwritten by (or after) the heap object reference load |
| 725 | // to be instrumented, e.g.: |
| 726 | // |
| 727 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 728 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 729 | // |
| 730 | // In that case, we have lost the information about the original |
| 731 | // object, and the emitted read barrier cannot work properly. |
| 732 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 733 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 734 | } |
| 735 | |
| 736 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 737 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 738 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 739 | DataType::Type type = DataType::Type::kReference; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 740 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 741 | DCHECK(locations->CanCall()); |
| 742 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 743 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 744 | instruction_->IsStaticFieldGet() || |
| 745 | instruction_->IsArrayGet() || |
| 746 | instruction_->IsInstanceOf() || |
| 747 | instruction_->IsCheckCast() || |
| 748 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 749 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 750 | << instruction_->DebugName(); |
| 751 | |
| 752 | __ Bind(GetEntryLabel()); |
| 753 | SaveLiveRegisters(codegen, locations); |
| 754 | |
| 755 | // We may have to change the index's value, but as `index_` is a |
| 756 | // constant member (like other "inputs" of this slow path), |
| 757 | // introduce a copy of it, `index`. |
| 758 | Location index = index_; |
| 759 | if (index_.IsValid()) { |
| 760 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 761 | if (instruction_->IsArrayGet()) { |
| 762 | // Compute the actual memory offset and store it in `index`. |
| 763 | GpuRegister index_reg = index_.AsRegister<GpuRegister>(); |
| 764 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 765 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 766 | // We are about to change the value of `index_reg` (see the |
| 767 | // calls to art::mips64::Mips64Assembler::Sll and |
| 768 | // art::mips64::MipsAssembler::Addiu32 below), but it has |
| 769 | // not been saved by the previous call to |
| 770 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 771 | // callee-save register -- |
| 772 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 773 | // callee-save registers, as it has been designed with the |
| 774 | // assumption that callee-save registers are supposed to be |
| 775 | // handled by the called function. So, as a callee-save |
| 776 | // register, `index_reg` _would_ eventually be saved onto |
| 777 | // the stack, but it would be too late: we would have |
| 778 | // changed its value earlier. Therefore, we manually save |
| 779 | // it here into another freely available register, |
| 780 | // `free_reg`, chosen of course among the caller-save |
| 781 | // registers (as a callee-save `free_reg` register would |
| 782 | // exhibit the same problem). |
| 783 | // |
| 784 | // Note we could have requested a temporary register from |
| 785 | // the register allocator instead; but we prefer not to, as |
| 786 | // this is a slow path, and we know we can find a |
| 787 | // caller-save register that is available. |
| 788 | GpuRegister free_reg = FindAvailableCallerSaveRegister(codegen); |
| 789 | __ Move(free_reg, index_reg); |
| 790 | index_reg = free_reg; |
| 791 | index = Location::RegisterLocation(index_reg); |
| 792 | } else { |
| 793 | // The initial register stored in `index_` has already been |
| 794 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 795 | // (as it is not a callee-save register), so we can freely |
| 796 | // use it. |
| 797 | } |
| 798 | // Shifting the index value contained in `index_reg` by the scale |
| 799 | // factor (2) cannot overflow in practice, as the runtime is |
| 800 | // unable to allocate object arrays with a size larger than |
| 801 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 802 | __ Sll(index_reg, index_reg, TIMES_4); |
| 803 | static_assert( |
| 804 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 805 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 806 | __ Addiu32(index_reg, index_reg, offset_); |
| 807 | } else { |
| 808 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 809 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 810 | // (as in the case of ArrayGet), as it is actually an offset |
| 811 | // to an object field within an object. |
| 812 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 813 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 814 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 815 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 816 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 817 | DCHECK_EQ(offset_, 0U); |
| 818 | DCHECK(index_.IsRegister()); |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | // We're moving two or three locations to locations that could |
| 823 | // overlap, so we need a parallel move resolver. |
| 824 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 825 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 826 | parallel_move.AddMove(ref_, |
| 827 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 828 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 829 | nullptr); |
| 830 | parallel_move.AddMove(obj_, |
| 831 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 832 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 833 | nullptr); |
| 834 | if (index.IsValid()) { |
| 835 | parallel_move.AddMove(index, |
| 836 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 837 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 838 | nullptr); |
| 839 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 840 | } else { |
| 841 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 842 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 843 | } |
| 844 | mips64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 845 | instruction_, |
| 846 | instruction_->GetDexPc(), |
| 847 | this); |
| 848 | CheckEntrypointTypes< |
| 849 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 850 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 851 | |
| 852 | RestoreLiveRegisters(codegen, locations); |
| 853 | __ Bc(GetExitLabel()); |
| 854 | } |
| 855 | |
| 856 | const char* GetDescription() const OVERRIDE { |
| 857 | return "ReadBarrierForHeapReferenceSlowPathMIPS64"; |
| 858 | } |
| 859 | |
| 860 | private: |
| 861 | GpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 862 | size_t ref = static_cast<int>(ref_.AsRegister<GpuRegister>()); |
| 863 | size_t obj = static_cast<int>(obj_.AsRegister<GpuRegister>()); |
| 864 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 865 | if (i != ref && |
| 866 | i != obj && |
| 867 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 868 | !codegen->IsBlockedCoreRegister(i)) { |
| 869 | return static_cast<GpuRegister>(i); |
| 870 | } |
| 871 | } |
| 872 | // We shall never fail to find a free caller-save register, as |
| 873 | // there are more than two core caller-save registers on MIPS64 |
| 874 | // (meaning it is possible to find one which is different from |
| 875 | // `ref` and `obj`). |
| 876 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 877 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 878 | UNREACHABLE(); |
| 879 | } |
| 880 | |
| 881 | const Location out_; |
| 882 | const Location ref_; |
| 883 | const Location obj_; |
| 884 | const uint32_t offset_; |
| 885 | // An additional location containing an index to an array. |
| 886 | // Only used for HArrayGet and the UnsafeGetObject & |
| 887 | // UnsafeGetObjectVolatile intrinsics. |
| 888 | const Location index_; |
| 889 | |
| 890 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS64); |
| 891 | }; |
| 892 | |
| 893 | // Slow path generating a read barrier for a GC root. |
| 894 | class ReadBarrierForRootSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 895 | public: |
| 896 | ReadBarrierForRootSlowPathMIPS64(HInstruction* instruction, Location out, Location root) |
| 897 | : SlowPathCodeMIPS64(instruction), out_(out), root_(root) { |
| 898 | DCHECK(kEmitCompilerReadBarrier); |
| 899 | } |
| 900 | |
| 901 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 902 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 903 | DataType::Type type = DataType::Type::kReference; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 904 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 905 | DCHECK(locations->CanCall()); |
| 906 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 907 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 908 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 909 | << instruction_->DebugName(); |
| 910 | |
| 911 | __ Bind(GetEntryLabel()); |
| 912 | SaveLiveRegisters(codegen, locations); |
| 913 | |
| 914 | InvokeRuntimeCallingConvention calling_convention; |
| 915 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 916 | mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 917 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 918 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 919 | mips64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 920 | instruction_, |
| 921 | instruction_->GetDexPc(), |
| 922 | this); |
| 923 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 924 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 925 | |
| 926 | RestoreLiveRegisters(codegen, locations); |
| 927 | __ Bc(GetExitLabel()); |
| 928 | } |
| 929 | |
| 930 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS64"; } |
| 931 | |
| 932 | private: |
| 933 | const Location out_; |
| 934 | const Location root_; |
| 935 | |
| 936 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS64); |
| 937 | }; |
| 938 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 939 | CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph, |
| 940 | const Mips64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 941 | const CompilerOptions& compiler_options, |
| 942 | OptimizingCompilerStats* stats) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 943 | : CodeGenerator(graph, |
| 944 | kNumberOfGpuRegisters, |
| 945 | kNumberOfFpuRegisters, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 946 | /* number_of_register_pairs */ 0, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 947 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 948 | arraysize(kCoreCalleeSaves)), |
| 949 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 950 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 951 | compiler_options, |
| 952 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 953 | block_labels_(nullptr), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 954 | location_builder_(graph, this), |
| 955 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 956 | move_resolver_(graph->GetAllocator(), this), |
| 957 | assembler_(graph->GetAllocator(), &isa_features), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 958 | isa_features_(isa_features), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 959 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 960 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 961 | uint64_literals_(std::less<uint64_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 962 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 963 | pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 964 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 965 | pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 966 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 967 | pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 968 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 969 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 970 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 971 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 972 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 973 | // Save RA (containing the return address) to mimic Quick. |
| 974 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 975 | } |
| 976 | |
| 977 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 978 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 979 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 980 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 981 | |
| 982 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 983 | // Ensure that we fix up branches. |
| 984 | __ FinalizeCode(); |
| 985 | |
| 986 | // Adjust native pc offsets in stack maps. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 987 | StackMapStream* stack_map_stream = GetStackMapStream(); |
| 988 | 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] | 989 | uint32_t old_position = |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 990 | stack_map_stream->GetStackMap(i).native_pc_code_offset.Uint32Value(InstructionSet::kMips64); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 991 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 992 | DCHECK_GE(new_position, old_position); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 993 | stack_map_stream->SetStackMapNativePcOffset(i, new_position); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | // Adjust pc offsets for the disassembly information. |
| 997 | if (disasm_info_ != nullptr) { |
| 998 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 999 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1000 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1001 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1002 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1003 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1004 | } |
| 1005 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1006 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1007 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1008 | } |
| 1009 | } |
| 1010 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1011 | CodeGenerator::Finalize(allocator); |
| 1012 | } |
| 1013 | |
| 1014 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { |
| 1015 | return codegen_->GetAssembler(); |
| 1016 | } |
| 1017 | |
| 1018 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1019 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1020 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1021 | } |
| 1022 | |
| 1023 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1024 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1025 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1026 | } |
| 1027 | |
| 1028 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { |
| 1029 | // Pop reg |
| 1030 | __ Ld(GpuRegister(reg), SP, 0); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1031 | __ DecreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { |
| 1035 | // Push reg |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1036 | __ IncreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1037 | __ Sd(GpuRegister(reg), SP, 0); |
| 1038 | } |
| 1039 | |
| 1040 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { |
| 1041 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; |
| 1042 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; |
| 1043 | // Allocate a scratch register other than TMP, if available. |
| 1044 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1045 | // automatically unspilled when the scratch scope object is destroyed). |
| 1046 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1047 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1048 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1049 | __ LoadFromOffset(load_type, |
| 1050 | GpuRegister(ensure_scratch.GetRegister()), |
| 1051 | SP, |
| 1052 | index1 + stack_offset); |
| 1053 | __ LoadFromOffset(load_type, |
| 1054 | TMP, |
| 1055 | SP, |
| 1056 | index2 + stack_offset); |
| 1057 | __ StoreToOffset(store_type, |
| 1058 | GpuRegister(ensure_scratch.GetRegister()), |
| 1059 | SP, |
| 1060 | index2 + stack_offset); |
| 1061 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); |
| 1062 | } |
| 1063 | |
| 1064 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 1065 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 1066 | } |
| 1067 | |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1068 | static dwarf::Reg DWARFReg(FpuRegister reg) { |
| 1069 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); |
| 1070 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1071 | |
| 1072 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 1073 | __ Bind(&frame_entry_label_); |
| 1074 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1075 | bool do_overflow_check = |
| 1076 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips64) || !IsLeafMethod(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1077 | |
| 1078 | if (do_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1079 | __ LoadFromOffset( |
| 1080 | kLoadWord, |
| 1081 | ZERO, |
| 1082 | SP, |
| 1083 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips64))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1084 | RecordPcInfo(nullptr, 0); |
| 1085 | } |
| 1086 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1087 | if (HasEmptyFrame()) { |
| 1088 | return; |
| 1089 | } |
| 1090 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1091 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1092 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips64)) { |
| 1093 | LOG(FATAL) << "Stack frame larger than " |
| 1094 | << GetStackOverflowReservedBytes(InstructionSet::kMips64) << " bytes"; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1095 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1096 | |
| 1097 | // Spill callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1098 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1099 | uint32_t ofs = GetFrameSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1100 | __ IncreaseFrameSize(ofs); |
| 1101 | |
| 1102 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1103 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1104 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1105 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1106 | __ StoreToOffset(kStoreDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1107 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1112 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1113 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1114 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1115 | __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs); |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1116 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1120 | // Save the current method if we need it. Note that we do not |
| 1121 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1122 | // in the SSA graph. |
| 1123 | if (RequiresCurrentMethod()) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1124 | __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1125 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1126 | |
| 1127 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1128 | // Initialize should_deoptimize flag to 0. |
| 1129 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1130 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 1134 | __ cfi().RememberState(); |
| 1135 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1136 | if (!HasEmptyFrame()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1137 | // Restore callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1138 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1139 | // For better instruction scheduling restore RA before other registers. |
| 1140 | uint32_t ofs = GetFrameSize(); |
| 1141 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1142 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1143 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1144 | ofs -= kMips64DoublewordSize; |
| 1145 | __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1146 | __ cfi().Restore(DWARFReg(reg)); |
| 1147 | } |
| 1148 | } |
| 1149 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1150 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1151 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1152 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 1153 | ofs -= kMips64DoublewordSize; |
| 1154 | __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs); |
| 1155 | __ cfi().Restore(DWARFReg(reg)); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | __ DecreaseFrameSize(GetFrameSize()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1162 | __ Jic(RA, 0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1163 | |
| 1164 | __ cfi().RestoreState(); |
| 1165 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1166 | } |
| 1167 | |
| 1168 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 1169 | __ Bind(GetLabelOf(block)); |
| 1170 | } |
| 1171 | |
| 1172 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 1173 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1174 | DataType::Type dst_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1175 | if (source.Equals(destination)) { |
| 1176 | return; |
| 1177 | } |
| 1178 | |
| 1179 | // A valid move can always be inferred from the destination and source |
| 1180 | // locations. When moving from and to a register, the argument type can be |
| 1181 | // used to generate 32bit instead of 64bit moves. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1182 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1183 | DCHECK_EQ(unspecified_type, false); |
| 1184 | |
| 1185 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1186 | if (unspecified_type) { |
| 1187 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1188 | if (source.IsStackSlot() || |
| 1189 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1190 | || src_cst->IsFloatConstant() |
| 1191 | || src_cst->IsNullConstant()))) { |
| 1192 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1193 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1194 | } else { |
| 1195 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1196 | // type is appropriate. Else the source is a register, and since the |
| 1197 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1198 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1199 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1200 | } |
| 1201 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1202 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1203 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1204 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1205 | // Move to GPR/FPR from stack |
| 1206 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1207 | if (DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1208 | __ LoadFpuFromOffset(load_type, |
| 1209 | destination.AsFpuRegister<FpuRegister>(), |
| 1210 | SP, |
| 1211 | source.GetStackIndex()); |
| 1212 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1213 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1214 | __ LoadFromOffset(load_type, |
| 1215 | destination.AsRegister<GpuRegister>(), |
| 1216 | SP, |
| 1217 | source.GetStackIndex()); |
| 1218 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1219 | } else if (source.IsSIMDStackSlot()) { |
| 1220 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1221 | destination.AsFpuRegister<FpuRegister>(), |
| 1222 | SP, |
| 1223 | source.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1224 | } else if (source.IsConstant()) { |
| 1225 | // Move to GPR/FPR from constant |
| 1226 | GpuRegister gpr = AT; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1227 | if (!DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1228 | gpr = destination.AsRegister<GpuRegister>(); |
| 1229 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1230 | if (dst_type == DataType::Type::kInt32 || dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1231 | int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1232 | if (DataType::IsFloatingPointType(dst_type) && value == 0) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1233 | gpr = ZERO; |
| 1234 | } else { |
| 1235 | __ LoadConst32(gpr, value); |
| 1236 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1237 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1238 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1239 | if (DataType::IsFloatingPointType(dst_type) && value == 0) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1240 | gpr = ZERO; |
| 1241 | } else { |
| 1242 | __ LoadConst64(gpr, value); |
| 1243 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1244 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1245 | if (dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1246 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1247 | } else if (dst_type == DataType::Type::kFloat64) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1248 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 1249 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1250 | } else if (source.IsRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1251 | if (destination.IsRegister()) { |
| 1252 | // Move to GPR from GPR |
| 1253 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 1254 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1255 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1256 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1257 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1258 | } else { |
| 1259 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1260 | } |
| 1261 | } |
| 1262 | } else if (source.IsFpuRegister()) { |
| 1263 | if (destination.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1264 | if (GetGraph()->HasSIMD()) { |
| 1265 | __ MoveV(VectorRegisterFrom(destination), |
| 1266 | VectorRegisterFrom(source)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1267 | } else { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1268 | // Move to FPR from FPR |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1269 | if (dst_type == DataType::Type::kFloat32) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1270 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1271 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1272 | DCHECK_EQ(dst_type, DataType::Type::kFloat64); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1273 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1274 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1275 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1276 | } else { |
| 1277 | DCHECK(destination.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1278 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1279 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1280 | } else { |
| 1281 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1282 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1283 | } |
| 1284 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1285 | } else if (destination.IsSIMDStackSlot()) { |
| 1286 | if (source.IsFpuRegister()) { |
| 1287 | __ StoreFpuToOffset(kStoreQuadword, |
| 1288 | source.AsFpuRegister<FpuRegister>(), |
| 1289 | SP, |
| 1290 | destination.GetStackIndex()); |
| 1291 | } else { |
| 1292 | DCHECK(source.IsSIMDStackSlot()); |
| 1293 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1294 | FTMP, |
| 1295 | SP, |
| 1296 | source.GetStackIndex()); |
| 1297 | __ StoreFpuToOffset(kStoreQuadword, |
| 1298 | FTMP, |
| 1299 | SP, |
| 1300 | destination.GetStackIndex()); |
| 1301 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1302 | } else { // The destination is not a register. It must be a stack slot. |
| 1303 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1304 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1305 | if (unspecified_type) { |
| 1306 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1307 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1308 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1309 | dst_type = |
| 1310 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1311 | } |
| 1312 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1313 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1314 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1315 | // Move to stack from GPR/FPR |
| 1316 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1317 | if (source.IsRegister()) { |
| 1318 | __ StoreToOffset(store_type, |
| 1319 | source.AsRegister<GpuRegister>(), |
| 1320 | SP, |
| 1321 | destination.GetStackIndex()); |
| 1322 | } else { |
| 1323 | __ StoreFpuToOffset(store_type, |
| 1324 | source.AsFpuRegister<FpuRegister>(), |
| 1325 | SP, |
| 1326 | destination.GetStackIndex()); |
| 1327 | } |
| 1328 | } else if (source.IsConstant()) { |
| 1329 | // Move to stack from constant |
| 1330 | HConstant* src_cst = source.GetConstant(); |
| 1331 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1332 | GpuRegister gpr = ZERO; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1333 | if (destination.IsStackSlot()) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1334 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); |
| 1335 | if (value != 0) { |
| 1336 | gpr = TMP; |
| 1337 | __ LoadConst32(gpr, value); |
| 1338 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1339 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1340 | DCHECK(destination.IsDoubleStackSlot()); |
| 1341 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); |
| 1342 | if (value != 0) { |
| 1343 | gpr = TMP; |
| 1344 | __ LoadConst64(gpr, value); |
| 1345 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1346 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1347 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1348 | } else { |
| 1349 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 1350 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 1351 | // Move to stack from stack |
| 1352 | if (destination.IsStackSlot()) { |
| 1353 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1354 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 1355 | } else { |
| 1356 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 1357 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | } |
| 1362 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1363 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1364 | DCHECK(!loc1.IsConstant()); |
| 1365 | DCHECK(!loc2.IsConstant()); |
| 1366 | |
| 1367 | if (loc1.Equals(loc2)) { |
| 1368 | return; |
| 1369 | } |
| 1370 | |
| 1371 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 1372 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
| 1373 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 1374 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 1375 | |
| 1376 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 1377 | // Swap 2 GPRs |
| 1378 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 1379 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 1380 | __ Move(TMP, r2); |
| 1381 | __ Move(r2, r1); |
| 1382 | __ Move(r1, TMP); |
| 1383 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 1384 | // Swap 2 FPRs |
| 1385 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 1386 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1387 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1388 | __ MovS(FTMP, r1); |
| 1389 | __ MovS(r1, r2); |
| 1390 | __ MovS(r2, FTMP); |
| 1391 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1392 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1393 | __ MovD(FTMP, r1); |
| 1394 | __ MovD(r1, r2); |
| 1395 | __ MovD(r2, FTMP); |
| 1396 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1397 | } else if (is_slot1 != is_slot2) { |
| 1398 | // Swap GPR/FPR and stack slot |
| 1399 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 1400 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 1401 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 1402 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1403 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1404 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 1405 | if (reg_loc.IsFpuRegister()) { |
| 1406 | __ StoreFpuToOffset(store_type, |
| 1407 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 1408 | SP, |
| 1409 | mem_loc.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1410 | if (mem_loc.IsStackSlot()) { |
| 1411 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1412 | } else { |
| 1413 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 1414 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1415 | } |
| 1416 | } else { |
| 1417 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 1418 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 1419 | } |
| 1420 | } else if (is_slot1 && is_slot2) { |
| 1421 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 1422 | loc2.GetStackIndex(), |
| 1423 | loc1.IsDoubleStackSlot()); |
| 1424 | } else { |
| 1425 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 1426 | } |
| 1427 | } |
| 1428 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1429 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 1430 | DCHECK(location.IsRegister()); |
| 1431 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 1432 | } |
| 1433 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1434 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1435 | if (location.IsRegister()) { |
| 1436 | locations->AddTemp(location); |
| 1437 | } else { |
| 1438 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1439 | } |
| 1440 | } |
| 1441 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1442 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, |
| 1443 | GpuRegister value, |
| 1444 | bool value_can_be_null) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1445 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1446 | GpuRegister card = AT; |
| 1447 | GpuRegister temp = TMP; |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1448 | if (value_can_be_null) { |
| 1449 | __ Beqzc(value, &done); |
| 1450 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1451 | __ LoadFromOffset(kLoadDoubleword, |
| 1452 | card, |
| 1453 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1454 | Thread::CardTableOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1455 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1456 | __ Daddu(temp, card, temp); |
| 1457 | __ Sb(card, temp, 0); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1458 | if (value_can_be_null) { |
| 1459 | __ Bind(&done); |
| 1460 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1463 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1464 | inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches( |
| 1465 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1466 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1467 | for (const PcRelativePatchInfo& info : infos) { |
| 1468 | const DexFile& dex_file = info.target_dex_file; |
| 1469 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1470 | DCHECK(info.label.IsBound()); |
| 1471 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
| 1472 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1473 | uint32_t pc_rel_offset = __ GetLabelLocation(&info_high.label); |
| 1474 | linker_patches->push_back(Factory(literal_offset, &dex_file, pc_rel_offset, offset_or_index)); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1478 | void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1479 | DCHECK(linker_patches->empty()); |
| 1480 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1481 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1482 | method_bss_entry_patches_.size() + |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1483 | pc_relative_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1484 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1485 | pc_relative_string_patches_.size() + |
| 1486 | string_bss_entry_patches_.size(); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1487 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1488 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1489 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1490 | pc_relative_method_patches_, linker_patches); |
| 1491 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1492 | pc_relative_type_patches_, linker_patches); |
| 1493 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 1494 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1495 | } else { |
| 1496 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1497 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 1498 | pc_relative_type_patches_, linker_patches); |
| 1499 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 1500 | pc_relative_string_patches_, linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1501 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1502 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1503 | method_bss_entry_patches_, linker_patches); |
| 1504 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1505 | type_bss_entry_patches_, linker_patches); |
| 1506 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1507 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1508 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1509 | } |
| 1510 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1511 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1512 | MethodReference target_method, |
| 1513 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1514 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1515 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1516 | info_high, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1517 | &pc_relative_method_patches_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1518 | } |
| 1519 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1520 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1521 | MethodReference target_method, |
| 1522 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1523 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1524 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1525 | info_high, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1526 | &method_bss_entry_patches_); |
| 1527 | } |
| 1528 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1529 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1530 | const DexFile& dex_file, |
| 1531 | dex::TypeIndex type_index, |
| 1532 | const PcRelativePatchInfo* info_high) { |
| 1533 | return NewPcRelativePatch(dex_file, type_index.index_, info_high, &pc_relative_type_patches_); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1536 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1537 | const DexFile& dex_file, |
| 1538 | dex::TypeIndex type_index, |
| 1539 | const PcRelativePatchInfo* info_high) { |
| 1540 | 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] | 1541 | } |
| 1542 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1543 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1544 | const DexFile& dex_file, |
| 1545 | dex::StringIndex string_index, |
| 1546 | const PcRelativePatchInfo* info_high) { |
| 1547 | 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] | 1548 | } |
| 1549 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1550 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewStringBssEntryPatch( |
| 1551 | const DexFile& dex_file, |
| 1552 | dex::StringIndex string_index, |
| 1553 | const PcRelativePatchInfo* info_high) { |
| 1554 | return NewPcRelativePatch(dex_file, string_index.index_, info_high, &string_bss_entry_patches_); |
| 1555 | } |
| 1556 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1557 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1558 | const DexFile& dex_file, |
| 1559 | uint32_t offset_or_index, |
| 1560 | const PcRelativePatchInfo* info_high, |
| 1561 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1562 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1563 | return &patches->back(); |
| 1564 | } |
| 1565 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1566 | Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1567 | return map->GetOrCreate( |
| 1568 | value, |
| 1569 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1570 | } |
| 1571 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1572 | Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) { |
| 1573 | return uint64_literals_.GetOrCreate( |
| 1574 | value, |
| 1575 | [this, value]() { return __ NewLiteral<uint64_t>(value); }); |
| 1576 | } |
| 1577 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1578 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1579 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1580 | } |
| 1581 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1582 | void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
| 1583 | GpuRegister out, |
| 1584 | PcRelativePatchInfo* info_low) { |
| 1585 | DCHECK(!info_high->patch_info_high); |
| 1586 | __ Bind(&info_high->label); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1587 | // Add the high half of a 32-bit offset to PC. |
| 1588 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1589 | // A following instruction will add the sign-extended low half of the 32-bit |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1590 | // offset to `out` (e.g. ld, jialc, daddiu). |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1591 | if (info_low != nullptr) { |
| 1592 | DCHECK_EQ(info_low->patch_info_high, info_high); |
| 1593 | __ Bind(&info_low->label); |
| 1594 | } |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1595 | } |
| 1596 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1597 | Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file, |
| 1598 | dex::StringIndex string_index, |
| 1599 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1600 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1601 | return jit_string_patches_.GetOrCreate( |
| 1602 | StringReference(&dex_file, string_index), |
| 1603 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1604 | } |
| 1605 | |
| 1606 | Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 1607 | dex::TypeIndex type_index, |
| 1608 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1609 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1610 | return jit_class_patches_.GetOrCreate( |
| 1611 | TypeReference(&dex_file, type_index), |
| 1612 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1613 | } |
| 1614 | |
| 1615 | void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code, |
| 1616 | const uint8_t* roots_data, |
| 1617 | const Literal* literal, |
| 1618 | uint64_t index_in_table) const { |
| 1619 | uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel()); |
| 1620 | uintptr_t address = |
| 1621 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1622 | reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address); |
| 1623 | } |
| 1624 | |
| 1625 | void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1626 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1627 | const StringReference& string_reference = entry.first; |
| 1628 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1629 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1630 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1631 | } |
| 1632 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1633 | const TypeReference& type_reference = entry.first; |
| 1634 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1635 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1636 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1637 | } |
| 1638 | } |
| 1639 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1640 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1641 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1642 | blocked_core_registers_[ZERO] = true; |
| 1643 | blocked_core_registers_[K0] = true; |
| 1644 | blocked_core_registers_[K1] = true; |
| 1645 | blocked_core_registers_[GP] = true; |
| 1646 | blocked_core_registers_[SP] = true; |
| 1647 | blocked_core_registers_[RA] = true; |
| 1648 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1649 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 1650 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1651 | blocked_core_registers_[AT] = true; |
| 1652 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1653 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1654 | blocked_fpu_registers_[FTMP] = true; |
| 1655 | |
| 1656 | // Reserve suspend and thread registers. |
| 1657 | blocked_core_registers_[S0] = true; |
| 1658 | blocked_core_registers_[TR] = true; |
| 1659 | |
| 1660 | // Reserve T9 for function calls |
| 1661 | blocked_core_registers_[T9] = true; |
| 1662 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 1663 | if (GetGraph()->IsDebuggable()) { |
| 1664 | // Stubs do not save callee-save floating point registers. If the graph |
| 1665 | // is debuggable, we need to deal with these registers differently. For |
| 1666 | // now, just block them. |
| 1667 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1668 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1669 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1673 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1674 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1675 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1679 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1680 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1684 | __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword, |
| 1685 | FpuRegister(reg_id), |
| 1686 | SP, |
| 1687 | stack_index); |
| 1688 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1692 | __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword, |
| 1693 | FpuRegister(reg_id), |
| 1694 | SP, |
| 1695 | stack_index); |
| 1696 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1700 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1704 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1707 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1708 | HInstruction* instruction, |
| 1709 | uint32_t dex_pc, |
| 1710 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1711 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1712 | GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1713 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1714 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1715 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1718 | void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1719 | HInstruction* instruction, |
| 1720 | SlowPathCode* slow_path) { |
| 1721 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1722 | GenerateInvokeRuntime(entry_point_offset); |
| 1723 | } |
| 1724 | |
| 1725 | void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| 1726 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 1727 | __ Jalr(T9); |
| 1728 | __ Nop(); |
| 1729 | } |
| 1730 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1731 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1732 | GpuRegister class_reg) { |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 1733 | __ LoadFromOffset(kLoadSignedByte, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1734 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1735 | __ Bltc(TMP, AT, slow_path->GetEntryLabel()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1736 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1737 | __ Sync(0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1738 | __ Bind(slow_path->GetExitLabel()); |
| 1739 | } |
| 1740 | |
| 1741 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1742 | __ Sync(0); // only stype 0 is supported |
| 1743 | } |
| 1744 | |
| 1745 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1746 | HBasicBlock* successor) { |
| 1747 | SuspendCheckSlowPathMIPS64* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1748 | down_cast<SuspendCheckSlowPathMIPS64*>(instruction->GetSlowPath()); |
| 1749 | |
| 1750 | if (slow_path == nullptr) { |
| 1751 | slow_path = |
| 1752 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1753 | instruction->SetSlowPath(slow_path); |
| 1754 | codegen_->AddSlowPath(slow_path); |
| 1755 | if (successor != nullptr) { |
| 1756 | DCHECK(successor->IsLoopHeader()); |
| 1757 | } |
| 1758 | } else { |
| 1759 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1760 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1761 | |
| 1762 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1763 | TMP, |
| 1764 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1765 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1766 | if (successor == nullptr) { |
| 1767 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1768 | __ Bind(slow_path->GetReturnLabel()); |
| 1769 | } else { |
| 1770 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1771 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1772 | // slow_path will return to GetLabelOf(successor). |
| 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1777 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1778 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1779 | assembler_(codegen->GetAssembler()), |
| 1780 | codegen_(codegen) {} |
| 1781 | |
| 1782 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1783 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1784 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1785 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1786 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1787 | case DataType::Type::kInt32: |
| 1788 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1789 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1790 | HInstruction* right = instruction->InputAt(1); |
| 1791 | bool can_use_imm = false; |
| 1792 | if (right->IsConstant()) { |
| 1793 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1794 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1795 | can_use_imm = IsUint<16>(imm); |
| 1796 | } else if (instruction->IsAdd()) { |
| 1797 | can_use_imm = IsInt<16>(imm); |
| 1798 | } else { |
| 1799 | DCHECK(instruction->IsSub()); |
| 1800 | can_use_imm = IsInt<16>(-imm); |
| 1801 | } |
| 1802 | } |
| 1803 | if (can_use_imm) |
| 1804 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1805 | else |
| 1806 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1807 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1808 | } |
| 1809 | break; |
| 1810 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1811 | case DataType::Type::kFloat32: |
| 1812 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1813 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1814 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1815 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1816 | break; |
| 1817 | |
| 1818 | default: |
| 1819 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1820 | } |
| 1821 | } |
| 1822 | |
| 1823 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1824 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1825 | LocationSummary* locations = instruction->GetLocations(); |
| 1826 | |
| 1827 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1828 | case DataType::Type::kInt32: |
| 1829 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1830 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1831 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1832 | Location rhs_location = locations->InAt(1); |
| 1833 | |
| 1834 | GpuRegister rhs_reg = ZERO; |
| 1835 | int64_t rhs_imm = 0; |
| 1836 | bool use_imm = rhs_location.IsConstant(); |
| 1837 | if (use_imm) { |
| 1838 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1839 | } else { |
| 1840 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1841 | } |
| 1842 | |
| 1843 | if (instruction->IsAnd()) { |
| 1844 | if (use_imm) |
| 1845 | __ Andi(dst, lhs, rhs_imm); |
| 1846 | else |
| 1847 | __ And(dst, lhs, rhs_reg); |
| 1848 | } else if (instruction->IsOr()) { |
| 1849 | if (use_imm) |
| 1850 | __ Ori(dst, lhs, rhs_imm); |
| 1851 | else |
| 1852 | __ Or(dst, lhs, rhs_reg); |
| 1853 | } else if (instruction->IsXor()) { |
| 1854 | if (use_imm) |
| 1855 | __ Xori(dst, lhs, rhs_imm); |
| 1856 | else |
| 1857 | __ Xor(dst, lhs, rhs_reg); |
| 1858 | } else if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1859 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1860 | if (use_imm) |
| 1861 | __ Addiu(dst, lhs, rhs_imm); |
| 1862 | else |
| 1863 | __ Addu(dst, lhs, rhs_reg); |
| 1864 | } else { |
| 1865 | if (use_imm) |
| 1866 | __ Daddiu(dst, lhs, rhs_imm); |
| 1867 | else |
| 1868 | __ Daddu(dst, lhs, rhs_reg); |
| 1869 | } |
| 1870 | } else { |
| 1871 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1872 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1873 | if (use_imm) |
| 1874 | __ Addiu(dst, lhs, -rhs_imm); |
| 1875 | else |
| 1876 | __ Subu(dst, lhs, rhs_reg); |
| 1877 | } else { |
| 1878 | if (use_imm) |
| 1879 | __ Daddiu(dst, lhs, -rhs_imm); |
| 1880 | else |
| 1881 | __ Dsubu(dst, lhs, rhs_reg); |
| 1882 | } |
| 1883 | } |
| 1884 | break; |
| 1885 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1886 | case DataType::Type::kFloat32: |
| 1887 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1888 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1889 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1890 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1891 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1892 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1893 | __ AddS(dst, lhs, rhs); |
| 1894 | else |
| 1895 | __ AddD(dst, lhs, rhs); |
| 1896 | } else if (instruction->IsSub()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1897 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1898 | __ SubS(dst, lhs, rhs); |
| 1899 | else |
| 1900 | __ SubD(dst, lhs, rhs); |
| 1901 | } else { |
| 1902 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 1903 | } |
| 1904 | break; |
| 1905 | } |
| 1906 | default: |
| 1907 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1912 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1913 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1914 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1915 | DataType::Type type = instr->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1916 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1917 | case DataType::Type::kInt32: |
| 1918 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1920 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1921 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1922 | break; |
| 1923 | } |
| 1924 | default: |
| 1925 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1930 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1931 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1932 | DataType::Type type = instr->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1933 | |
| 1934 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1935 | case DataType::Type::kInt32: |
| 1936 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1937 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1938 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1939 | Location rhs_location = locations->InAt(1); |
| 1940 | |
| 1941 | GpuRegister rhs_reg = ZERO; |
| 1942 | int64_t rhs_imm = 0; |
| 1943 | bool use_imm = rhs_location.IsConstant(); |
| 1944 | if (use_imm) { |
| 1945 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1946 | } else { |
| 1947 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1948 | } |
| 1949 | |
| 1950 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1951 | uint32_t shift_value = rhs_imm & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1952 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1953 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1954 | if (shift_value == 0) { |
| 1955 | if (dst != lhs) { |
| 1956 | __ Move(dst, lhs); |
| 1957 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1958 | } else if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1959 | if (instr->IsShl()) { |
| 1960 | __ Sll(dst, lhs, shift_value); |
| 1961 | } else if (instr->IsShr()) { |
| 1962 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1963 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1964 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1965 | } else { |
| 1966 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1967 | } |
| 1968 | } else { |
| 1969 | if (shift_value < 32) { |
| 1970 | if (instr->IsShl()) { |
| 1971 | __ Dsll(dst, lhs, shift_value); |
| 1972 | } else if (instr->IsShr()) { |
| 1973 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1974 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1975 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1976 | } else { |
| 1977 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1978 | } |
| 1979 | } else { |
| 1980 | shift_value -= 32; |
| 1981 | if (instr->IsShl()) { |
| 1982 | __ Dsll32(dst, lhs, shift_value); |
| 1983 | } else if (instr->IsShr()) { |
| 1984 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1985 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1986 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1987 | } else { |
| 1988 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1993 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1994 | if (instr->IsShl()) { |
| 1995 | __ Sllv(dst, lhs, rhs_reg); |
| 1996 | } else if (instr->IsShr()) { |
| 1997 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1998 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1999 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2000 | } else { |
| 2001 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2002 | } |
| 2003 | } else { |
| 2004 | if (instr->IsShl()) { |
| 2005 | __ Dsllv(dst, lhs, rhs_reg); |
| 2006 | } else if (instr->IsShr()) { |
| 2007 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2008 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2009 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2010 | } else { |
| 2011 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | } |
| 2015 | break; |
| 2016 | } |
| 2017 | default: |
| 2018 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 2023 | HandleBinaryOp(instruction); |
| 2024 | } |
| 2025 | |
| 2026 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 2027 | HandleBinaryOp(instruction); |
| 2028 | } |
| 2029 | |
| 2030 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 2031 | HandleBinaryOp(instruction); |
| 2032 | } |
| 2033 | |
| 2034 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 2035 | HandleBinaryOp(instruction); |
| 2036 | } |
| 2037 | |
| 2038 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2039 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2040 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2041 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2042 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2043 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2044 | object_array_get_with_read_barrier |
| 2045 | ? LocationSummary::kCallOnSlowPath |
| 2046 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2047 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2048 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2049 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2050 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2051 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2052 | if (DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2053 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2054 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2055 | // The output overlaps in the case of an object array get with |
| 2056 | // read barriers enabled: we do not want the move to overwrite the |
| 2057 | // array's location, as we need it to emit the read barrier. |
| 2058 | locations->SetOut(Location::RequiresRegister(), |
| 2059 | object_array_get_with_read_barrier |
| 2060 | ? Location::kOutputOverlap |
| 2061 | : Location::kNoOutputOverlap); |
| 2062 | } |
| 2063 | // We need a temporary register for the read barrier marking slow |
| 2064 | // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier. |
| 2065 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2066 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2067 | ? !kBakerReadBarrierThunksEnableForFields |
| 2068 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2069 | if (temp_needed) { |
| 2070 | locations->AddTemp(Location::RequiresRegister()); |
| 2071 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2075 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) { |
| 2076 | auto null_checker = [codegen, instruction]() { |
| 2077 | codegen->MaybeRecordImplicitNullCheck(instruction); |
| 2078 | }; |
| 2079 | return null_checker; |
| 2080 | } |
| 2081 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2082 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 2083 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2084 | Location obj_loc = locations->InAt(0); |
| 2085 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 2086 | Location out_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2087 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2088 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2089 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2090 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2091 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2092 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2093 | instruction->IsStringCharAt(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2094 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2095 | case DataType::Type::kBool: |
| 2096 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2097 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2098 | if (index.IsConstant()) { |
| 2099 | size_t offset = |
| 2100 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2101 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2102 | } else { |
| 2103 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2104 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2105 | } |
| 2106 | break; |
| 2107 | } |
| 2108 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2109 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2110 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2111 | if (index.IsConstant()) { |
| 2112 | size_t offset = |
| 2113 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2114 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2115 | } else { |
| 2116 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2117 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2118 | } |
| 2119 | break; |
| 2120 | } |
| 2121 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2122 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2123 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2124 | if (maybe_compressed_char_at) { |
| 2125 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2126 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2127 | __ Dext(TMP, TMP, 0, 1); |
| 2128 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2129 | "Expecting 0=compressed, 1=uncompressed"); |
| 2130 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2131 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2132 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2133 | if (maybe_compressed_char_at) { |
| 2134 | Mips64Label uncompressed_load, done; |
| 2135 | __ Bnezc(TMP, &uncompressed_load); |
| 2136 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2137 | out, |
| 2138 | obj, |
| 2139 | data_offset + (const_index << TIMES_1)); |
| 2140 | __ Bc(&done); |
| 2141 | __ Bind(&uncompressed_load); |
| 2142 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2143 | out, |
| 2144 | obj, |
| 2145 | data_offset + (const_index << TIMES_2)); |
| 2146 | __ Bind(&done); |
| 2147 | } else { |
| 2148 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2149 | out, |
| 2150 | obj, |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2151 | data_offset + (const_index << TIMES_2), |
| 2152 | null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2153 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2154 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2155 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 2156 | if (maybe_compressed_char_at) { |
| 2157 | Mips64Label uncompressed_load, done; |
| 2158 | __ Bnezc(TMP, &uncompressed_load); |
| 2159 | __ Daddu(TMP, obj, index_reg); |
| 2160 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2161 | __ Bc(&done); |
| 2162 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2163 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2164 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2165 | __ Bind(&done); |
| 2166 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2167 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2168 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2169 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2170 | } |
| 2171 | break; |
| 2172 | } |
| 2173 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2174 | case DataType::Type::kInt16: { |
| 2175 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2176 | if (index.IsConstant()) { |
| 2177 | size_t offset = |
| 2178 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2179 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
| 2180 | } else { |
| 2181 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
| 2182 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2183 | } |
| 2184 | break; |
| 2185 | } |
| 2186 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2187 | case DataType::Type::kInt32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2188 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2189 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2190 | LoadOperandType load_type = |
| 2191 | (type == DataType::Type::kReference) ? kLoadUnsignedWord : kLoadWord; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2192 | if (index.IsConstant()) { |
| 2193 | size_t offset = |
| 2194 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2195 | __ LoadFromOffset(load_type, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2196 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2197 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2198 | __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2199 | } |
| 2200 | break; |
| 2201 | } |
| 2202 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2203 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2204 | static_assert( |
| 2205 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2206 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2207 | // /* HeapReference<Object> */ out = |
| 2208 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2209 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2210 | bool temp_needed = index.IsConstant() |
| 2211 | ? !kBakerReadBarrierThunksEnableForFields |
| 2212 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2213 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2214 | // Note that a potential implicit null check is handled in this |
| 2215 | // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2216 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2217 | if (index.IsConstant()) { |
| 2218 | // Array load with a constant index can be treated as a field load. |
| 2219 | size_t offset = |
| 2220 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2221 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2222 | out_loc, |
| 2223 | obj, |
| 2224 | offset, |
| 2225 | temp, |
| 2226 | /* needs_null_check */ false); |
| 2227 | } else { |
| 2228 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2229 | out_loc, |
| 2230 | obj, |
| 2231 | data_offset, |
| 2232 | index, |
| 2233 | temp, |
| 2234 | /* needs_null_check */ false); |
| 2235 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2236 | } else { |
| 2237 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2238 | if (index.IsConstant()) { |
| 2239 | size_t offset = |
| 2240 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2241 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker); |
| 2242 | // If read barriers are enabled, emit read barriers other than |
| 2243 | // Baker's using a slow path (and also unpoison the loaded |
| 2244 | // reference, if heap poisoning is enabled). |
| 2245 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2246 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2247 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2248 | __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker); |
| 2249 | // If read barriers are enabled, emit read barriers other than |
| 2250 | // Baker's using a slow path (and also unpoison the loaded |
| 2251 | // reference, if heap poisoning is enabled). |
| 2252 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2253 | out_loc, |
| 2254 | out_loc, |
| 2255 | obj_loc, |
| 2256 | data_offset, |
| 2257 | index); |
| 2258 | } |
| 2259 | } |
| 2260 | break; |
| 2261 | } |
| 2262 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2263 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2264 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2265 | if (index.IsConstant()) { |
| 2266 | size_t offset = |
| 2267 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2268 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2269 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2270 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2271 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2272 | } |
| 2273 | break; |
| 2274 | } |
| 2275 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2276 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2277 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2278 | if (index.IsConstant()) { |
| 2279 | size_t offset = |
| 2280 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2281 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2282 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2283 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2284 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2285 | } |
| 2286 | break; |
| 2287 | } |
| 2288 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2289 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2290 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2291 | if (index.IsConstant()) { |
| 2292 | size_t offset = |
| 2293 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2294 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2295 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2296 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2297 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2298 | } |
| 2299 | break; |
| 2300 | } |
| 2301 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2302 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2303 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2304 | UNREACHABLE(); |
| 2305 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2309 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2310 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2311 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2312 | } |
| 2313 | |
| 2314 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2315 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2316 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2317 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2318 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2319 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2320 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2321 | // Mask out compression flag from String's array length. |
| 2322 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2323 | __ Srl(out, out, 1u); |
| 2324 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2327 | Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2328 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2329 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2330 | : Location::RequiresRegister(); |
| 2331 | } |
| 2332 | |
| 2333 | Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2334 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2335 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2336 | // but we should only prefer this if the constant has a single use. |
| 2337 | if (instruction->IsConstant() && |
| 2338 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2339 | instruction->GetUses().HasExactlyOneElement())) { |
| 2340 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2341 | // Otherwise fall through and require an FPU register for the constant. |
| 2342 | } |
| 2343 | return Location::RequiresFpuRegister(); |
| 2344 | } |
| 2345 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2346 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2347 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2348 | |
| 2349 | bool needs_write_barrier = |
| 2350 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2351 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2352 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2353 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2354 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2355 | may_need_runtime_call_for_type_check ? |
| 2356 | LocationSummary::kCallOnSlowPath : |
| 2357 | LocationSummary::kNoCall); |
| 2358 | |
| 2359 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2360 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2361 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2362 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2363 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2364 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2365 | } |
| 2366 | if (needs_write_barrier) { |
| 2367 | // Temporary register for the write barrier. |
| 2368 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2369 | } |
| 2370 | } |
| 2371 | |
| 2372 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 2373 | LocationSummary* locations = instruction->GetLocations(); |
| 2374 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2375 | Location index = locations->InAt(1); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2376 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2377 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2378 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2379 | bool needs_write_barrier = |
| 2380 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2381 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2382 | GpuRegister base_reg = index.IsConstant() ? obj : TMP; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2383 | |
| 2384 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2385 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2386 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2387 | case DataType::Type::kInt8: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2388 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2389 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2390 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2391 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2392 | __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>()); |
| 2393 | } |
| 2394 | if (value_location.IsConstant()) { |
| 2395 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2396 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2397 | } else { |
| 2398 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2399 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2400 | } |
| 2401 | break; |
| 2402 | } |
| 2403 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2404 | case DataType::Type::kUint16: |
| 2405 | case DataType::Type::kInt16: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2406 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2407 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2408 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2409 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2410 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2411 | } |
| 2412 | if (value_location.IsConstant()) { |
| 2413 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2414 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2415 | } else { |
| 2416 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2417 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2418 | } |
| 2419 | break; |
| 2420 | } |
| 2421 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2422 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2423 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2424 | if (index.IsConstant()) { |
| 2425 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2426 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2427 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2428 | } |
| 2429 | if (value_location.IsConstant()) { |
| 2430 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2431 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2432 | } else { |
| 2433 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2434 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2435 | } |
| 2436 | break; |
| 2437 | } |
| 2438 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2439 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2440 | if (value_location.IsConstant()) { |
| 2441 | // Just setting null. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2442 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2443 | if (index.IsConstant()) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2444 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2445 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2446 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2447 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2448 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2449 | DCHECK_EQ(value, 0); |
| 2450 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2451 | DCHECK(!needs_write_barrier); |
| 2452 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2453 | break; |
| 2454 | } |
| 2455 | |
| 2456 | DCHECK(needs_write_barrier); |
| 2457 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2458 | GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 2459 | GpuRegister temp2 = TMP; // Doesn't need to survive slow path. |
| 2460 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2461 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2462 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2463 | Mips64Label done; |
| 2464 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 2465 | |
| 2466 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2467 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS64(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2468 | codegen_->AddSlowPath(slow_path); |
| 2469 | if (instruction->GetValueCanBeNull()) { |
| 2470 | Mips64Label non_zero; |
| 2471 | __ Bnezc(value, &non_zero); |
| 2472 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2473 | if (index.IsConstant()) { |
| 2474 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2475 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2476 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2477 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2478 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2479 | __ Bc(&done); |
| 2480 | __ Bind(&non_zero); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2481 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2482 | |
| 2483 | // Note that when read barriers are enabled, the type checks |
| 2484 | // are performed without read barriers. This is fine, even in |
| 2485 | // the case where a class object is in the from-space after |
| 2486 | // the flip, as a comparison involving such a type would not |
| 2487 | // produce a false positive; it may of course produce a false |
| 2488 | // negative, in which case we would take the ArraySet slow |
| 2489 | // path. |
| 2490 | |
| 2491 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2492 | __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker); |
| 2493 | __ MaybeUnpoisonHeapReference(temp1); |
| 2494 | |
| 2495 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2496 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset); |
| 2497 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2498 | __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset); |
| 2499 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2500 | // nor `temp2`, as we are comparing two poisoned references. |
| 2501 | |
| 2502 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2503 | Mips64Label do_put; |
| 2504 | __ Beqc(temp1, temp2, &do_put); |
| 2505 | // If heap poisoning is enabled, the `temp1` reference has |
| 2506 | // not been unpoisoned yet; unpoison it now. |
| 2507 | __ MaybeUnpoisonHeapReference(temp1); |
| 2508 | |
| 2509 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2510 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset); |
| 2511 | // If heap poisoning is enabled, no need to unpoison |
| 2512 | // `temp1`, as we are comparing against null below. |
| 2513 | __ Bnezc(temp1, slow_path->GetEntryLabel()); |
| 2514 | __ Bind(&do_put); |
| 2515 | } else { |
| 2516 | __ Bnec(temp1, temp2, slow_path->GetEntryLabel()); |
| 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | GpuRegister source = value; |
| 2521 | if (kPoisonHeapReferences) { |
| 2522 | // Note that in the case where `value` is a null reference, |
| 2523 | // we do not enter this block, as a null reference does not |
| 2524 | // need poisoning. |
| 2525 | __ Move(temp1, value); |
| 2526 | __ PoisonHeapReference(temp1); |
| 2527 | source = temp1; |
| 2528 | } |
| 2529 | |
| 2530 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2531 | if (index.IsConstant()) { |
| 2532 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2533 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2534 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2535 | } |
| 2536 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2537 | |
| 2538 | if (!may_need_runtime_call_for_type_check) { |
| 2539 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2540 | } |
| 2541 | |
| 2542 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2543 | |
| 2544 | if (done.IsLinked()) { |
| 2545 | __ Bind(&done); |
| 2546 | } |
| 2547 | |
| 2548 | if (slow_path != nullptr) { |
| 2549 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2550 | } |
| 2551 | break; |
| 2552 | } |
| 2553 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2554 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2555 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2556 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2557 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2558 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2559 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2560 | } |
| 2561 | if (value_location.IsConstant()) { |
| 2562 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2563 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2564 | } else { |
| 2565 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2566 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2567 | } |
| 2568 | break; |
| 2569 | } |
| 2570 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2571 | case DataType::Type::kFloat32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2572 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2573 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2574 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2575 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2576 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2577 | } |
| 2578 | if (value_location.IsConstant()) { |
| 2579 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2580 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2581 | } else { |
| 2582 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2583 | __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2584 | } |
| 2585 | break; |
| 2586 | } |
| 2587 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2588 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2589 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2590 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2591 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2592 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2593 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2594 | } |
| 2595 | if (value_location.IsConstant()) { |
| 2596 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2597 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2598 | } else { |
| 2599 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2600 | __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2601 | } |
| 2602 | break; |
| 2603 | } |
| 2604 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2605 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2606 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2607 | UNREACHABLE(); |
| 2608 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2612 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2613 | InvokeRuntimeCallingConvention calling_convention; |
| 2614 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2615 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2616 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2617 | |
| 2618 | HInstruction* index = instruction->InputAt(0); |
| 2619 | HInstruction* length = instruction->InputAt(1); |
| 2620 | |
| 2621 | bool const_index = false; |
| 2622 | bool const_length = false; |
| 2623 | |
| 2624 | if (index->IsConstant()) { |
| 2625 | if (length->IsConstant()) { |
| 2626 | const_index = true; |
| 2627 | const_length = true; |
| 2628 | } else { |
| 2629 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 2630 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 2631 | const_index = true; |
| 2632 | } |
| 2633 | } |
| 2634 | } else if (length->IsConstant()) { |
| 2635 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 2636 | if (IsUint<15>(length_value)) { |
| 2637 | const_length = true; |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | locations->SetInAt(0, const_index |
| 2642 | ? Location::ConstantLocation(index->AsConstant()) |
| 2643 | : Location::RequiresRegister()); |
| 2644 | locations->SetInAt(1, const_length |
| 2645 | ? Location::ConstantLocation(length->AsConstant()) |
| 2646 | : Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2650 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2651 | Location index_loc = locations->InAt(0); |
| 2652 | Location length_loc = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2653 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2654 | if (length_loc.IsConstant()) { |
| 2655 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2656 | if (index_loc.IsConstant()) { |
| 2657 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2658 | if (index < 0 || index >= length) { |
| 2659 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2660 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2661 | codegen_->AddSlowPath(slow_path); |
| 2662 | __ Bc(slow_path->GetEntryLabel()); |
| 2663 | } else { |
| 2664 | // Nothing to be done. |
| 2665 | } |
| 2666 | return; |
| 2667 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2668 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2669 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2670 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2671 | codegen_->AddSlowPath(slow_path); |
| 2672 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2673 | if (length == 0) { |
| 2674 | __ Bc(slow_path->GetEntryLabel()); |
| 2675 | } else if (length == 1) { |
| 2676 | __ Bnezc(index, slow_path->GetEntryLabel()); |
| 2677 | } else { |
| 2678 | DCHECK(IsUint<15>(length)) << length; |
| 2679 | __ Sltiu(TMP, index, length); |
| 2680 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2681 | } |
| 2682 | } else { |
| 2683 | GpuRegister length = length_loc.AsRegister<GpuRegister>(); |
| 2684 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2685 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2686 | codegen_->AddSlowPath(slow_path); |
| 2687 | if (index_loc.IsConstant()) { |
| 2688 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2689 | if (index < 0) { |
| 2690 | __ Bc(slow_path->GetEntryLabel()); |
| 2691 | } else if (index == 0) { |
| 2692 | __ Blezc(length, slow_path->GetEntryLabel()); |
| 2693 | } else { |
| 2694 | DCHECK(IsInt<16>(index + 1)) << index; |
| 2695 | __ Sltiu(TMP, length, index + 1); |
| 2696 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 2697 | } |
| 2698 | } else { |
| 2699 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2700 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
| 2701 | } |
| 2702 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2705 | // Temp is used for read barrier. |
| 2706 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 2707 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2708 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2709 | (kUseBakerReadBarrier || |
| 2710 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2711 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2712 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2713 | return 1; |
| 2714 | } |
| 2715 | return 0; |
| 2716 | } |
| 2717 | |
| 2718 | // Extra temp is used for read barrier. |
| 2719 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 2720 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 2721 | } |
| 2722 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2723 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2724 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2725 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 2726 | |
| 2727 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 2728 | switch (type_check_kind) { |
| 2729 | case TypeCheckKind::kExactCheck: |
| 2730 | case TypeCheckKind::kAbstractClassCheck: |
| 2731 | case TypeCheckKind::kClassHierarchyCheck: |
| 2732 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2733 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2734 | ? LocationSummary::kCallOnSlowPath |
| 2735 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 2736 | break; |
| 2737 | case TypeCheckKind::kArrayCheck: |
| 2738 | case TypeCheckKind::kUnresolvedCheck: |
| 2739 | case TypeCheckKind::kInterfaceCheck: |
| 2740 | call_kind = LocationSummary::kCallOnSlowPath; |
| 2741 | break; |
| 2742 | } |
| 2743 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2744 | LocationSummary* locations = |
| 2745 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2746 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2747 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2748 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2752 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2753 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2754 | Location obj_loc = locations->InAt(0); |
| 2755 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2756 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2757 | Location temp_loc = locations->GetTemp(0); |
| 2758 | GpuRegister temp = temp_loc.AsRegister<GpuRegister>(); |
| 2759 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 2760 | DCHECK_LE(num_temps, 2u); |
| 2761 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2762 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2763 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2764 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2765 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2766 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 2767 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2768 | const uint32_t object_array_data_offset = |
| 2769 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 2770 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2771 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2772 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 2773 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 2774 | // read barriers is done for performance and code size reasons. |
| 2775 | bool is_type_check_slow_path_fatal = false; |
| 2776 | if (!kEmitCompilerReadBarrier) { |
| 2777 | is_type_check_slow_path_fatal = |
| 2778 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 2779 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2780 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2781 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 2782 | !instruction->CanThrowIntoCatchBlock(); |
| 2783 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2784 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2785 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 2786 | instruction, is_type_check_slow_path_fatal); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2787 | codegen_->AddSlowPath(slow_path); |
| 2788 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2789 | // Avoid this check if we know `obj` is not null. |
| 2790 | if (instruction->MustDoNullCheck()) { |
| 2791 | __ Beqzc(obj, &done); |
| 2792 | } |
| 2793 | |
| 2794 | switch (type_check_kind) { |
| 2795 | case TypeCheckKind::kExactCheck: |
| 2796 | case TypeCheckKind::kArrayCheck: { |
| 2797 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2798 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2799 | temp_loc, |
| 2800 | obj_loc, |
| 2801 | class_offset, |
| 2802 | maybe_temp2_loc, |
| 2803 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2804 | // Jump to slow path for throwing the exception or doing a |
| 2805 | // more involved array check. |
| 2806 | __ Bnec(temp, cls, slow_path->GetEntryLabel()); |
| 2807 | break; |
| 2808 | } |
| 2809 | |
| 2810 | case TypeCheckKind::kAbstractClassCheck: { |
| 2811 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2812 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2813 | temp_loc, |
| 2814 | obj_loc, |
| 2815 | class_offset, |
| 2816 | maybe_temp2_loc, |
| 2817 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2818 | // If the class is abstract, we eagerly fetch the super class of the |
| 2819 | // object to avoid doing a comparison we know will fail. |
| 2820 | Mips64Label loop; |
| 2821 | __ Bind(&loop); |
| 2822 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2823 | GenerateReferenceLoadOneRegister(instruction, |
| 2824 | temp_loc, |
| 2825 | super_offset, |
| 2826 | maybe_temp2_loc, |
| 2827 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2828 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2829 | // exception. |
| 2830 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2831 | // Otherwise, compare the classes. |
| 2832 | __ Bnec(temp, cls, &loop); |
| 2833 | break; |
| 2834 | } |
| 2835 | |
| 2836 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2837 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2838 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2839 | temp_loc, |
| 2840 | obj_loc, |
| 2841 | class_offset, |
| 2842 | maybe_temp2_loc, |
| 2843 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2844 | // Walk over the class hierarchy to find a match. |
| 2845 | Mips64Label loop; |
| 2846 | __ Bind(&loop); |
| 2847 | __ Beqc(temp, cls, &done); |
| 2848 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2849 | GenerateReferenceLoadOneRegister(instruction, |
| 2850 | temp_loc, |
| 2851 | super_offset, |
| 2852 | maybe_temp2_loc, |
| 2853 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2854 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2855 | // exception. Otherwise, jump to the beginning of the loop. |
| 2856 | __ Bnezc(temp, &loop); |
| 2857 | __ Bc(slow_path->GetEntryLabel()); |
| 2858 | break; |
| 2859 | } |
| 2860 | |
| 2861 | case TypeCheckKind::kArrayObjectCheck: { |
| 2862 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2863 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2864 | temp_loc, |
| 2865 | obj_loc, |
| 2866 | class_offset, |
| 2867 | maybe_temp2_loc, |
| 2868 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2869 | // Do an exact check. |
| 2870 | __ Beqc(temp, cls, &done); |
| 2871 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 2872 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2873 | GenerateReferenceLoadOneRegister(instruction, |
| 2874 | temp_loc, |
| 2875 | component_offset, |
| 2876 | maybe_temp2_loc, |
| 2877 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2878 | // If the component type is null, jump to the slow path to throw the exception. |
| 2879 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2880 | // Otherwise, the object is indeed an array, further check that this component |
| 2881 | // type is not a primitive type. |
| 2882 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 2883 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2884 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
| 2885 | break; |
| 2886 | } |
| 2887 | |
| 2888 | case TypeCheckKind::kUnresolvedCheck: |
| 2889 | // We always go into the type check slow path for the unresolved check case. |
| 2890 | // We cannot directly call the CheckCast runtime entry point |
| 2891 | // without resorting to a type checking slow path here (i.e. by |
| 2892 | // calling InvokeRuntime directly), as it would require to |
| 2893 | // assign fixed registers for the inputs of this HInstanceOf |
| 2894 | // instruction (following the runtime calling convention), which |
| 2895 | // might be cluttered by the potential first read barrier |
| 2896 | // emission at the beginning of this method. |
| 2897 | __ Bc(slow_path->GetEntryLabel()); |
| 2898 | break; |
| 2899 | |
| 2900 | case TypeCheckKind::kInterfaceCheck: { |
| 2901 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 2902 | // positives by doing this. |
| 2903 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2904 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2905 | temp_loc, |
| 2906 | obj_loc, |
| 2907 | class_offset, |
| 2908 | maybe_temp2_loc, |
| 2909 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2910 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2911 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2912 | temp_loc, |
| 2913 | temp_loc, |
| 2914 | iftable_offset, |
| 2915 | maybe_temp2_loc, |
| 2916 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2917 | // Iftable is never null. |
| 2918 | __ Lw(TMP, temp, array_length_offset); |
| 2919 | // Loop through the iftable and check if any class matches. |
| 2920 | Mips64Label loop; |
| 2921 | __ Bind(&loop); |
| 2922 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2923 | __ Lwu(AT, temp, object_array_data_offset); |
| 2924 | __ MaybeUnpoisonHeapReference(AT); |
| 2925 | // Go to next interface. |
| 2926 | __ Daddiu(temp, temp, 2 * kHeapReferenceSize); |
| 2927 | __ Addiu(TMP, TMP, -2); |
| 2928 | // Compare the classes and continue the loop if they do not match. |
| 2929 | __ Bnec(AT, cls, &loop); |
| 2930 | break; |
| 2931 | } |
| 2932 | } |
| 2933 | |
| 2934 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2935 | __ Bind(slow_path->GetExitLabel()); |
| 2936 | } |
| 2937 | |
| 2938 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2939 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2940 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2941 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2942 | if (check->HasUses()) { |
| 2943 | locations->SetOut(Location::SameAsFirstInput()); |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2948 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2949 | SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64( |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2950 | check->GetLoadClass(), |
| 2951 | check, |
| 2952 | check->GetDexPc(), |
| 2953 | true); |
| 2954 | codegen_->AddSlowPath(slow_path); |
| 2955 | GenerateClassInitializationCheck(slow_path, |
| 2956 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 2957 | } |
| 2958 | |
| 2959 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2960 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2961 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2962 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2963 | |
| 2964 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2965 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2966 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2967 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2968 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2969 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2970 | case DataType::Type::kInt32: |
| 2971 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2972 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2973 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2974 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2975 | break; |
| 2976 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2977 | case DataType::Type::kFloat32: |
| 2978 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2979 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2980 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2981 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2982 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2983 | |
| 2984 | default: |
| 2985 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2986 | } |
| 2987 | } |
| 2988 | |
| 2989 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 2990 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2991 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2992 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2993 | |
| 2994 | // 0 if: left == right |
| 2995 | // 1 if: left > right |
| 2996 | // -1 if: left < right |
| 2997 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2998 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2999 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3000 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3001 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3002 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3003 | case DataType::Type::kInt32: |
| 3004 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3005 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3006 | Location rhs_location = locations->InAt(1); |
| 3007 | bool use_imm = rhs_location.IsConstant(); |
| 3008 | GpuRegister rhs = ZERO; |
| 3009 | if (use_imm) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3010 | if (in_type == DataType::Type::kInt64) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3011 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3012 | if (value != 0) { |
| 3013 | rhs = AT; |
| 3014 | __ LoadConst64(rhs, value); |
| 3015 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3016 | } else { |
| 3017 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3018 | if (value != 0) { |
| 3019 | rhs = AT; |
| 3020 | __ LoadConst32(rhs, value); |
| 3021 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3022 | } |
| 3023 | } else { |
| 3024 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 3025 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3026 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3027 | __ Slt(res, rhs, lhs); |
| 3028 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3029 | break; |
| 3030 | } |
| 3031 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3032 | case DataType::Type::kFloat32: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3033 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3034 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3035 | Mips64Label done; |
| 3036 | __ CmpEqS(FTMP, lhs, rhs); |
| 3037 | __ LoadConst32(res, 0); |
| 3038 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3039 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3040 | __ CmpLtS(FTMP, lhs, rhs); |
| 3041 | __ LoadConst32(res, -1); |
| 3042 | __ Bc1nez(FTMP, &done); |
| 3043 | __ LoadConst32(res, 1); |
| 3044 | } else { |
| 3045 | __ CmpLtS(FTMP, rhs, lhs); |
| 3046 | __ LoadConst32(res, 1); |
| 3047 | __ Bc1nez(FTMP, &done); |
| 3048 | __ LoadConst32(res, -1); |
| 3049 | } |
| 3050 | __ Bind(&done); |
| 3051 | break; |
| 3052 | } |
| 3053 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3054 | case DataType::Type::kFloat64: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3055 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3056 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3057 | Mips64Label done; |
| 3058 | __ CmpEqD(FTMP, lhs, rhs); |
| 3059 | __ LoadConst32(res, 0); |
| 3060 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3061 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3062 | __ CmpLtD(FTMP, lhs, rhs); |
| 3063 | __ LoadConst32(res, -1); |
| 3064 | __ Bc1nez(FTMP, &done); |
| 3065 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3066 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3067 | __ CmpLtD(FTMP, rhs, lhs); |
| 3068 | __ LoadConst32(res, 1); |
| 3069 | __ Bc1nez(FTMP, &done); |
| 3070 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3071 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3072 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3073 | break; |
| 3074 | } |
| 3075 | |
| 3076 | default: |
| 3077 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3078 | } |
| 3079 | } |
| 3080 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3081 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3082 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3083 | switch (instruction->InputAt(0)->GetType()) { |
| 3084 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3085 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3086 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3087 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3088 | break; |
| 3089 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3090 | case DataType::Type::kFloat32: |
| 3091 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3092 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3093 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3094 | break; |
| 3095 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3096 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3097 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3098 | } |
| 3099 | } |
| 3100 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3101 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3102 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3103 | return; |
| 3104 | } |
| 3105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3106 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3107 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3108 | switch (type) { |
| 3109 | default: |
| 3110 | // Integer case. |
| 3111 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 3112 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3113 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3114 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 3115 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3116 | case DataType::Type::kFloat32: |
| 3117 | case DataType::Type::kFloat64: |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3118 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3119 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3120 | } |
| 3121 | } |
| 3122 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3123 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3124 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3125 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3126 | |
| 3127 | LocationSummary* locations = instruction->GetLocations(); |
| 3128 | Location second = locations->InAt(1); |
| 3129 | DCHECK(second.IsConstant()); |
| 3130 | |
| 3131 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3132 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3133 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3134 | DCHECK(imm == 1 || imm == -1); |
| 3135 | |
| 3136 | if (instruction->IsRem()) { |
| 3137 | __ Move(out, ZERO); |
| 3138 | } else { |
| 3139 | if (imm == -1) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3140 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3141 | __ Subu(out, ZERO, dividend); |
| 3142 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3143 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3144 | __ Dsubu(out, ZERO, dividend); |
| 3145 | } |
| 3146 | } else if (out != dividend) { |
| 3147 | __ Move(out, dividend); |
| 3148 | } |
| 3149 | } |
| 3150 | } |
| 3151 | |
| 3152 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3153 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3154 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3155 | |
| 3156 | LocationSummary* locations = instruction->GetLocations(); |
| 3157 | Location second = locations->InAt(1); |
| 3158 | DCHECK(second.IsConstant()); |
| 3159 | |
| 3160 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3161 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3162 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3163 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3164 | int ctz_imm = CTZ(abs_imm); |
| 3165 | |
| 3166 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3167 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3168 | if (ctz_imm == 1) { |
| 3169 | // Fast path for division by +/-2, which is very common. |
| 3170 | __ Srl(TMP, dividend, 31); |
| 3171 | } else { |
| 3172 | __ Sra(TMP, dividend, 31); |
| 3173 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3174 | } |
| 3175 | __ Addu(out, dividend, TMP); |
| 3176 | __ Sra(out, out, ctz_imm); |
| 3177 | if (imm < 0) { |
| 3178 | __ Subu(out, ZERO, out); |
| 3179 | } |
| 3180 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3181 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3182 | if (ctz_imm == 1) { |
| 3183 | // Fast path for division by +/-2, which is very common. |
| 3184 | __ Dsrl32(TMP, dividend, 31); |
| 3185 | } else { |
| 3186 | __ Dsra32(TMP, dividend, 31); |
| 3187 | if (ctz_imm > 32) { |
| 3188 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3189 | } else { |
| 3190 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3191 | } |
| 3192 | } |
| 3193 | __ Daddu(out, dividend, TMP); |
| 3194 | if (ctz_imm < 32) { |
| 3195 | __ Dsra(out, out, ctz_imm); |
| 3196 | } else { |
| 3197 | __ Dsra32(out, out, ctz_imm - 32); |
| 3198 | } |
| 3199 | if (imm < 0) { |
| 3200 | __ Dsubu(out, ZERO, out); |
| 3201 | } |
| 3202 | } |
| 3203 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3204 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3205 | if (ctz_imm == 1) { |
| 3206 | // Fast path for modulo +/-2, which is very common. |
| 3207 | __ Sra(TMP, dividend, 31); |
| 3208 | __ Subu(out, dividend, TMP); |
| 3209 | __ Andi(out, out, 1); |
| 3210 | __ Addu(out, out, TMP); |
| 3211 | } else { |
| 3212 | __ Sra(TMP, dividend, 31); |
| 3213 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3214 | __ Addu(out, dividend, TMP); |
| 3215 | if (IsUint<16>(abs_imm - 1)) { |
| 3216 | __ Andi(out, out, abs_imm - 1); |
| 3217 | } else { |
| 3218 | __ Sll(out, out, 32 - ctz_imm); |
| 3219 | __ Srl(out, out, 32 - ctz_imm); |
| 3220 | } |
| 3221 | __ Subu(out, out, TMP); |
| 3222 | } |
| 3223 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3224 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3225 | if (ctz_imm == 1) { |
| 3226 | // Fast path for modulo +/-2, which is very common. |
| 3227 | __ Dsra32(TMP, dividend, 31); |
| 3228 | __ Dsubu(out, dividend, TMP); |
| 3229 | __ Andi(out, out, 1); |
| 3230 | __ Daddu(out, out, TMP); |
| 3231 | } else { |
| 3232 | __ Dsra32(TMP, dividend, 31); |
| 3233 | if (ctz_imm > 32) { |
| 3234 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3235 | } else { |
| 3236 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3237 | } |
| 3238 | __ Daddu(out, dividend, TMP); |
| 3239 | if (IsUint<16>(abs_imm - 1)) { |
| 3240 | __ Andi(out, out, abs_imm - 1); |
| 3241 | } else { |
| 3242 | if (ctz_imm > 32) { |
| 3243 | __ Dsll(out, out, 64 - ctz_imm); |
| 3244 | __ Dsrl(out, out, 64 - ctz_imm); |
| 3245 | } else { |
| 3246 | __ Dsll32(out, out, 32 - ctz_imm); |
| 3247 | __ Dsrl32(out, out, 32 - ctz_imm); |
| 3248 | } |
| 3249 | } |
| 3250 | __ Dsubu(out, out, TMP); |
| 3251 | } |
| 3252 | } |
| 3253 | } |
| 3254 | } |
| 3255 | |
| 3256 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3257 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3258 | |
| 3259 | LocationSummary* locations = instruction->GetLocations(); |
| 3260 | Location second = locations->InAt(1); |
| 3261 | DCHECK(second.IsConstant()); |
| 3262 | |
| 3263 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3264 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3265 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3266 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3267 | DataType::Type type = instruction->GetResultType(); |
| 3268 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3269 | |
| 3270 | int64_t magic; |
| 3271 | int shift; |
| 3272 | CalculateMagicAndShiftForDivRem(imm, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3273 | (type == DataType::Type::kInt64), |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3274 | &magic, |
| 3275 | &shift); |
| 3276 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3277 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3278 | __ LoadConst32(TMP, magic); |
| 3279 | __ MuhR6(TMP, dividend, TMP); |
| 3280 | |
| 3281 | if (imm > 0 && magic < 0) { |
| 3282 | __ Addu(TMP, TMP, dividend); |
| 3283 | } else if (imm < 0 && magic > 0) { |
| 3284 | __ Subu(TMP, TMP, dividend); |
| 3285 | } |
| 3286 | |
| 3287 | if (shift != 0) { |
| 3288 | __ Sra(TMP, TMP, shift); |
| 3289 | } |
| 3290 | |
| 3291 | if (instruction->IsDiv()) { |
| 3292 | __ Sra(out, TMP, 31); |
| 3293 | __ Subu(out, TMP, out); |
| 3294 | } else { |
| 3295 | __ Sra(AT, TMP, 31); |
| 3296 | __ Subu(AT, TMP, AT); |
| 3297 | __ LoadConst32(TMP, imm); |
| 3298 | __ MulR6(TMP, AT, TMP); |
| 3299 | __ Subu(out, dividend, TMP); |
| 3300 | } |
| 3301 | } else { |
| 3302 | __ LoadConst64(TMP, magic); |
| 3303 | __ Dmuh(TMP, dividend, TMP); |
| 3304 | |
| 3305 | if (imm > 0 && magic < 0) { |
| 3306 | __ Daddu(TMP, TMP, dividend); |
| 3307 | } else if (imm < 0 && magic > 0) { |
| 3308 | __ Dsubu(TMP, TMP, dividend); |
| 3309 | } |
| 3310 | |
| 3311 | if (shift >= 32) { |
| 3312 | __ Dsra32(TMP, TMP, shift - 32); |
| 3313 | } else if (shift > 0) { |
| 3314 | __ Dsra(TMP, TMP, shift); |
| 3315 | } |
| 3316 | |
| 3317 | if (instruction->IsDiv()) { |
| 3318 | __ Dsra32(out, TMP, 31); |
| 3319 | __ Dsubu(out, TMP, out); |
| 3320 | } else { |
| 3321 | __ Dsra32(AT, TMP, 31); |
| 3322 | __ Dsubu(AT, TMP, AT); |
| 3323 | __ LoadConst64(TMP, imm); |
| 3324 | __ Dmul(TMP, AT, TMP); |
| 3325 | __ Dsubu(out, dividend, TMP); |
| 3326 | } |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3331 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3332 | DataType::Type type = instruction->GetResultType(); |
| 3333 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3334 | |
| 3335 | LocationSummary* locations = instruction->GetLocations(); |
| 3336 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3337 | Location second = locations->InAt(1); |
| 3338 | |
| 3339 | if (second.IsConstant()) { |
| 3340 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3341 | if (imm == 0) { |
| 3342 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3343 | } else if (imm == 1 || imm == -1) { |
| 3344 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3345 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3346 | DivRemByPowerOfTwo(instruction); |
| 3347 | } else { |
| 3348 | DCHECK(imm <= -2 || imm >= 2); |
| 3349 | GenerateDivRemWithAnyConstant(instruction); |
| 3350 | } |
| 3351 | } else { |
| 3352 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3353 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 3354 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3355 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3356 | __ DivR6(out, dividend, divisor); |
| 3357 | else |
| 3358 | __ Ddiv(out, dividend, divisor); |
| 3359 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3360 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3361 | __ ModR6(out, dividend, divisor); |
| 3362 | else |
| 3363 | __ Dmod(out, dividend, divisor); |
| 3364 | } |
| 3365 | } |
| 3366 | } |
| 3367 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3368 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 3369 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3370 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3371 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3372 | case DataType::Type::kInt32: |
| 3373 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3374 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3375 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3376 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3377 | break; |
| 3378 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3379 | case DataType::Type::kFloat32: |
| 3380 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3381 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3382 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3383 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3384 | break; |
| 3385 | |
| 3386 | default: |
| 3387 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3388 | } |
| 3389 | } |
| 3390 | |
| 3391 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3392 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3393 | LocationSummary* locations = instruction->GetLocations(); |
| 3394 | |
| 3395 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3396 | case DataType::Type::kInt32: |
| 3397 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3398 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3399 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3400 | case DataType::Type::kFloat32: |
| 3401 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3402 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3403 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3404 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3405 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3406 | __ DivS(dst, lhs, rhs); |
| 3407 | else |
| 3408 | __ DivD(dst, lhs, rhs); |
| 3409 | break; |
| 3410 | } |
| 3411 | default: |
| 3412 | LOG(FATAL) << "Unexpected div type " << type; |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3417 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3418 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3422 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3423 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3424 | codegen_->AddSlowPath(slow_path); |
| 3425 | Location value = instruction->GetLocations()->InAt(0); |
| 3426 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3427 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3428 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3429 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3430 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3431 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
| 3434 | if (value.IsConstant()) { |
| 3435 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 3436 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3437 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3438 | } else { |
| 3439 | // A division by a non-null constant is valid. We don't need to perform |
| 3440 | // any check, so simply fall through. |
| 3441 | } |
| 3442 | } else { |
| 3443 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3444 | } |
| 3445 | } |
| 3446 | |
| 3447 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3448 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3449 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3450 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3451 | } |
| 3452 | |
| 3453 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3454 | // Will be generated at use site. |
| 3455 | } |
| 3456 | |
| 3457 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 3458 | exit->SetLocations(nullptr); |
| 3459 | } |
| 3460 | |
| 3461 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3462 | } |
| 3463 | |
| 3464 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 3465 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3466 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3467 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3468 | } |
| 3469 | |
| 3470 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3471 | // Will be generated at use site. |
| 3472 | } |
| 3473 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3474 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3475 | DCHECK(!successor->IsExitBlock()); |
| 3476 | HBasicBlock* block = got->GetBlock(); |
| 3477 | HInstruction* previous = got->GetPrevious(); |
| 3478 | HLoopInformation* info = block->GetLoopInformation(); |
| 3479 | |
| 3480 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3481 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3482 | return; |
| 3483 | } |
| 3484 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3485 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3486 | } |
| 3487 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3488 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3489 | } |
| 3490 | } |
| 3491 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3492 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 3493 | got->SetLocations(nullptr); |
| 3494 | } |
| 3495 | |
| 3496 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 3497 | HandleGoto(got, got->GetSuccessor()); |
| 3498 | } |
| 3499 | |
| 3500 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3501 | try_boundary->SetLocations(nullptr); |
| 3502 | } |
| 3503 | |
| 3504 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3505 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3506 | if (!successor->IsExitBlock()) { |
| 3507 | HandleGoto(try_boundary, successor); |
| 3508 | } |
| 3509 | } |
| 3510 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3511 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 3512 | bool is64bit, |
| 3513 | LocationSummary* locations) { |
| 3514 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3515 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3516 | Location rhs_location = locations->InAt(1); |
| 3517 | GpuRegister rhs_reg = ZERO; |
| 3518 | int64_t rhs_imm = 0; |
| 3519 | bool use_imm = rhs_location.IsConstant(); |
| 3520 | if (use_imm) { |
| 3521 | if (is64bit) { |
| 3522 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3523 | } else { |
| 3524 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3525 | } |
| 3526 | } else { |
| 3527 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3528 | } |
| 3529 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3530 | |
| 3531 | switch (cond) { |
| 3532 | case kCondEQ: |
| 3533 | case kCondNE: |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3534 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3535 | if (rhs_imm == 0) { |
| 3536 | if (cond == kCondEQ) { |
| 3537 | __ Sltiu(dst, lhs, 1); |
| 3538 | } else { |
| 3539 | __ Sltu(dst, ZERO, lhs); |
| 3540 | } |
| 3541 | } else { |
| 3542 | if (is64bit) { |
| 3543 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3544 | } else { |
| 3545 | __ Addiu(dst, lhs, -rhs_imm); |
| 3546 | } |
| 3547 | if (cond == kCondEQ) { |
| 3548 | __ Sltiu(dst, dst, 1); |
| 3549 | } else { |
| 3550 | __ Sltu(dst, ZERO, dst); |
| 3551 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3552 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3553 | } else { |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3554 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3555 | __ Xori(dst, lhs, rhs_imm); |
| 3556 | } else { |
| 3557 | if (use_imm) { |
| 3558 | rhs_reg = TMP; |
| 3559 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3560 | } |
| 3561 | __ Xor(dst, lhs, rhs_reg); |
| 3562 | } |
| 3563 | if (cond == kCondEQ) { |
| 3564 | __ Sltiu(dst, dst, 1); |
| 3565 | } else { |
| 3566 | __ Sltu(dst, ZERO, dst); |
| 3567 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3568 | } |
| 3569 | break; |
| 3570 | |
| 3571 | case kCondLT: |
| 3572 | case kCondGE: |
| 3573 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3574 | __ Slti(dst, lhs, rhs_imm); |
| 3575 | } else { |
| 3576 | if (use_imm) { |
| 3577 | rhs_reg = TMP; |
| 3578 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3579 | } |
| 3580 | __ Slt(dst, lhs, rhs_reg); |
| 3581 | } |
| 3582 | if (cond == kCondGE) { |
| 3583 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3584 | // only the slt instruction but no sge. |
| 3585 | __ Xori(dst, dst, 1); |
| 3586 | } |
| 3587 | break; |
| 3588 | |
| 3589 | case kCondLE: |
| 3590 | case kCondGT: |
| 3591 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3592 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3593 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3594 | if (cond == kCondGT) { |
| 3595 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3596 | // only the slti instruction but no sgti. |
| 3597 | __ Xori(dst, dst, 1); |
| 3598 | } |
| 3599 | } else { |
| 3600 | if (use_imm) { |
| 3601 | rhs_reg = TMP; |
| 3602 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3603 | } |
| 3604 | __ Slt(dst, rhs_reg, lhs); |
| 3605 | if (cond == kCondLE) { |
| 3606 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3607 | // only the slt instruction but no sle. |
| 3608 | __ Xori(dst, dst, 1); |
| 3609 | } |
| 3610 | } |
| 3611 | break; |
| 3612 | |
| 3613 | case kCondB: |
| 3614 | case kCondAE: |
| 3615 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3616 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3617 | // the comparison and thus lets us compare directly with |
| 3618 | // unsigned values in the ranges [0, 0x7fff] and |
| 3619 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3620 | __ Sltiu(dst, lhs, rhs_imm); |
| 3621 | } else { |
| 3622 | if (use_imm) { |
| 3623 | rhs_reg = TMP; |
| 3624 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3625 | } |
| 3626 | __ Sltu(dst, lhs, rhs_reg); |
| 3627 | } |
| 3628 | if (cond == kCondAE) { |
| 3629 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3630 | // only the sltu instruction but no sgeu. |
| 3631 | __ Xori(dst, dst, 1); |
| 3632 | } |
| 3633 | break; |
| 3634 | |
| 3635 | case kCondBE: |
| 3636 | case kCondA: |
| 3637 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3638 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3639 | // Note that this only works if rhs + 1 does not overflow |
| 3640 | // to 0, hence the check above. |
| 3641 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3642 | // the comparison and thus lets us compare directly with |
| 3643 | // unsigned values in the ranges [0, 0x7fff] and |
| 3644 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3645 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3646 | if (cond == kCondA) { |
| 3647 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3648 | // only the sltiu instruction but no sgtiu. |
| 3649 | __ Xori(dst, dst, 1); |
| 3650 | } |
| 3651 | } else { |
| 3652 | if (use_imm) { |
| 3653 | rhs_reg = TMP; |
| 3654 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3655 | } |
| 3656 | __ Sltu(dst, rhs_reg, lhs); |
| 3657 | if (cond == kCondBE) { |
| 3658 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3659 | // only the sltu instruction but no sleu. |
| 3660 | __ Xori(dst, dst, 1); |
| 3661 | } |
| 3662 | } |
| 3663 | break; |
| 3664 | } |
| 3665 | } |
| 3666 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3667 | bool InstructionCodeGeneratorMIPS64::MaterializeIntLongCompare(IfCondition cond, |
| 3668 | bool is64bit, |
| 3669 | LocationSummary* input_locations, |
| 3670 | GpuRegister dst) { |
| 3671 | GpuRegister lhs = input_locations->InAt(0).AsRegister<GpuRegister>(); |
| 3672 | Location rhs_location = input_locations->InAt(1); |
| 3673 | GpuRegister rhs_reg = ZERO; |
| 3674 | int64_t rhs_imm = 0; |
| 3675 | bool use_imm = rhs_location.IsConstant(); |
| 3676 | if (use_imm) { |
| 3677 | if (is64bit) { |
| 3678 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3679 | } else { |
| 3680 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3681 | } |
| 3682 | } else { |
| 3683 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3684 | } |
| 3685 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3686 | |
| 3687 | switch (cond) { |
| 3688 | case kCondEQ: |
| 3689 | case kCondNE: |
| 3690 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3691 | if (is64bit) { |
| 3692 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3693 | } else { |
| 3694 | __ Addiu(dst, lhs, -rhs_imm); |
| 3695 | } |
| 3696 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 3697 | __ Xori(dst, lhs, rhs_imm); |
| 3698 | } else { |
| 3699 | if (use_imm) { |
| 3700 | rhs_reg = TMP; |
| 3701 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3702 | } |
| 3703 | __ Xor(dst, lhs, rhs_reg); |
| 3704 | } |
| 3705 | return (cond == kCondEQ); |
| 3706 | |
| 3707 | case kCondLT: |
| 3708 | case kCondGE: |
| 3709 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3710 | __ Slti(dst, lhs, rhs_imm); |
| 3711 | } else { |
| 3712 | if (use_imm) { |
| 3713 | rhs_reg = TMP; |
| 3714 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3715 | } |
| 3716 | __ Slt(dst, lhs, rhs_reg); |
| 3717 | } |
| 3718 | return (cond == kCondGE); |
| 3719 | |
| 3720 | case kCondLE: |
| 3721 | case kCondGT: |
| 3722 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3723 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3724 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3725 | return (cond == kCondGT); |
| 3726 | } else { |
| 3727 | if (use_imm) { |
| 3728 | rhs_reg = TMP; |
| 3729 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3730 | } |
| 3731 | __ Slt(dst, rhs_reg, lhs); |
| 3732 | return (cond == kCondLE); |
| 3733 | } |
| 3734 | |
| 3735 | case kCondB: |
| 3736 | case kCondAE: |
| 3737 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3738 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3739 | // the comparison and thus lets us compare directly with |
| 3740 | // unsigned values in the ranges [0, 0x7fff] and |
| 3741 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3742 | __ Sltiu(dst, lhs, rhs_imm); |
| 3743 | } else { |
| 3744 | if (use_imm) { |
| 3745 | rhs_reg = TMP; |
| 3746 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3747 | } |
| 3748 | __ Sltu(dst, lhs, rhs_reg); |
| 3749 | } |
| 3750 | return (cond == kCondAE); |
| 3751 | |
| 3752 | case kCondBE: |
| 3753 | case kCondA: |
| 3754 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3755 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3756 | // Note that this only works if rhs + 1 does not overflow |
| 3757 | // to 0, hence the check above. |
| 3758 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3759 | // the comparison and thus lets us compare directly with |
| 3760 | // unsigned values in the ranges [0, 0x7fff] and |
| 3761 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3762 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3763 | return (cond == kCondA); |
| 3764 | } else { |
| 3765 | if (use_imm) { |
| 3766 | rhs_reg = TMP; |
| 3767 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3768 | } |
| 3769 | __ Sltu(dst, rhs_reg, lhs); |
| 3770 | return (cond == kCondBE); |
| 3771 | } |
| 3772 | } |
| 3773 | } |
| 3774 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3775 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 3776 | bool is64bit, |
| 3777 | LocationSummary* locations, |
| 3778 | Mips64Label* label) { |
| 3779 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3780 | Location rhs_location = locations->InAt(1); |
| 3781 | GpuRegister rhs_reg = ZERO; |
| 3782 | int64_t rhs_imm = 0; |
| 3783 | bool use_imm = rhs_location.IsConstant(); |
| 3784 | if (use_imm) { |
| 3785 | if (is64bit) { |
| 3786 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3787 | } else { |
| 3788 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3789 | } |
| 3790 | } else { |
| 3791 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3792 | } |
| 3793 | |
| 3794 | if (use_imm && rhs_imm == 0) { |
| 3795 | switch (cond) { |
| 3796 | case kCondEQ: |
| 3797 | case kCondBE: // <= 0 if zero |
| 3798 | __ Beqzc(lhs, label); |
| 3799 | break; |
| 3800 | case kCondNE: |
| 3801 | case kCondA: // > 0 if non-zero |
| 3802 | __ Bnezc(lhs, label); |
| 3803 | break; |
| 3804 | case kCondLT: |
| 3805 | __ Bltzc(lhs, label); |
| 3806 | break; |
| 3807 | case kCondGE: |
| 3808 | __ Bgezc(lhs, label); |
| 3809 | break; |
| 3810 | case kCondLE: |
| 3811 | __ Blezc(lhs, label); |
| 3812 | break; |
| 3813 | case kCondGT: |
| 3814 | __ Bgtzc(lhs, label); |
| 3815 | break; |
| 3816 | case kCondB: // always false |
| 3817 | break; |
| 3818 | case kCondAE: // always true |
| 3819 | __ Bc(label); |
| 3820 | break; |
| 3821 | } |
| 3822 | } else { |
| 3823 | if (use_imm) { |
| 3824 | rhs_reg = TMP; |
| 3825 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3826 | } |
| 3827 | switch (cond) { |
| 3828 | case kCondEQ: |
| 3829 | __ Beqc(lhs, rhs_reg, label); |
| 3830 | break; |
| 3831 | case kCondNE: |
| 3832 | __ Bnec(lhs, rhs_reg, label); |
| 3833 | break; |
| 3834 | case kCondLT: |
| 3835 | __ Bltc(lhs, rhs_reg, label); |
| 3836 | break; |
| 3837 | case kCondGE: |
| 3838 | __ Bgec(lhs, rhs_reg, label); |
| 3839 | break; |
| 3840 | case kCondLE: |
| 3841 | __ Bgec(rhs_reg, lhs, label); |
| 3842 | break; |
| 3843 | case kCondGT: |
| 3844 | __ Bltc(rhs_reg, lhs, label); |
| 3845 | break; |
| 3846 | case kCondB: |
| 3847 | __ Bltuc(lhs, rhs_reg, label); |
| 3848 | break; |
| 3849 | case kCondAE: |
| 3850 | __ Bgeuc(lhs, rhs_reg, label); |
| 3851 | break; |
| 3852 | case kCondBE: |
| 3853 | __ Bgeuc(rhs_reg, lhs, label); |
| 3854 | break; |
| 3855 | case kCondA: |
| 3856 | __ Bltuc(rhs_reg, lhs, label); |
| 3857 | break; |
| 3858 | } |
| 3859 | } |
| 3860 | } |
| 3861 | |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3862 | void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond, |
| 3863 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3864 | DataType::Type type, |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3865 | LocationSummary* locations) { |
| 3866 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3867 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3868 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3869 | if (type == DataType::Type::kFloat32) { |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3870 | switch (cond) { |
| 3871 | case kCondEQ: |
| 3872 | __ CmpEqS(FTMP, lhs, rhs); |
| 3873 | __ Mfc1(dst, FTMP); |
| 3874 | __ Andi(dst, dst, 1); |
| 3875 | break; |
| 3876 | case kCondNE: |
| 3877 | __ CmpEqS(FTMP, lhs, rhs); |
| 3878 | __ Mfc1(dst, FTMP); |
| 3879 | __ Addiu(dst, dst, 1); |
| 3880 | break; |
| 3881 | case kCondLT: |
| 3882 | if (gt_bias) { |
| 3883 | __ CmpLtS(FTMP, lhs, rhs); |
| 3884 | } else { |
| 3885 | __ CmpUltS(FTMP, lhs, rhs); |
| 3886 | } |
| 3887 | __ Mfc1(dst, FTMP); |
| 3888 | __ Andi(dst, dst, 1); |
| 3889 | break; |
| 3890 | case kCondLE: |
| 3891 | if (gt_bias) { |
| 3892 | __ CmpLeS(FTMP, lhs, rhs); |
| 3893 | } else { |
| 3894 | __ CmpUleS(FTMP, lhs, rhs); |
| 3895 | } |
| 3896 | __ Mfc1(dst, FTMP); |
| 3897 | __ Andi(dst, dst, 1); |
| 3898 | break; |
| 3899 | case kCondGT: |
| 3900 | if (gt_bias) { |
| 3901 | __ CmpUltS(FTMP, rhs, lhs); |
| 3902 | } else { |
| 3903 | __ CmpLtS(FTMP, rhs, lhs); |
| 3904 | } |
| 3905 | __ Mfc1(dst, FTMP); |
| 3906 | __ Andi(dst, dst, 1); |
| 3907 | break; |
| 3908 | case kCondGE: |
| 3909 | if (gt_bias) { |
| 3910 | __ CmpUleS(FTMP, rhs, lhs); |
| 3911 | } else { |
| 3912 | __ CmpLeS(FTMP, rhs, lhs); |
| 3913 | } |
| 3914 | __ Mfc1(dst, FTMP); |
| 3915 | __ Andi(dst, dst, 1); |
| 3916 | break; |
| 3917 | default: |
| 3918 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3919 | UNREACHABLE(); |
| 3920 | } |
| 3921 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3922 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3923 | switch (cond) { |
| 3924 | case kCondEQ: |
| 3925 | __ CmpEqD(FTMP, lhs, rhs); |
| 3926 | __ Mfc1(dst, FTMP); |
| 3927 | __ Andi(dst, dst, 1); |
| 3928 | break; |
| 3929 | case kCondNE: |
| 3930 | __ CmpEqD(FTMP, lhs, rhs); |
| 3931 | __ Mfc1(dst, FTMP); |
| 3932 | __ Addiu(dst, dst, 1); |
| 3933 | break; |
| 3934 | case kCondLT: |
| 3935 | if (gt_bias) { |
| 3936 | __ CmpLtD(FTMP, lhs, rhs); |
| 3937 | } else { |
| 3938 | __ CmpUltD(FTMP, lhs, rhs); |
| 3939 | } |
| 3940 | __ Mfc1(dst, FTMP); |
| 3941 | __ Andi(dst, dst, 1); |
| 3942 | break; |
| 3943 | case kCondLE: |
| 3944 | if (gt_bias) { |
| 3945 | __ CmpLeD(FTMP, lhs, rhs); |
| 3946 | } else { |
| 3947 | __ CmpUleD(FTMP, lhs, rhs); |
| 3948 | } |
| 3949 | __ Mfc1(dst, FTMP); |
| 3950 | __ Andi(dst, dst, 1); |
| 3951 | break; |
| 3952 | case kCondGT: |
| 3953 | if (gt_bias) { |
| 3954 | __ CmpUltD(FTMP, rhs, lhs); |
| 3955 | } else { |
| 3956 | __ CmpLtD(FTMP, rhs, lhs); |
| 3957 | } |
| 3958 | __ Mfc1(dst, FTMP); |
| 3959 | __ Andi(dst, dst, 1); |
| 3960 | break; |
| 3961 | case kCondGE: |
| 3962 | if (gt_bias) { |
| 3963 | __ CmpUleD(FTMP, rhs, lhs); |
| 3964 | } else { |
| 3965 | __ CmpLeD(FTMP, rhs, lhs); |
| 3966 | } |
| 3967 | __ Mfc1(dst, FTMP); |
| 3968 | __ Andi(dst, dst, 1); |
| 3969 | break; |
| 3970 | default: |
| 3971 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3972 | UNREACHABLE(); |
| 3973 | } |
| 3974 | } |
| 3975 | } |
| 3976 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3977 | bool InstructionCodeGeneratorMIPS64::MaterializeFpCompare(IfCondition cond, |
| 3978 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3979 | DataType::Type type, |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3980 | LocationSummary* input_locations, |
| 3981 | FpuRegister dst) { |
| 3982 | FpuRegister lhs = input_locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3983 | FpuRegister rhs = input_locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3984 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3985 | switch (cond) { |
| 3986 | case kCondEQ: |
| 3987 | __ CmpEqS(dst, lhs, rhs); |
| 3988 | return false; |
| 3989 | case kCondNE: |
| 3990 | __ CmpEqS(dst, lhs, rhs); |
| 3991 | return true; |
| 3992 | case kCondLT: |
| 3993 | if (gt_bias) { |
| 3994 | __ CmpLtS(dst, lhs, rhs); |
| 3995 | } else { |
| 3996 | __ CmpUltS(dst, lhs, rhs); |
| 3997 | } |
| 3998 | return false; |
| 3999 | case kCondLE: |
| 4000 | if (gt_bias) { |
| 4001 | __ CmpLeS(dst, lhs, rhs); |
| 4002 | } else { |
| 4003 | __ CmpUleS(dst, lhs, rhs); |
| 4004 | } |
| 4005 | return false; |
| 4006 | case kCondGT: |
| 4007 | if (gt_bias) { |
| 4008 | __ CmpUltS(dst, rhs, lhs); |
| 4009 | } else { |
| 4010 | __ CmpLtS(dst, rhs, lhs); |
| 4011 | } |
| 4012 | return false; |
| 4013 | case kCondGE: |
| 4014 | if (gt_bias) { |
| 4015 | __ CmpUleS(dst, rhs, lhs); |
| 4016 | } else { |
| 4017 | __ CmpLeS(dst, rhs, lhs); |
| 4018 | } |
| 4019 | return false; |
| 4020 | default: |
| 4021 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4022 | UNREACHABLE(); |
| 4023 | } |
| 4024 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4025 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4026 | switch (cond) { |
| 4027 | case kCondEQ: |
| 4028 | __ CmpEqD(dst, lhs, rhs); |
| 4029 | return false; |
| 4030 | case kCondNE: |
| 4031 | __ CmpEqD(dst, lhs, rhs); |
| 4032 | return true; |
| 4033 | case kCondLT: |
| 4034 | if (gt_bias) { |
| 4035 | __ CmpLtD(dst, lhs, rhs); |
| 4036 | } else { |
| 4037 | __ CmpUltD(dst, lhs, rhs); |
| 4038 | } |
| 4039 | return false; |
| 4040 | case kCondLE: |
| 4041 | if (gt_bias) { |
| 4042 | __ CmpLeD(dst, lhs, rhs); |
| 4043 | } else { |
| 4044 | __ CmpUleD(dst, lhs, rhs); |
| 4045 | } |
| 4046 | return false; |
| 4047 | case kCondGT: |
| 4048 | if (gt_bias) { |
| 4049 | __ CmpUltD(dst, rhs, lhs); |
| 4050 | } else { |
| 4051 | __ CmpLtD(dst, rhs, lhs); |
| 4052 | } |
| 4053 | return false; |
| 4054 | case kCondGE: |
| 4055 | if (gt_bias) { |
| 4056 | __ CmpUleD(dst, rhs, lhs); |
| 4057 | } else { |
| 4058 | __ CmpLeD(dst, rhs, lhs); |
| 4059 | } |
| 4060 | return false; |
| 4061 | default: |
| 4062 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4063 | UNREACHABLE(); |
| 4064 | } |
| 4065 | } |
| 4066 | } |
| 4067 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4068 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 4069 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4070 | DataType::Type type, |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4071 | LocationSummary* locations, |
| 4072 | Mips64Label* label) { |
| 4073 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4074 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4075 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4076 | switch (cond) { |
| 4077 | case kCondEQ: |
| 4078 | __ CmpEqS(FTMP, lhs, rhs); |
| 4079 | __ Bc1nez(FTMP, label); |
| 4080 | break; |
| 4081 | case kCondNE: |
| 4082 | __ CmpEqS(FTMP, lhs, rhs); |
| 4083 | __ Bc1eqz(FTMP, label); |
| 4084 | break; |
| 4085 | case kCondLT: |
| 4086 | if (gt_bias) { |
| 4087 | __ CmpLtS(FTMP, lhs, rhs); |
| 4088 | } else { |
| 4089 | __ CmpUltS(FTMP, lhs, rhs); |
| 4090 | } |
| 4091 | __ Bc1nez(FTMP, label); |
| 4092 | break; |
| 4093 | case kCondLE: |
| 4094 | if (gt_bias) { |
| 4095 | __ CmpLeS(FTMP, lhs, rhs); |
| 4096 | } else { |
| 4097 | __ CmpUleS(FTMP, lhs, rhs); |
| 4098 | } |
| 4099 | __ Bc1nez(FTMP, label); |
| 4100 | break; |
| 4101 | case kCondGT: |
| 4102 | if (gt_bias) { |
| 4103 | __ CmpUltS(FTMP, rhs, lhs); |
| 4104 | } else { |
| 4105 | __ CmpLtS(FTMP, rhs, lhs); |
| 4106 | } |
| 4107 | __ Bc1nez(FTMP, label); |
| 4108 | break; |
| 4109 | case kCondGE: |
| 4110 | if (gt_bias) { |
| 4111 | __ CmpUleS(FTMP, rhs, lhs); |
| 4112 | } else { |
| 4113 | __ CmpLeS(FTMP, rhs, lhs); |
| 4114 | } |
| 4115 | __ Bc1nez(FTMP, label); |
| 4116 | break; |
| 4117 | default: |
| 4118 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4119 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4120 | } |
| 4121 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4122 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4123 | switch (cond) { |
| 4124 | case kCondEQ: |
| 4125 | __ CmpEqD(FTMP, lhs, rhs); |
| 4126 | __ Bc1nez(FTMP, label); |
| 4127 | break; |
| 4128 | case kCondNE: |
| 4129 | __ CmpEqD(FTMP, lhs, rhs); |
| 4130 | __ Bc1eqz(FTMP, label); |
| 4131 | break; |
| 4132 | case kCondLT: |
| 4133 | if (gt_bias) { |
| 4134 | __ CmpLtD(FTMP, lhs, rhs); |
| 4135 | } else { |
| 4136 | __ CmpUltD(FTMP, lhs, rhs); |
| 4137 | } |
| 4138 | __ Bc1nez(FTMP, label); |
| 4139 | break; |
| 4140 | case kCondLE: |
| 4141 | if (gt_bias) { |
| 4142 | __ CmpLeD(FTMP, lhs, rhs); |
| 4143 | } else { |
| 4144 | __ CmpUleD(FTMP, lhs, rhs); |
| 4145 | } |
| 4146 | __ Bc1nez(FTMP, label); |
| 4147 | break; |
| 4148 | case kCondGT: |
| 4149 | if (gt_bias) { |
| 4150 | __ CmpUltD(FTMP, rhs, lhs); |
| 4151 | } else { |
| 4152 | __ CmpLtD(FTMP, rhs, lhs); |
| 4153 | } |
| 4154 | __ Bc1nez(FTMP, label); |
| 4155 | break; |
| 4156 | case kCondGE: |
| 4157 | if (gt_bias) { |
| 4158 | __ CmpUleD(FTMP, rhs, lhs); |
| 4159 | } else { |
| 4160 | __ CmpLeD(FTMP, rhs, lhs); |
| 4161 | } |
| 4162 | __ Bc1nez(FTMP, label); |
| 4163 | break; |
| 4164 | default: |
| 4165 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4166 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4167 | } |
| 4168 | } |
| 4169 | } |
| 4170 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4171 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4172 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4173 | Mips64Label* true_target, |
| 4174 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4175 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4176 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4177 | if (true_target == nullptr && false_target == nullptr) { |
| 4178 | // Nothing to do. The code always falls through. |
| 4179 | return; |
| 4180 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4181 | // Constant condition, statically compared against "true" (integer value 1). |
| 4182 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4183 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4184 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4185 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4186 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4187 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4188 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4189 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4190 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4191 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4192 | return; |
| 4193 | } |
| 4194 | |
| 4195 | // The following code generates these patterns: |
| 4196 | // (1) true_target == nullptr && false_target != nullptr |
| 4197 | // - opposite condition true => branch to false_target |
| 4198 | // (2) true_target != nullptr && false_target == nullptr |
| 4199 | // - condition true => branch to true_target |
| 4200 | // (3) true_target != nullptr && false_target != nullptr |
| 4201 | // - condition true => branch to true_target |
| 4202 | // - branch to false_target |
| 4203 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4204 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4205 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4206 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4207 | if (true_target == nullptr) { |
| 4208 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 4209 | } else { |
| 4210 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 4211 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4212 | } else { |
| 4213 | // The condition instruction has not been materialized, use its inputs as |
| 4214 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4215 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4216 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4217 | LocationSummary* locations = cond->GetLocations(); |
| 4218 | IfCondition if_cond = condition->GetCondition(); |
| 4219 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4220 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4221 | if (true_target == nullptr) { |
| 4222 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4223 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4224 | } |
| 4225 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4226 | switch (type) { |
| 4227 | default: |
| 4228 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 4229 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4230 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4231 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 4232 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4233 | case DataType::Type::kFloat32: |
| 4234 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4235 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4236 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4237 | } |
| 4238 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4239 | |
| 4240 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4241 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4242 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4243 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4244 | } |
| 4245 | } |
| 4246 | |
| 4247 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4248 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4249 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4250 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4251 | } |
| 4252 | } |
| 4253 | |
| 4254 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4255 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4256 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4257 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4258 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4259 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4260 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4261 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4265 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4266 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 4267 | InvokeRuntimeCallingConvention calling_convention; |
| 4268 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4269 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4270 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4271 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4272 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4277 | SlowPathCodeMIPS64* slow_path = |
| 4278 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4279 | GenerateTestAndBranch(deoptimize, |
| 4280 | /* condition_input_index */ 0, |
| 4281 | slow_path->GetEntryLabel(), |
| 4282 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4283 | } |
| 4284 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4285 | // This function returns true if a conditional move can be generated for HSelect. |
| 4286 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4287 | // branches and regular moves. |
| 4288 | // |
| 4289 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4290 | // |
| 4291 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4292 | // are two distinct tasks, this function does both because they share quite a bit |
| 4293 | // of common logic. |
| 4294 | static bool CanMoveConditionally(HSelect* select, LocationSummary* locations_to_set) { |
| 4295 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4296 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4297 | HCondition* condition = cond->AsCondition(); |
| 4298 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4299 | DataType::Type cond_type = |
| 4300 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 4301 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4302 | |
| 4303 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4304 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4305 | bool is_true_value_zero_constant = |
| 4306 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4307 | bool is_false_value_zero_constant = |
| 4308 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4309 | |
| 4310 | bool can_move_conditionally = false; |
| 4311 | bool use_const_for_false_in = false; |
| 4312 | bool use_const_for_true_in = false; |
| 4313 | |
| 4314 | if (!cond->IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4315 | if (!DataType::IsFloatingPointType(cond_type)) { |
| 4316 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4317 | // Moving int/long on int/long condition. |
| 4318 | if (is_true_value_zero_constant) { |
| 4319 | // seleqz out_reg, false_reg, cond_reg |
| 4320 | can_move_conditionally = true; |
| 4321 | use_const_for_true_in = true; |
| 4322 | } else if (is_false_value_zero_constant) { |
| 4323 | // selnez out_reg, true_reg, cond_reg |
| 4324 | can_move_conditionally = true; |
| 4325 | use_const_for_false_in = true; |
| 4326 | } else if (materialized) { |
| 4327 | // Not materializing unmaterialized int conditions |
| 4328 | // to keep the instruction count low. |
| 4329 | // selnez AT, true_reg, cond_reg |
| 4330 | // seleqz TMP, false_reg, cond_reg |
| 4331 | // or out_reg, AT, TMP |
| 4332 | can_move_conditionally = true; |
| 4333 | } |
| 4334 | } else { |
| 4335 | // Moving float/double on int/long condition. |
| 4336 | if (materialized) { |
| 4337 | // Not materializing unmaterialized int conditions |
| 4338 | // to keep the instruction count low. |
| 4339 | can_move_conditionally = true; |
| 4340 | if (is_true_value_zero_constant) { |
| 4341 | // sltu TMP, ZERO, cond_reg |
| 4342 | // mtc1 TMP, temp_cond_reg |
| 4343 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4344 | use_const_for_true_in = true; |
| 4345 | } else if (is_false_value_zero_constant) { |
| 4346 | // sltu TMP, ZERO, cond_reg |
| 4347 | // mtc1 TMP, temp_cond_reg |
| 4348 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4349 | use_const_for_false_in = true; |
| 4350 | } else { |
| 4351 | // sltu TMP, ZERO, cond_reg |
| 4352 | // mtc1 TMP, temp_cond_reg |
| 4353 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4354 | // mov.fmt out_reg, temp_cond_reg |
| 4355 | } |
| 4356 | } |
| 4357 | } |
| 4358 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4359 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4360 | // Moving int/long on float/double condition. |
| 4361 | can_move_conditionally = true; |
| 4362 | if (is_true_value_zero_constant) { |
| 4363 | // mfc1 TMP, temp_cond_reg |
| 4364 | // seleqz out_reg, false_reg, TMP |
| 4365 | use_const_for_true_in = true; |
| 4366 | } else if (is_false_value_zero_constant) { |
| 4367 | // mfc1 TMP, temp_cond_reg |
| 4368 | // selnez out_reg, true_reg, TMP |
| 4369 | use_const_for_false_in = true; |
| 4370 | } else { |
| 4371 | // mfc1 TMP, temp_cond_reg |
| 4372 | // selnez AT, true_reg, TMP |
| 4373 | // seleqz TMP, false_reg, TMP |
| 4374 | // or out_reg, AT, TMP |
| 4375 | } |
| 4376 | } else { |
| 4377 | // Moving float/double on float/double condition. |
| 4378 | can_move_conditionally = true; |
| 4379 | if (is_true_value_zero_constant) { |
| 4380 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4381 | use_const_for_true_in = true; |
| 4382 | } else if (is_false_value_zero_constant) { |
| 4383 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4384 | use_const_for_false_in = true; |
| 4385 | } else { |
| 4386 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4387 | // mov.fmt out_reg, temp_cond_reg |
| 4388 | } |
| 4389 | } |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | if (can_move_conditionally) { |
| 4394 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4395 | } else { |
| 4396 | DCHECK(!use_const_for_false_in); |
| 4397 | DCHECK(!use_const_for_true_in); |
| 4398 | } |
| 4399 | |
| 4400 | if (locations_to_set != nullptr) { |
| 4401 | if (use_const_for_false_in) { |
| 4402 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4403 | } else { |
| 4404 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4405 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4406 | ? Location::RequiresFpuRegister() |
| 4407 | : Location::RequiresRegister()); |
| 4408 | } |
| 4409 | if (use_const_for_true_in) { |
| 4410 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4411 | } else { |
| 4412 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4413 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4414 | ? Location::RequiresFpuRegister() |
| 4415 | : Location::RequiresRegister()); |
| 4416 | } |
| 4417 | if (materialized) { |
| 4418 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4419 | } |
| 4420 | |
| 4421 | if (can_move_conditionally) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4422 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4423 | ? Location::RequiresFpuRegister() |
| 4424 | : Location::RequiresRegister()); |
| 4425 | } else { |
| 4426 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | return can_move_conditionally; |
| 4431 | } |
| 4432 | |
| 4433 | |
| 4434 | void InstructionCodeGeneratorMIPS64::GenConditionalMove(HSelect* select) { |
| 4435 | LocationSummary* locations = select->GetLocations(); |
| 4436 | Location dst = locations->Out(); |
| 4437 | Location false_src = locations->InAt(0); |
| 4438 | Location true_src = locations->InAt(1); |
| 4439 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4440 | GpuRegister cond_reg = TMP; |
| 4441 | FpuRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4442 | DataType::Type cond_type = DataType::Type::kInt32; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4443 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4444 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4445 | |
| 4446 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4447 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<GpuRegister>(); |
| 4448 | } else { |
| 4449 | HCondition* condition = cond->AsCondition(); |
| 4450 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4451 | IfCondition if_cond = condition->GetCondition(); |
| 4452 | cond_type = condition->InputAt(0)->GetType(); |
| 4453 | switch (cond_type) { |
| 4454 | default: |
| 4455 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4456 | /* is64bit */ false, |
| 4457 | cond_locations, |
| 4458 | cond_reg); |
| 4459 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4460 | case DataType::Type::kInt64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4461 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4462 | /* is64bit */ true, |
| 4463 | cond_locations, |
| 4464 | cond_reg); |
| 4465 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4466 | case DataType::Type::kFloat32: |
| 4467 | case DataType::Type::kFloat64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4468 | cond_inverted = MaterializeFpCompare(if_cond, |
| 4469 | condition->IsGtBias(), |
| 4470 | cond_type, |
| 4471 | cond_locations, |
| 4472 | fcond_reg); |
| 4473 | break; |
| 4474 | } |
| 4475 | } |
| 4476 | |
| 4477 | if (true_src.IsConstant()) { |
| 4478 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4479 | } |
| 4480 | if (false_src.IsConstant()) { |
| 4481 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4482 | } |
| 4483 | |
| 4484 | switch (dst_type) { |
| 4485 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4486 | if (DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4487 | __ Mfc1(cond_reg, fcond_reg); |
| 4488 | } |
| 4489 | if (true_src.IsConstant()) { |
| 4490 | if (cond_inverted) { |
| 4491 | __ Selnez(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4492 | } else { |
| 4493 | __ Seleqz(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4494 | } |
| 4495 | } else if (false_src.IsConstant()) { |
| 4496 | if (cond_inverted) { |
| 4497 | __ Seleqz(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4498 | } else { |
| 4499 | __ Selnez(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4500 | } |
| 4501 | } else { |
| 4502 | DCHECK_NE(cond_reg, AT); |
| 4503 | if (cond_inverted) { |
| 4504 | __ Seleqz(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4505 | __ Selnez(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4506 | } else { |
| 4507 | __ Selnez(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4508 | __ Seleqz(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4509 | } |
| 4510 | __ Or(dst.AsRegister<GpuRegister>(), AT, TMP); |
| 4511 | } |
| 4512 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4513 | case DataType::Type::kFloat32: { |
| 4514 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4515 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4516 | __ Sltu(TMP, ZERO, cond_reg); |
| 4517 | __ Mtc1(TMP, fcond_reg); |
| 4518 | } |
| 4519 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4520 | if (true_src.IsConstant()) { |
| 4521 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4522 | if (cond_inverted) { |
| 4523 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4524 | } else { |
| 4525 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4526 | } |
| 4527 | } else if (false_src.IsConstant()) { |
| 4528 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4529 | if (cond_inverted) { |
| 4530 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4531 | } else { |
| 4532 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4533 | } |
| 4534 | } else { |
| 4535 | if (cond_inverted) { |
| 4536 | __ SelS(fcond_reg, |
| 4537 | true_src.AsFpuRegister<FpuRegister>(), |
| 4538 | false_src.AsFpuRegister<FpuRegister>()); |
| 4539 | } else { |
| 4540 | __ SelS(fcond_reg, |
| 4541 | false_src.AsFpuRegister<FpuRegister>(), |
| 4542 | true_src.AsFpuRegister<FpuRegister>()); |
| 4543 | } |
| 4544 | __ MovS(dst_reg, fcond_reg); |
| 4545 | } |
| 4546 | break; |
| 4547 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4548 | case DataType::Type::kFloat64: { |
| 4549 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4550 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4551 | __ Sltu(TMP, ZERO, cond_reg); |
| 4552 | __ Mtc1(TMP, fcond_reg); |
| 4553 | } |
| 4554 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4555 | if (true_src.IsConstant()) { |
| 4556 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4557 | if (cond_inverted) { |
| 4558 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4559 | } else { |
| 4560 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4561 | } |
| 4562 | } else if (false_src.IsConstant()) { |
| 4563 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4564 | if (cond_inverted) { |
| 4565 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4566 | } else { |
| 4567 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4568 | } |
| 4569 | } else { |
| 4570 | if (cond_inverted) { |
| 4571 | __ SelD(fcond_reg, |
| 4572 | true_src.AsFpuRegister<FpuRegister>(), |
| 4573 | false_src.AsFpuRegister<FpuRegister>()); |
| 4574 | } else { |
| 4575 | __ SelD(fcond_reg, |
| 4576 | false_src.AsFpuRegister<FpuRegister>(), |
| 4577 | true_src.AsFpuRegister<FpuRegister>()); |
| 4578 | } |
| 4579 | __ MovD(dst_reg, fcond_reg); |
| 4580 | } |
| 4581 | break; |
| 4582 | } |
| 4583 | } |
| 4584 | } |
| 4585 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4586 | void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4587 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4588 | LocationSummary(flag, LocationSummary::kNoCall); |
| 4589 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4590 | } |
| 4591 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4592 | void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4593 | __ LoadFromOffset(kLoadWord, |
| 4594 | flag->GetLocations()->Out().AsRegister<GpuRegister>(), |
| 4595 | SP, |
| 4596 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4597 | } |
| 4598 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4599 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4600 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4601 | CanMoveConditionally(select, locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4605 | if (CanMoveConditionally(select, /* locations_to_set */ nullptr)) { |
| 4606 | GenConditionalMove(select); |
| 4607 | } else { |
| 4608 | LocationSummary* locations = select->GetLocations(); |
| 4609 | Mips64Label false_target; |
| 4610 | GenerateTestAndBranch(select, |
| 4611 | /* condition_input_index */ 2, |
| 4612 | /* true_target */ nullptr, |
| 4613 | &false_target); |
| 4614 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4615 | __ Bind(&false_target); |
| 4616 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4619 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4620 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4621 | } |
| 4622 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4623 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4624 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | void CodeGeneratorMIPS64::GenerateNop() { |
| 4628 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4631 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4632 | const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4633 | DataType::Type field_type = field_info.GetFieldType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4634 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4635 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4636 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4637 | instruction, |
| 4638 | object_field_get_with_read_barrier |
| 4639 | ? LocationSummary::kCallOnSlowPath |
| 4640 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4641 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4642 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4643 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4644 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4645 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4646 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4647 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4648 | // The output overlaps in the case of an object field get with |
| 4649 | // read barriers enabled: we do not want the move to overwrite the |
| 4650 | // object's location, as we need it to emit the read barrier. |
| 4651 | locations->SetOut(Location::RequiresRegister(), |
| 4652 | object_field_get_with_read_barrier |
| 4653 | ? Location::kOutputOverlap |
| 4654 | : Location::kNoOutputOverlap); |
| 4655 | } |
| 4656 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4657 | // We need a temporary register for the read barrier marking slow |
| 4658 | // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4659 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 4660 | locations->AddTemp(Location::RequiresRegister()); |
| 4661 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4662 | } |
| 4663 | } |
| 4664 | |
| 4665 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 4666 | const FieldInfo& field_info) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4667 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4668 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4669 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4670 | Location obj_loc = locations->InAt(0); |
| 4671 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 4672 | Location dst_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4673 | LoadOperandType load_type = kLoadUnsignedByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4674 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4675 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4676 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4677 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4678 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4679 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4680 | case DataType::Type::kUint8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4681 | load_type = kLoadUnsignedByte; |
| 4682 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4683 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4684 | load_type = kLoadSignedByte; |
| 4685 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4686 | case DataType::Type::kUint16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4687 | load_type = kLoadUnsignedHalfword; |
| 4688 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4689 | case DataType::Type::kInt16: |
| 4690 | load_type = kLoadSignedHalfword; |
| 4691 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4692 | case DataType::Type::kInt32: |
| 4693 | case DataType::Type::kFloat32: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4694 | load_type = kLoadWord; |
| 4695 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4696 | case DataType::Type::kInt64: |
| 4697 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4698 | load_type = kLoadDoubleword; |
| 4699 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4700 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4701 | load_type = kLoadUnsignedWord; |
| 4702 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4703 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4704 | LOG(FATAL) << "Unreachable type " << type; |
| 4705 | UNREACHABLE(); |
| 4706 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4707 | if (!DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4708 | DCHECK(dst_loc.IsRegister()); |
| 4709 | GpuRegister dst = dst_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4710 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4711 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 4712 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4713 | Location temp_loc = |
| 4714 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4715 | // Note that a potential implicit null check is handled in this |
| 4716 | // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4717 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4718 | dst_loc, |
| 4719 | obj, |
| 4720 | offset, |
| 4721 | temp_loc, |
| 4722 | /* needs_null_check */ true); |
| 4723 | if (is_volatile) { |
| 4724 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4725 | } |
| 4726 | } else { |
| 4727 | __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker); |
| 4728 | if (is_volatile) { |
| 4729 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4730 | } |
| 4731 | // If read barriers are enabled, emit read barriers other than |
| 4732 | // Baker's using a slow path (and also unpoison the loaded |
| 4733 | // reference, if heap poisoning is enabled). |
| 4734 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 4735 | } |
| 4736 | } else { |
| 4737 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
| 4738 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4739 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4740 | DCHECK(dst_loc.IsFpuRegister()); |
| 4741 | FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4742 | __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4743 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4744 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4745 | // Memory barriers, in the case of references, are handled in the |
| 4746 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4747 | if (is_volatile && (type != DataType::Type::kReference)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4748 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4749 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 4753 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 4754 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4755 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4756 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4757 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4758 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4759 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4760 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4761 | } |
| 4762 | } |
| 4763 | |
| 4764 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4765 | const FieldInfo& field_info, |
| 4766 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4767 | DataType::Type type = field_info.GetFieldType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4768 | LocationSummary* locations = instruction->GetLocations(); |
| 4769 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4770 | Location value_location = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4771 | StoreOperandType store_type = kStoreByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4772 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4773 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4774 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4775 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4776 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4777 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4778 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4779 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4780 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4781 | store_type = kStoreByte; |
| 4782 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4783 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4784 | case DataType::Type::kInt16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4785 | store_type = kStoreHalfword; |
| 4786 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4787 | case DataType::Type::kInt32: |
| 4788 | case DataType::Type::kFloat32: |
| 4789 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4790 | store_type = kStoreWord; |
| 4791 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4792 | case DataType::Type::kInt64: |
| 4793 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4794 | store_type = kStoreDoubleword; |
| 4795 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4796 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4797 | LOG(FATAL) << "Unreachable type " << type; |
| 4798 | UNREACHABLE(); |
| 4799 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4800 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4801 | if (is_volatile) { |
| 4802 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4803 | } |
| 4804 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4805 | if (value_location.IsConstant()) { |
| 4806 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4807 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4808 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4809 | if (!DataType::IsFloatingPointType(type)) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4810 | DCHECK(value_location.IsRegister()); |
| 4811 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
| 4812 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4813 | // Note that in the case where `value` is a null reference, |
| 4814 | // we do not enter this block, as a null reference does not |
| 4815 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4816 | DCHECK_EQ(type, DataType::Type::kReference); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4817 | __ PoisonHeapReference(TMP, src); |
| 4818 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 4819 | } else { |
| 4820 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 4821 | } |
| 4822 | } else { |
| 4823 | DCHECK(value_location.IsFpuRegister()); |
| 4824 | FpuRegister src = value_location.AsFpuRegister<FpuRegister>(); |
| 4825 | __ StoreFpuToOffset(store_type, src, obj, offset, null_checker); |
| 4826 | } |
| 4827 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4828 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4829 | if (needs_write_barrier) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4830 | DCHECK(value_location.IsRegister()); |
| 4831 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4832 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4833 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4834 | |
| 4835 | if (is_volatile) { |
| 4836 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4837 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4841 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4842 | } |
| 4843 | |
| 4844 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4845 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4846 | } |
| 4847 | |
| 4848 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4849 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4850 | } |
| 4851 | |
| 4852 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4853 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4856 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister( |
| 4857 | HInstruction* instruction, |
| 4858 | Location out, |
| 4859 | uint32_t offset, |
| 4860 | Location maybe_temp, |
| 4861 | ReadBarrierOption read_barrier_option) { |
| 4862 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4863 | if (read_barrier_option == kWithReadBarrier) { |
| 4864 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4865 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 4866 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4867 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4868 | if (kUseBakerReadBarrier) { |
| 4869 | // Load with fast path based Baker's read barrier. |
| 4870 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4871 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4872 | out, |
| 4873 | out_reg, |
| 4874 | offset, |
| 4875 | maybe_temp, |
| 4876 | /* needs_null_check */ false); |
| 4877 | } else { |
| 4878 | // Load with slow path based read barrier. |
| 4879 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4880 | // in the following move operation, as we will need it for the |
| 4881 | // read barrier below. |
| 4882 | __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg); |
| 4883 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4884 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4885 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4886 | } |
| 4887 | } else { |
| 4888 | // Plain load with no read barrier. |
| 4889 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4890 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4891 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4892 | } |
| 4893 | } |
| 4894 | |
| 4895 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters( |
| 4896 | HInstruction* instruction, |
| 4897 | Location out, |
| 4898 | Location obj, |
| 4899 | uint32_t offset, |
| 4900 | Location maybe_temp, |
| 4901 | ReadBarrierOption read_barrier_option) { |
| 4902 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4903 | GpuRegister obj_reg = obj.AsRegister<GpuRegister>(); |
| 4904 | if (read_barrier_option == kWithReadBarrier) { |
| 4905 | CHECK(kEmitCompilerReadBarrier); |
| 4906 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4907 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 4908 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4909 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4910 | // Load with fast path based Baker's read barrier. |
| 4911 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4912 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4913 | out, |
| 4914 | obj_reg, |
| 4915 | offset, |
| 4916 | maybe_temp, |
| 4917 | /* needs_null_check */ false); |
| 4918 | } else { |
| 4919 | // Load with slow path based read barrier. |
| 4920 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4921 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4922 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 4923 | } |
| 4924 | } else { |
| 4925 | // Plain load with no read barrier. |
| 4926 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4927 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4928 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4929 | } |
| 4930 | } |
| 4931 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4932 | static inline int GetBakerMarkThunkNumber(GpuRegister reg) { |
| 4933 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 20, "Expecting equal"); |
| 4934 | if (reg >= V0 && reg <= T2) { // 13 consequtive regs. |
| 4935 | return reg - V0; |
| 4936 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 4937 | return 13 + (reg - S2); |
| 4938 | } else if (reg == S8) { // One more. |
| 4939 | return 19; |
| 4940 | } |
| 4941 | LOG(FATAL) << "Unexpected register " << reg; |
| 4942 | UNREACHABLE(); |
| 4943 | } |
| 4944 | |
| 4945 | static inline int GetBakerMarkFieldArrayThunkDisplacement(GpuRegister reg, bool short_offset) { |
| 4946 | int num = GetBakerMarkThunkNumber(reg) + |
| 4947 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 4948 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 4949 | } |
| 4950 | |
| 4951 | static inline int GetBakerMarkGcRootThunkDisplacement(GpuRegister reg) { |
| 4952 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 4953 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 4954 | } |
| 4955 | |
| 4956 | void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 4957 | Location root, |
| 4958 | GpuRegister obj, |
| 4959 | uint32_t offset, |
| 4960 | ReadBarrierOption read_barrier_option, |
| 4961 | Mips64Label* label_low) { |
| 4962 | if (label_low != nullptr) { |
| 4963 | DCHECK_EQ(offset, 0x5678u); |
| 4964 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4965 | GpuRegister root_reg = root.AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4966 | if (read_barrier_option == kWithReadBarrier) { |
| 4967 | DCHECK(kEmitCompilerReadBarrier); |
| 4968 | if (kUseBakerReadBarrier) { |
| 4969 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 4970 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4971 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 4972 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 4973 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 4974 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 4975 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 4976 | // vice versa. |
| 4977 | // |
| 4978 | // We use thunks for the slow path. That thunk checks the reference |
| 4979 | // and jumps to the entrypoint if needed. |
| 4980 | // |
| 4981 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 4982 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 4983 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 4984 | // if (temp != nullptr) { |
| 4985 | // temp = &gc_root_thunk<root_reg> |
| 4986 | // root = temp(root) |
| 4987 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4988 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4989 | const int32_t entry_point_offset = |
| 4990 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 4991 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 4992 | int16_t offset_low = Low16Bits(offset); |
| 4993 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 4994 | // extension in lwu. |
| 4995 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 4996 | GpuRegister base = short_offset ? obj : TMP; |
| 4997 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 4998 | // threads are suspended or running a checkpoint. |
| 4999 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5000 | if (!short_offset) { |
| 5001 | DCHECK(!label_low); |
| 5002 | __ Daui(base, obj, offset_high); |
| 5003 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5004 | Mips64Label skip_call; |
| 5005 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5006 | if (label_low != nullptr) { |
| 5007 | DCHECK(short_offset); |
| 5008 | __ Bind(label_low); |
| 5009 | } |
| 5010 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5011 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, base, offset_low); // Single instruction |
| 5012 | // in delay slot. |
| 5013 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5014 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5015 | } else { |
| 5016 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5017 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5018 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 5019 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 5020 | // is false, and vice versa. |
| 5021 | // |
| 5022 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5023 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5024 | // if (temp != null) { |
| 5025 | // root = temp(root) |
| 5026 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5027 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5028 | if (label_low != nullptr) { |
| 5029 | __ Bind(label_low); |
| 5030 | } |
| 5031 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5032 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5033 | static_assert( |
| 5034 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5035 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5036 | "have different sizes."); |
| 5037 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5038 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5039 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5040 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5041 | // Slow path marking the GC root `root`. |
| 5042 | Location temp = Location::RegisterLocation(T9); |
| 5043 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5044 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5045 | instruction, |
| 5046 | root, |
| 5047 | /*entrypoint*/ temp); |
| 5048 | codegen_->AddSlowPath(slow_path); |
| 5049 | |
| 5050 | const int32_t entry_point_offset = |
| 5051 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1); |
| 5052 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5053 | // threads are suspended or running a checkpoint. |
| 5054 | __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset); |
| 5055 | __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 5056 | __ Bind(slow_path->GetExitLabel()); |
| 5057 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5058 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5059 | if (label_low != nullptr) { |
| 5060 | __ Bind(label_low); |
| 5061 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5062 | // GC root loaded through a slow path for read barriers other |
| 5063 | // than Baker's. |
| 5064 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 5065 | __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset)); |
| 5066 | // /* mirror::Object* */ root = root->Read() |
| 5067 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5068 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5069 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5070 | if (label_low != nullptr) { |
| 5071 | __ Bind(label_low); |
| 5072 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5073 | // Plain GC root load with no read barrier. |
| 5074 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5075 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5076 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5077 | // do not have to unpoison `root_reg` here. |
| 5078 | } |
| 5079 | } |
| 5080 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5081 | void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5082 | Location ref, |
| 5083 | GpuRegister obj, |
| 5084 | uint32_t offset, |
| 5085 | Location temp, |
| 5086 | bool needs_null_check) { |
| 5087 | DCHECK(kEmitCompilerReadBarrier); |
| 5088 | DCHECK(kUseBakerReadBarrier); |
| 5089 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5090 | if (kBakerReadBarrierThunksEnableForFields) { |
| 5091 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5092 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5093 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5094 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5095 | // vice versa. |
| 5096 | // |
| 5097 | // We use thunks for the slow path. That thunk checks the reference |
| 5098 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5099 | // it issues a load-load memory barrier and returns to the original |
| 5100 | // reference load. |
| 5101 | // |
| 5102 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5103 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5104 | // if (temp != nullptr) { |
| 5105 | // temp = &field_array_thunk<holder_reg> |
| 5106 | // temp() |
| 5107 | // } |
| 5108 | // not_gray_return_address: |
| 5109 | // // If the offset is too large to fit into the lw instruction, we |
| 5110 | // // use an adjusted base register (TMP) here. This register |
| 5111 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 5112 | // // and the thunk benefits from it. |
| 5113 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 5114 | // gray_return_address: |
| 5115 | |
| 5116 | DCHECK(temp.IsInvalid()); |
| 5117 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5118 | const int32_t entry_point_offset = |
| 5119 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5120 | // There may have or may have not been a null check if the field offset is smaller than |
| 5121 | // the page size. |
| 5122 | // There must've been a null check in case it's actually a load from an array. |
| 5123 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 5124 | // do it than not. |
| 5125 | if (instruction->IsArrayGet()) { |
| 5126 | DCHECK(!needs_null_check); |
| 5127 | } |
| 5128 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 5129 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5130 | // threads are suspended or running a checkpoint. |
| 5131 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5132 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5133 | Mips64Label skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5134 | if (short_offset) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5135 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5136 | __ Nop(); // In forbidden slot. |
| 5137 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5138 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5139 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5140 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); // Single instruction. |
| 5141 | } else { |
| 5142 | int16_t offset_low = Low16Bits(offset); |
| 5143 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lwu. |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5144 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5145 | __ Daui(TMP, obj, offset_high); // In delay slot. |
| 5146 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5147 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5148 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5149 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset_low); // Single instruction. |
| 5150 | } |
| 5151 | if (needs_null_check) { |
| 5152 | MaybeRecordImplicitNullCheck(instruction); |
| 5153 | } |
| 5154 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5155 | return; |
| 5156 | } |
| 5157 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5158 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5159 | Location no_index = Location::NoLocation(); |
| 5160 | ScaleFactor no_scale_factor = TIMES_1; |
| 5161 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5162 | ref, |
| 5163 | obj, |
| 5164 | offset, |
| 5165 | no_index, |
| 5166 | no_scale_factor, |
| 5167 | temp, |
| 5168 | needs_null_check); |
| 5169 | } |
| 5170 | |
| 5171 | void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5172 | Location ref, |
| 5173 | GpuRegister obj, |
| 5174 | uint32_t data_offset, |
| 5175 | Location index, |
| 5176 | Location temp, |
| 5177 | bool needs_null_check) { |
| 5178 | DCHECK(kEmitCompilerReadBarrier); |
| 5179 | DCHECK(kUseBakerReadBarrier); |
| 5180 | |
| 5181 | static_assert( |
| 5182 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5183 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5184 | ScaleFactor scale_factor = TIMES_4; |
| 5185 | |
| 5186 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 5187 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5188 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5189 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5190 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5191 | // vice versa. |
| 5192 | // |
| 5193 | // We use thunks for the slow path. That thunk checks the reference |
| 5194 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5195 | // it issues a load-load memory barrier and returns to the original |
| 5196 | // reference load. |
| 5197 | // |
| 5198 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5199 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5200 | // if (temp != nullptr) { |
| 5201 | // temp = &field_array_thunk<holder_reg> |
| 5202 | // temp() |
| 5203 | // } |
| 5204 | // not_gray_return_address: |
| 5205 | // // The element address is pre-calculated in the TMP register before the |
| 5206 | // // thunk invocation and the thunk benefits from it. |
| 5207 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 5208 | // gray_return_address: |
| 5209 | |
| 5210 | DCHECK(temp.IsInvalid()); |
| 5211 | DCHECK(index.IsValid()); |
| 5212 | const int32_t entry_point_offset = |
| 5213 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5214 | // We will not do the explicit null check in the thunk as some form of a null check |
| 5215 | // must've been done earlier. |
| 5216 | DCHECK(!needs_null_check); |
| 5217 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 5218 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5219 | // threads are suspended or running a checkpoint. |
| 5220 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5221 | Mips64Label skip_call; |
| 5222 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5223 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5224 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 5225 | __ Dlsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 5226 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5227 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5228 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 5229 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 5230 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, data_offset); // Single instruction. |
| 5231 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5232 | return; |
| 5233 | } |
| 5234 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5235 | // /* HeapReference<Object> */ ref = |
| 5236 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5237 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5238 | ref, |
| 5239 | obj, |
| 5240 | data_offset, |
| 5241 | index, |
| 5242 | scale_factor, |
| 5243 | temp, |
| 5244 | needs_null_check); |
| 5245 | } |
| 5246 | |
| 5247 | void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5248 | Location ref, |
| 5249 | GpuRegister obj, |
| 5250 | uint32_t offset, |
| 5251 | Location index, |
| 5252 | ScaleFactor scale_factor, |
| 5253 | Location temp, |
| 5254 | bool needs_null_check, |
| 5255 | bool always_update_field) { |
| 5256 | DCHECK(kEmitCompilerReadBarrier); |
| 5257 | DCHECK(kUseBakerReadBarrier); |
| 5258 | |
| 5259 | // In slow path based read barriers, the read barrier call is |
| 5260 | // inserted after the original load. However, in fast path based |
| 5261 | // Baker's read barriers, we need to perform the load of |
| 5262 | // mirror::Object::monitor_ *before* the original reference load. |
| 5263 | // This load-load ordering is required by the read barrier. |
| 5264 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5265 | // |
| 5266 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5267 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5268 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5269 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 5270 | // if (is_gray) { |
| 5271 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5272 | // } |
| 5273 | // |
| 5274 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5275 | // slightly more complex as it performs additional checks that we do |
| 5276 | // not do here for performance reasons. |
| 5277 | |
| 5278 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5279 | GpuRegister temp_reg = temp.AsRegister<GpuRegister>(); |
| 5280 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5281 | |
| 5282 | // /* int32_t */ monitor = obj->monitor_ |
| 5283 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 5284 | if (needs_null_check) { |
| 5285 | MaybeRecordImplicitNullCheck(instruction); |
| 5286 | } |
| 5287 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5288 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5289 | "art::LockWord and int32_t have different sizes."); |
| 5290 | |
| 5291 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 5292 | |
| 5293 | // The actual reference load. |
| 5294 | if (index.IsValid()) { |
| 5295 | // Load types involving an "index": ArrayGet, |
| 5296 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5297 | // intrinsics. |
| 5298 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5299 | if (index.IsConstant()) { |
| 5300 | size_t computed_offset = |
| 5301 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 5302 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset); |
| 5303 | } else { |
| 5304 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 5305 | if (scale_factor == TIMES_1) { |
| 5306 | __ Daddu(TMP, index_reg, obj); |
| 5307 | } else { |
| 5308 | __ Dlsa(TMP, index_reg, obj, scale_factor); |
| 5309 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5310 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset); |
| 5311 | } |
| 5312 | } else { |
| 5313 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5314 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); |
| 5315 | } |
| 5316 | |
| 5317 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5318 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5319 | |
| 5320 | // Slow path marking the object `ref` when it is gray. |
| 5321 | SlowPathCodeMIPS64* slow_path; |
| 5322 | if (always_update_field) { |
| 5323 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address |
| 5324 | // of the form `obj + field_offset`, where `obj` is a register and |
| 5325 | // `field_offset` is a register. Thus `offset` and `scale_factor` |
| 5326 | // above are expected to be null in this code path. |
| 5327 | DCHECK_EQ(offset, 0u); |
| 5328 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5329 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5330 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction, |
| 5331 | ref, |
| 5332 | obj, |
| 5333 | /* field_offset */ index, |
| 5334 | temp_reg); |
| 5335 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5336 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5337 | } |
| 5338 | AddSlowPath(slow_path); |
| 5339 | |
| 5340 | // if (rb_state == ReadBarrier::GrayState()) |
| 5341 | // ref = ReadBarrier::Mark(ref); |
| 5342 | // Given the numeric representation, it's enough to check the low bit of the |
| 5343 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 5344 | // performing a branch on less than zero. |
| 5345 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 5346 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 5347 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 5348 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 5349 | __ Bltzc(temp_reg, slow_path->GetEntryLabel()); |
| 5350 | __ Bind(slow_path->GetExitLabel()); |
| 5351 | } |
| 5352 | |
| 5353 | void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5354 | Location out, |
| 5355 | Location ref, |
| 5356 | Location obj, |
| 5357 | uint32_t offset, |
| 5358 | Location index) { |
| 5359 | DCHECK(kEmitCompilerReadBarrier); |
| 5360 | |
| 5361 | // Insert a slow path based read barrier *after* the reference load. |
| 5362 | // |
| 5363 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5364 | // reference will be carried out by the runtime within the slow |
| 5365 | // path. |
| 5366 | // |
| 5367 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5368 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5369 | // not used by the artReadBarrierSlow entry point. |
| 5370 | // |
| 5371 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5372 | SlowPathCodeMIPS64* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5373 | ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index); |
| 5374 | AddSlowPath(slow_path); |
| 5375 | |
| 5376 | __ Bc(slow_path->GetEntryLabel()); |
| 5377 | __ Bind(slow_path->GetExitLabel()); |
| 5378 | } |
| 5379 | |
| 5380 | void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5381 | Location out, |
| 5382 | Location ref, |
| 5383 | Location obj, |
| 5384 | uint32_t offset, |
| 5385 | Location index) { |
| 5386 | if (kEmitCompilerReadBarrier) { |
| 5387 | // Baker's read barriers shall be handled by the fast path |
| 5388 | // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5389 | DCHECK(!kUseBakerReadBarrier); |
| 5390 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5391 | // by the runtime within the slow path. |
| 5392 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 5393 | } else if (kPoisonHeapReferences) { |
| 5394 | __ UnpoisonHeapReference(out.AsRegister<GpuRegister>()); |
| 5395 | } |
| 5396 | } |
| 5397 | |
| 5398 | void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5399 | Location out, |
| 5400 | Location root) { |
| 5401 | DCHECK(kEmitCompilerReadBarrier); |
| 5402 | |
| 5403 | // Insert a slow path based read barrier *after* the GC root load. |
| 5404 | // |
| 5405 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5406 | // not need to do anything special for this here. |
| 5407 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5408 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5409 | AddSlowPath(slow_path); |
| 5410 | |
| 5411 | __ Bc(slow_path->GetEntryLabel()); |
| 5412 | __ Bind(slow_path->GetExitLabel()); |
| 5413 | } |
| 5414 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5415 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5416 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5417 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5418 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5419 | switch (type_check_kind) { |
| 5420 | case TypeCheckKind::kExactCheck: |
| 5421 | case TypeCheckKind::kAbstractClassCheck: |
| 5422 | case TypeCheckKind::kClassHierarchyCheck: |
| 5423 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5424 | call_kind = |
| 5425 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5426 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5427 | break; |
| 5428 | case TypeCheckKind::kArrayCheck: |
| 5429 | case TypeCheckKind::kUnresolvedCheck: |
| 5430 | case TypeCheckKind::kInterfaceCheck: |
| 5431 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5432 | break; |
| 5433 | } |
| 5434 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5435 | LocationSummary* locations = |
| 5436 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5437 | if (baker_read_barrier_slow_path) { |
| 5438 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5439 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5440 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5441 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5442 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5443 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5444 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5445 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5449 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5450 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5451 | Location obj_loc = locations->InAt(0); |
| 5452 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5453 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5454 | Location out_loc = locations->Out(); |
| 5455 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5456 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 5457 | DCHECK_LE(num_temps, 1u); |
| 5458 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5459 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5460 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5461 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5462 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5463 | Mips64Label done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5464 | SlowPathCodeMIPS64* slow_path = nullptr; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5465 | |
| 5466 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5467 | // Avoid this check if we know `obj` is not null. |
| 5468 | if (instruction->MustDoNullCheck()) { |
| 5469 | __ Move(out, ZERO); |
| 5470 | __ Beqzc(obj, &done); |
| 5471 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5472 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5473 | switch (type_check_kind) { |
| 5474 | case TypeCheckKind::kExactCheck: { |
| 5475 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5476 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5477 | out_loc, |
| 5478 | obj_loc, |
| 5479 | class_offset, |
| 5480 | maybe_temp_loc, |
| 5481 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5482 | // Classes must be equal for the instanceof to succeed. |
| 5483 | __ Xor(out, out, cls); |
| 5484 | __ Sltiu(out, out, 1); |
| 5485 | break; |
| 5486 | } |
| 5487 | |
| 5488 | case TypeCheckKind::kAbstractClassCheck: { |
| 5489 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5490 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5491 | out_loc, |
| 5492 | obj_loc, |
| 5493 | class_offset, |
| 5494 | maybe_temp_loc, |
| 5495 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5496 | // If the class is abstract, we eagerly fetch the super class of the |
| 5497 | // object to avoid doing a comparison we know will fail. |
| 5498 | Mips64Label loop; |
| 5499 | __ Bind(&loop); |
| 5500 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5501 | GenerateReferenceLoadOneRegister(instruction, |
| 5502 | out_loc, |
| 5503 | super_offset, |
| 5504 | maybe_temp_loc, |
| 5505 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5506 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5507 | __ Beqzc(out, &done); |
| 5508 | __ Bnec(out, cls, &loop); |
| 5509 | __ LoadConst32(out, 1); |
| 5510 | break; |
| 5511 | } |
| 5512 | |
| 5513 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5514 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5515 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5516 | out_loc, |
| 5517 | obj_loc, |
| 5518 | class_offset, |
| 5519 | maybe_temp_loc, |
| 5520 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5521 | // Walk over the class hierarchy to find a match. |
| 5522 | Mips64Label loop, success; |
| 5523 | __ Bind(&loop); |
| 5524 | __ Beqc(out, cls, &success); |
| 5525 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5526 | GenerateReferenceLoadOneRegister(instruction, |
| 5527 | out_loc, |
| 5528 | super_offset, |
| 5529 | maybe_temp_loc, |
| 5530 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5531 | __ Bnezc(out, &loop); |
| 5532 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5533 | __ Bc(&done); |
| 5534 | __ Bind(&success); |
| 5535 | __ LoadConst32(out, 1); |
| 5536 | break; |
| 5537 | } |
| 5538 | |
| 5539 | case TypeCheckKind::kArrayObjectCheck: { |
| 5540 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5541 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5542 | out_loc, |
| 5543 | obj_loc, |
| 5544 | class_offset, |
| 5545 | maybe_temp_loc, |
| 5546 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5547 | // Do an exact check. |
| 5548 | Mips64Label success; |
| 5549 | __ Beqc(out, cls, &success); |
| 5550 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5551 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5552 | GenerateReferenceLoadOneRegister(instruction, |
| 5553 | out_loc, |
| 5554 | component_offset, |
| 5555 | maybe_temp_loc, |
| 5556 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5557 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5558 | __ Beqzc(out, &done); |
| 5559 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5560 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5561 | __ Sltiu(out, out, 1); |
| 5562 | __ Bc(&done); |
| 5563 | __ Bind(&success); |
| 5564 | __ LoadConst32(out, 1); |
| 5565 | break; |
| 5566 | } |
| 5567 | |
| 5568 | case TypeCheckKind::kArrayCheck: { |
| 5569 | // No read barrier since the slow path will retry upon failure. |
| 5570 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5571 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5572 | out_loc, |
| 5573 | obj_loc, |
| 5574 | class_offset, |
| 5575 | maybe_temp_loc, |
| 5576 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5577 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5578 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5579 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5580 | codegen_->AddSlowPath(slow_path); |
| 5581 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
| 5582 | __ LoadConst32(out, 1); |
| 5583 | break; |
| 5584 | } |
| 5585 | |
| 5586 | case TypeCheckKind::kUnresolvedCheck: |
| 5587 | case TypeCheckKind::kInterfaceCheck: { |
| 5588 | // Note that we indeed only call on slow path, but we always go |
| 5589 | // into the slow path for the unresolved and interface check |
| 5590 | // cases. |
| 5591 | // |
| 5592 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5593 | // entry point without resorting to a type checking slow path |
| 5594 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5595 | // require to assign fixed registers for the inputs of this |
| 5596 | // HInstanceOf instruction (following the runtime calling |
| 5597 | // convention), which might be cluttered by the potential first |
| 5598 | // read barrier emission at the beginning of this method. |
| 5599 | // |
| 5600 | // TODO: Introduce a new runtime entry point taking the object |
| 5601 | // to test (instead of its class) as argument, and let it deal |
| 5602 | // with the read barrier issues. This will let us refactor this |
| 5603 | // case of the `switch` code as it was previously (with a direct |
| 5604 | // call to the runtime not using a type checking slow path). |
| 5605 | // This should also be beneficial for the other cases above. |
| 5606 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5607 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5608 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5609 | codegen_->AddSlowPath(slow_path); |
| 5610 | __ Bc(slow_path->GetEntryLabel()); |
| 5611 | break; |
| 5612 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5613 | } |
| 5614 | |
| 5615 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5616 | |
| 5617 | if (slow_path != nullptr) { |
| 5618 | __ Bind(slow_path->GetExitLabel()); |
| 5619 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5623 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5624 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5625 | } |
| 5626 | |
| 5627 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5628 | // Will be generated at use site. |
| 5629 | } |
| 5630 | |
| 5631 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5632 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5633 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5634 | } |
| 5635 | |
| 5636 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5637 | // Will be generated at use site. |
| 5638 | } |
| 5639 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 5640 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5641 | // The trampoline uses the same calling convention as dex calling conventions, |
| 5642 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 5643 | // the method_idx. |
| 5644 | HandleInvoke(invoke); |
| 5645 | } |
| 5646 | |
| 5647 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5648 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 5649 | } |
| 5650 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5651 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 5652 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 5653 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5654 | } |
| 5655 | |
| 5656 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5657 | HandleInvoke(invoke); |
| 5658 | // The register T0 is required to be used for the hidden argument in |
| 5659 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 5660 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 5661 | } |
| 5662 | |
| 5663 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5664 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5665 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5666 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5667 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5668 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5669 | |
| 5670 | // Set the hidden argument. |
| 5671 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 5672 | invoke->GetDexMethodIndex()); |
| 5673 | |
| 5674 | // temp = object->GetClass(); |
| 5675 | if (receiver.IsStackSlot()) { |
| 5676 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 5677 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 5678 | } else { |
| 5679 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 5680 | } |
| 5681 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5682 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5683 | // emit a read barrier for the previous class reference load. |
| 5684 | // However this is not required in practice, as this is an |
| 5685 | // intermediate/temporary reference and because the current |
| 5686 | // concurrent copying collector keeps the from-space memory |
| 5687 | // intact/accessible until the end of the marking phase (the |
| 5688 | // concurrent copying collector may not in the future). |
| 5689 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5690 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 5691 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 5692 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5693 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5694 | // temp = temp->GetImtEntryAt(method_offset); |
| 5695 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5696 | // T9 = temp->GetEntryPoint(); |
| 5697 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5698 | // T9(); |
| 5699 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5700 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5701 | DCHECK(!codegen_->IsLeafMethod()); |
| 5702 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5703 | } |
| 5704 | |
| 5705 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5706 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5707 | if (intrinsic.TryDispatch(invoke)) { |
| 5708 | return; |
| 5709 | } |
| 5710 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5711 | HandleInvoke(invoke); |
| 5712 | } |
| 5713 | |
| 5714 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5715 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5716 | // art::PrepareForRegisterAllocation. |
| 5717 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5718 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5719 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5720 | if (intrinsic.TryDispatch(invoke)) { |
| 5721 | return; |
| 5722 | } |
| 5723 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5724 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5725 | } |
| 5726 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 5727 | void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5728 | HandleInvoke(invoke); |
| 5729 | } |
| 5730 | |
| 5731 | void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5732 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 5733 | } |
| 5734 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5735 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5736 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5737 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 5738 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5739 | return true; |
| 5740 | } |
| 5741 | return false; |
| 5742 | } |
| 5743 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5744 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5745 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5746 | bool fallback_load = false; |
| 5747 | switch (desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5748 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5749 | case HLoadString::LoadKind::kBootImageInternTable: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5750 | case HLoadString::LoadKind::kBssEntry: |
| 5751 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5752 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5753 | case HLoadString::LoadKind::kJitTableAddress: |
| 5754 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5755 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5756 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5757 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5758 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5759 | } |
| 5760 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5761 | desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5762 | } |
| 5763 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5764 | } |
| 5765 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5766 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 5767 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5768 | bool fallback_load = false; |
| 5769 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5770 | case HLoadClass::LoadKind::kInvalid: |
| 5771 | LOG(FATAL) << "UNREACHABLE"; |
| 5772 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5773 | case HLoadClass::LoadKind::kReferrersClass: |
| 5774 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5775 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5776 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5777 | case HLoadClass::LoadKind::kBssEntry: |
| 5778 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5779 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5780 | case HLoadClass::LoadKind::kJitTableAddress: |
| 5781 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5782 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5783 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5784 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5785 | break; |
| 5786 | } |
| 5787 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5788 | desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5789 | } |
| 5790 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5791 | } |
| 5792 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5793 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 5794 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5795 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5796 | // On MIPS64 we support all dispatch types. |
| 5797 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5798 | } |
| 5799 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5800 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall( |
| 5801 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5802 | // All registers are assumed to be correctly set up per the calling convention. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5803 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5804 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5805 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 5806 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5807 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5808 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5809 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5810 | uint32_t offset = |
| 5811 | GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5812 | __ LoadFromOffset(kLoadDoubleword, |
| 5813 | temp.AsRegister<GpuRegister>(), |
| 5814 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5815 | offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5816 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5817 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5818 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5819 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5820 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5821 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 5822 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5823 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5824 | NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5825 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 5826 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), info_high); |
| 5827 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5828 | __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5829 | break; |
| 5830 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5831 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5832 | __ LoadLiteral(temp.AsRegister<GpuRegister>(), |
| 5833 | kLoadDoubleword, |
| 5834 | DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5835 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5836 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5837 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5838 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5839 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 5840 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
| 5841 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5842 | __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5843 | break; |
| 5844 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5845 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 5846 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5847 | return; // No code pointer retrieval; the runtime performs the call directly. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5848 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5851 | switch (code_ptr_location) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5852 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5853 | __ Balc(&frame_entry_label_); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5854 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5855 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5856 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 5857 | __ LoadFromOffset(kLoadDoubleword, |
| 5858 | T9, |
| 5859 | callee_method.AsRegister<GpuRegister>(), |
| 5860 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5861 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5862 | // T9() |
| 5863 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5864 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5865 | break; |
| 5866 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5867 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5868 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5869 | DCHECK(!IsLeafMethod()); |
| 5870 | } |
| 5871 | |
| 5872 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5873 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5874 | // art::PrepareForRegisterAllocation. |
| 5875 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5876 | |
| 5877 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5878 | return; |
| 5879 | } |
| 5880 | |
| 5881 | LocationSummary* locations = invoke->GetLocations(); |
| 5882 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 5883 | locations->HasTemps() |
| 5884 | ? locations->GetTemp(0) |
| 5885 | : Location::NoLocation()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5886 | } |
| 5887 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5888 | void CodeGeneratorMIPS64::GenerateVirtualCall( |
| 5889 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5890 | // Use the calling convention instead of the location of the receiver, as |
| 5891 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5892 | // slow path, the arguments have been moved to the right place, so here we are |
| 5893 | // guaranteed that the receiver is the first register of the calling convention. |
| 5894 | InvokeDexCallingConvention calling_convention; |
| 5895 | GpuRegister receiver = calling_convention.GetRegisterAt(0); |
| 5896 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5897 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5898 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5899 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 5900 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5901 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5902 | |
| 5903 | // temp = object->GetClass(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5904 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5905 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5906 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5907 | // emit a read barrier for the previous class reference load. |
| 5908 | // However this is not required in practice, as this is an |
| 5909 | // intermediate/temporary reference and because the current |
| 5910 | // concurrent copying collector keeps the from-space memory |
| 5911 | // intact/accessible until the end of the marking phase (the |
| 5912 | // concurrent copying collector may not in the future). |
| 5913 | __ MaybeUnpoisonHeapReference(temp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5914 | // temp = temp->GetMethodAt(method_offset); |
| 5915 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5916 | // T9 = temp->GetEntryPoint(); |
| 5917 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5918 | // T9(); |
| 5919 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5920 | __ Nop(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5921 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5922 | } |
| 5923 | |
| 5924 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 5925 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5926 | return; |
| 5927 | } |
| 5928 | |
| 5929 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5930 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5934 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5935 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5936 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5937 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 5938 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5939 | return; |
| 5940 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5941 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5942 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5943 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5944 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5945 | ? LocationSummary::kCallOnSlowPath |
| 5946 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5947 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5948 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 5949 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5950 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5951 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5952 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5953 | } |
| 5954 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5955 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5956 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5957 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 5958 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5959 | InvokeRuntimeCallingConvention calling_convention; |
| 5960 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5961 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5962 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5963 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5964 | } |
| 5965 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5966 | } |
| 5967 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5968 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5969 | // move. |
| 5970 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5971 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5972 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5973 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5974 | return; |
| 5975 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5976 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5977 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5978 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5979 | Location out_loc = locations->Out(); |
| 5980 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5981 | GpuRegister current_method_reg = ZERO; |
| 5982 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5983 | load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5984 | current_method_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5985 | } |
| 5986 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5987 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5988 | ? kWithoutReadBarrier |
| 5989 | : kCompilerReadBarrierOption; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5990 | bool generate_null_check = false; |
| 5991 | switch (load_kind) { |
| 5992 | case HLoadClass::LoadKind::kReferrersClass: |
| 5993 | DCHECK(!cls->CanCallRuntime()); |
| 5994 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5995 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5996 | GenerateGcRootFieldLoad(cls, |
| 5997 | out_loc, |
| 5998 | current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5999 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 6000 | read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6001 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6002 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6003 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6004 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6005 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6006 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6007 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6008 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 6009 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6010 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 6011 | break; |
| 6012 | } |
| 6013 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6014 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6015 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6016 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6017 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6018 | __ LoadLiteral(out, |
| 6019 | kLoadUnsignedWord, |
| 6020 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6021 | break; |
| 6022 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6023 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6024 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6025 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
| 6026 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6027 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6028 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 6029 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6030 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6031 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6032 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6033 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6034 | if (masked_hash != 0) { |
| 6035 | __ Daddiu(out, out, -masked_hash); |
| 6036 | } |
| 6037 | break; |
| 6038 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6039 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6040 | CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high = |
| 6041 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6042 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6043 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6044 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, out); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6045 | GenerateGcRootFieldLoad(cls, |
| 6046 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6047 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6048 | /* placeholder */ 0x5678, |
| 6049 | read_barrier_option, |
| 6050 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6051 | generate_null_check = true; |
| 6052 | break; |
| 6053 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6054 | case HLoadClass::LoadKind::kJitTableAddress: |
| 6055 | __ LoadLiteral(out, |
| 6056 | kLoadUnsignedWord, |
| 6057 | codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6058 | cls->GetTypeIndex(), |
| 6059 | cls->GetClass())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6060 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6061 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6062 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6063 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6064 | LOG(FATAL) << "UNREACHABLE"; |
| 6065 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6066 | } |
| 6067 | |
| 6068 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6069 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6070 | SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6071 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6072 | codegen_->AddSlowPath(slow_path); |
| 6073 | if (generate_null_check) { |
| 6074 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6075 | } |
| 6076 | if (cls->MustGenerateClinitCheck()) { |
| 6077 | GenerateClassInitializationCheck(slow_path, out); |
| 6078 | } else { |
| 6079 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6080 | } |
| 6081 | } |
| 6082 | } |
| 6083 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6084 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6085 | return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6086 | } |
| 6087 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6088 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 6089 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6090 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6091 | locations->SetOut(Location::RequiresRegister()); |
| 6092 | } |
| 6093 | |
| 6094 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 6095 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6096 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 6097 | } |
| 6098 | |
| 6099 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6100 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6104 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6105 | } |
| 6106 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6107 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6108 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6109 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6110 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6111 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6112 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6113 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6114 | } else { |
| 6115 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6116 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6117 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6118 | // Rely on the pResolveString and marking to save everything we need. |
| 6119 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6120 | InvokeRuntimeCallingConvention calling_convention; |
| 6121 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6122 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6123 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6124 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6125 | } |
| 6126 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6127 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6128 | } |
| 6129 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6130 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6131 | // move. |
| 6132 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6133 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6134 | LocationSummary* locations = load->GetLocations(); |
| 6135 | Location out_loc = locations->Out(); |
| 6136 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6137 | |
| 6138 | switch (load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6139 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6140 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6141 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6142 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6143 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6144 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
| 6145 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6146 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6147 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6148 | } |
| 6149 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6150 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6151 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6152 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6153 | __ LoadLiteral(out, |
| 6154 | kLoadUnsignedWord, |
| 6155 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6156 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6157 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6158 | case HLoadString::LoadKind::kBootImageInternTable: { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6159 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6160 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6161 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6162 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6163 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6164 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6165 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6166 | return; |
| 6167 | } |
| 6168 | case HLoadString::LoadKind::kBssEntry: { |
| 6169 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6170 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
| 6171 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 6172 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6173 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6174 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, out); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6175 | GenerateGcRootFieldLoad(load, |
| 6176 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6177 | out, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6178 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6179 | kCompilerReadBarrierOption, |
| 6180 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6181 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6182 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS64(load); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6183 | codegen_->AddSlowPath(slow_path); |
| 6184 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6185 | __ Bind(slow_path->GetExitLabel()); |
| 6186 | return; |
| 6187 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6188 | case HLoadString::LoadKind::kJitTableAddress: |
| 6189 | __ LoadLiteral(out, |
| 6190 | kLoadUnsignedWord, |
| 6191 | codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| 6192 | load->GetStringIndex(), |
| 6193 | load->GetString())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6194 | GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6195 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6196 | default: |
| 6197 | break; |
| 6198 | } |
| 6199 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6200 | // 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] | 6201 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6202 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6203 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6204 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| 6205 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6206 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6207 | } |
| 6208 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6209 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6210 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6211 | locations->SetOut(Location::ConstantLocation(constant)); |
| 6212 | } |
| 6213 | |
| 6214 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 6215 | // Will be generated at use site. |
| 6216 | } |
| 6217 | |
| 6218 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6219 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6220 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6221 | InvokeRuntimeCallingConvention calling_convention; |
| 6222 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6223 | } |
| 6224 | |
| 6225 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6226 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6227 | instruction, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6228 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6229 | if (instruction->IsEnter()) { |
| 6230 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6231 | } else { |
| 6232 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6233 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6234 | } |
| 6235 | |
| 6236 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 6237 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6238 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6239 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6240 | case DataType::Type::kInt32: |
| 6241 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6242 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6243 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6244 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6245 | break; |
| 6246 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6247 | case DataType::Type::kFloat32: |
| 6248 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6249 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6250 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 6251 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6252 | break; |
| 6253 | |
| 6254 | default: |
| 6255 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 6256 | } |
| 6257 | } |
| 6258 | |
| 6259 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6260 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6261 | LocationSummary* locations = instruction->GetLocations(); |
| 6262 | |
| 6263 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6264 | case DataType::Type::kInt32: |
| 6265 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6266 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6267 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6268 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6269 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6270 | __ MulR6(dst, lhs, rhs); |
| 6271 | else |
| 6272 | __ Dmul(dst, lhs, rhs); |
| 6273 | break; |
| 6274 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6275 | case DataType::Type::kFloat32: |
| 6276 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6277 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6278 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6279 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6280 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6281 | __ MulS(dst, lhs, rhs); |
| 6282 | else |
| 6283 | __ MulD(dst, lhs, rhs); |
| 6284 | break; |
| 6285 | } |
| 6286 | default: |
| 6287 | LOG(FATAL) << "Unexpected mul type " << type; |
| 6288 | } |
| 6289 | } |
| 6290 | |
| 6291 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 6292 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6293 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6294 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6295 | case DataType::Type::kInt32: |
| 6296 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6297 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6298 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6299 | break; |
| 6300 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6301 | case DataType::Type::kFloat32: |
| 6302 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6303 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6304 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6305 | break; |
| 6306 | |
| 6307 | default: |
| 6308 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 6309 | } |
| 6310 | } |
| 6311 | |
| 6312 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6313 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6314 | LocationSummary* locations = instruction->GetLocations(); |
| 6315 | |
| 6316 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6317 | case DataType::Type::kInt32: |
| 6318 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6319 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6320 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6321 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6322 | __ Subu(dst, ZERO, src); |
| 6323 | else |
| 6324 | __ Dsubu(dst, ZERO, src); |
| 6325 | break; |
| 6326 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6327 | case DataType::Type::kFloat32: |
| 6328 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6329 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6330 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6331 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6332 | __ NegS(dst, src); |
| 6333 | else |
| 6334 | __ NegD(dst, src); |
| 6335 | break; |
| 6336 | } |
| 6337 | default: |
| 6338 | LOG(FATAL) << "Unexpected neg type " << type; |
| 6339 | } |
| 6340 | } |
| 6341 | |
| 6342 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6343 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6344 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6345 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6346 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6347 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6348 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6349 | } |
| 6350 | |
| 6351 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6352 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6353 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6354 | QuickEntrypointEnum entrypoint = |
| 6355 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 6356 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6357 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6358 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6362 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6363 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6364 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6365 | if (instruction->IsStringAlloc()) { |
| 6366 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6367 | } else { |
| 6368 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6369 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6370 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6374 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6375 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6376 | if (instruction->IsStringAlloc()) { |
| 6377 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 6378 | GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 6379 | MemberOffset code_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6380 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6381 | __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 6382 | __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value()); |
| 6383 | __ Jalr(T9); |
| 6384 | __ Nop(); |
| 6385 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6386 | } else { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6387 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 6388 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6389 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6390 | } |
| 6391 | |
| 6392 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6393 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6394 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6395 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6396 | } |
| 6397 | |
| 6398 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6399 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6400 | LocationSummary* locations = instruction->GetLocations(); |
| 6401 | |
| 6402 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6403 | case DataType::Type::kInt32: |
| 6404 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6405 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6406 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6407 | __ Nor(dst, src, ZERO); |
| 6408 | break; |
| 6409 | } |
| 6410 | |
| 6411 | default: |
| 6412 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 6413 | } |
| 6414 | } |
| 6415 | |
| 6416 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6417 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6418 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6419 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6420 | } |
| 6421 | |
| 6422 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 6423 | LocationSummary* locations = instruction->GetLocations(); |
| 6424 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 6425 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6426 | 1); |
| 6427 | } |
| 6428 | |
| 6429 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6430 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6431 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6434 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6435 | if (CanMoveNullCheckToUser(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6436 | return; |
| 6437 | } |
| 6438 | Location obj = instruction->GetLocations()->InAt(0); |
| 6439 | |
| 6440 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6441 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6442 | } |
| 6443 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6444 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6445 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6446 | new (GetScopedAllocator()) NullCheckSlowPathMIPS64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6447 | AddSlowPath(slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6448 | |
| 6449 | Location obj = instruction->GetLocations()->InAt(0); |
| 6450 | |
| 6451 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 6452 | } |
| 6453 | |
| 6454 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6455 | codegen_->GenerateNullCheck(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6456 | } |
| 6457 | |
| 6458 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 6459 | HandleBinaryOp(instruction); |
| 6460 | } |
| 6461 | |
| 6462 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 6463 | HandleBinaryOp(instruction); |
| 6464 | } |
| 6465 | |
| 6466 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6467 | LOG(FATAL) << "Unreachable"; |
| 6468 | } |
| 6469 | |
| 6470 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6471 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6472 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6473 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6474 | // The back edge will generate the suspend check. |
| 6475 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6476 | } |
| 6477 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6478 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6479 | } |
| 6480 | |
| 6481 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6482 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6483 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6484 | if (location.IsStackSlot()) { |
| 6485 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6486 | } else if (location.IsDoubleStackSlot()) { |
| 6487 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6488 | } |
| 6489 | locations->SetOut(location); |
| 6490 | } |
| 6491 | |
| 6492 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 6493 | ATTRIBUTE_UNUSED) { |
| 6494 | // Nothing to do, the parameter is already at its location. |
| 6495 | } |
| 6496 | |
| 6497 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6498 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6499 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6500 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6501 | } |
| 6502 | |
| 6503 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 6504 | ATTRIBUTE_UNUSED) { |
| 6505 | // Nothing to do, the method is already at its location. |
| 6506 | } |
| 6507 | |
| 6508 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6509 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6510 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6511 | locations->SetInAt(i, Location::Any()); |
| 6512 | } |
| 6513 | locations->SetOut(Location::Any()); |
| 6514 | } |
| 6515 | |
| 6516 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6517 | LOG(FATAL) << "Unreachable"; |
| 6518 | } |
| 6519 | |
| 6520 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6521 | DataType::Type type = rem->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6522 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6523 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 6524 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6525 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6526 | |
| 6527 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6528 | case DataType::Type::kInt32: |
| 6529 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6530 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6531 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6532 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6533 | break; |
| 6534 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6535 | case DataType::Type::kFloat32: |
| 6536 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6537 | InvokeRuntimeCallingConvention calling_convention; |
| 6538 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6539 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6540 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6541 | break; |
| 6542 | } |
| 6543 | |
| 6544 | default: |
| 6545 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6546 | } |
| 6547 | } |
| 6548 | |
| 6549 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6550 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6551 | |
| 6552 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6553 | case DataType::Type::kInt32: |
| 6554 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6555 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6556 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6557 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6558 | case DataType::Type::kFloat32: |
| 6559 | case DataType::Type::kFloat64: { |
| 6560 | QuickEntrypointEnum entrypoint = |
| 6561 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6562 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6563 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6564 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 6565 | } else { |
| 6566 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 6567 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6568 | break; |
| 6569 | } |
| 6570 | default: |
| 6571 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6572 | } |
| 6573 | } |
| 6574 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6575 | void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 6576 | constructor_fence->SetLocations(nullptr); |
| 6577 | } |
| 6578 | |
| 6579 | void InstructionCodeGeneratorMIPS64::VisitConstructorFence( |
| 6580 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 6581 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 6582 | } |
| 6583 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6584 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6585 | memory_barrier->SetLocations(nullptr); |
| 6586 | } |
| 6587 | |
| 6588 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6589 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 6590 | } |
| 6591 | |
| 6592 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6593 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6594 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6595 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 6596 | } |
| 6597 | |
| 6598 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 6599 | codegen_->GenerateFrameExit(); |
| 6600 | } |
| 6601 | |
| 6602 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 6603 | ret->SetLocations(nullptr); |
| 6604 | } |
| 6605 | |
| 6606 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 6607 | codegen_->GenerateFrameExit(); |
| 6608 | } |
| 6609 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6610 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { |
| 6611 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6612 | } |
| 6613 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6614 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { |
| 6615 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6616 | } |
| 6617 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6618 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 6619 | HandleShift(shl); |
| 6620 | } |
| 6621 | |
| 6622 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 6623 | HandleShift(shl); |
| 6624 | } |
| 6625 | |
| 6626 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 6627 | HandleShift(shr); |
| 6628 | } |
| 6629 | |
| 6630 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 6631 | HandleShift(shr); |
| 6632 | } |
| 6633 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6634 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 6635 | HandleBinaryOp(instruction); |
| 6636 | } |
| 6637 | |
| 6638 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 6639 | HandleBinaryOp(instruction); |
| 6640 | } |
| 6641 | |
| 6642 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6643 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6644 | } |
| 6645 | |
| 6646 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6647 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6648 | } |
| 6649 | |
| 6650 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6651 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6652 | } |
| 6653 | |
| 6654 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 6655 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6656 | } |
| 6657 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6658 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6659 | HUnresolvedInstanceFieldGet* instruction) { |
| 6660 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6661 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6662 | instruction, instruction->GetFieldType(), calling_convention); |
| 6663 | } |
| 6664 | |
| 6665 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6666 | HUnresolvedInstanceFieldGet* instruction) { |
| 6667 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6668 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6669 | instruction->GetFieldType(), |
| 6670 | instruction->GetFieldIndex(), |
| 6671 | instruction->GetDexPc(), |
| 6672 | calling_convention); |
| 6673 | } |
| 6674 | |
| 6675 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6676 | HUnresolvedInstanceFieldSet* instruction) { |
| 6677 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6678 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6679 | instruction, instruction->GetFieldType(), calling_convention); |
| 6680 | } |
| 6681 | |
| 6682 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6683 | HUnresolvedInstanceFieldSet* instruction) { |
| 6684 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6685 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6686 | instruction->GetFieldType(), |
| 6687 | instruction->GetFieldIndex(), |
| 6688 | instruction->GetDexPc(), |
| 6689 | calling_convention); |
| 6690 | } |
| 6691 | |
| 6692 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( |
| 6693 | HUnresolvedStaticFieldGet* instruction) { |
| 6694 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6695 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6696 | instruction, instruction->GetFieldType(), calling_convention); |
| 6697 | } |
| 6698 | |
| 6699 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( |
| 6700 | HUnresolvedStaticFieldGet* instruction) { |
| 6701 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6702 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6703 | instruction->GetFieldType(), |
| 6704 | instruction->GetFieldIndex(), |
| 6705 | instruction->GetDexPc(), |
| 6706 | calling_convention); |
| 6707 | } |
| 6708 | |
| 6709 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( |
| 6710 | HUnresolvedStaticFieldSet* instruction) { |
| 6711 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6712 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6713 | instruction, instruction->GetFieldType(), calling_convention); |
| 6714 | } |
| 6715 | |
| 6716 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( |
| 6717 | HUnresolvedStaticFieldSet* instruction) { |
| 6718 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6719 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6720 | instruction->GetFieldType(), |
| 6721 | instruction->GetFieldIndex(), |
| 6722 | instruction->GetDexPc(), |
| 6723 | calling_convention); |
| 6724 | } |
| 6725 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6726 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6727 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6728 | instruction, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 6729 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6730 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6731 | // registers in full width (since the runtime only saves/restores lower part). |
| 6732 | locations->SetCustomSlowPathCallerSaves( |
| 6733 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6734 | } |
| 6735 | |
| 6736 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6737 | HBasicBlock* block = instruction->GetBlock(); |
| 6738 | if (block->GetLoopInformation() != nullptr) { |
| 6739 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6740 | // The back edge will generate the suspend check. |
| 6741 | return; |
| 6742 | } |
| 6743 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6744 | // The goto will generate the suspend check. |
| 6745 | return; |
| 6746 | } |
| 6747 | GenerateSuspendCheck(instruction, nullptr); |
| 6748 | } |
| 6749 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6750 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6751 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6752 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6753 | InvokeRuntimeCallingConvention calling_convention; |
| 6754 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6755 | } |
| 6756 | |
| 6757 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6758 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6759 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6760 | } |
| 6761 | |
| 6762 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6763 | DataType::Type input_type = conversion->GetInputType(); |
| 6764 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6765 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6766 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6767 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6768 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6769 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6770 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6771 | } |
| 6772 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6773 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(conversion); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6774 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6775 | if (DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6776 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6777 | } else { |
| 6778 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6779 | } |
| 6780 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6781 | if (DataType::IsFloatingPointType(result_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6782 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6783 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6784 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6785 | } |
| 6786 | } |
| 6787 | |
| 6788 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6789 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6790 | DataType::Type result_type = conversion->GetResultType(); |
| 6791 | DataType::Type input_type = conversion->GetInputType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6792 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6793 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6794 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6795 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6796 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6797 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6798 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6799 | |
| 6800 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6801 | case DataType::Type::kUint8: |
| 6802 | __ Andi(dst, src, 0xFF); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6803 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6804 | case DataType::Type::kInt8: |
| 6805 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6806 | // Type conversion from long to types narrower than int is a result of code |
| 6807 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6808 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6809 | __ Sll(dst, src, 0); |
| 6810 | __ Seb(dst, dst); |
| 6811 | } else { |
| 6812 | __ Seb(dst, src); |
| 6813 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6814 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6815 | case DataType::Type::kUint16: |
| 6816 | __ Andi(dst, src, 0xFFFF); |
| 6817 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6818 | case DataType::Type::kInt16: |
| 6819 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6820 | // Type conversion from long to types narrower than int is a result of code |
| 6821 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6822 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6823 | __ Sll(dst, src, 0); |
| 6824 | __ Seh(dst, dst); |
| 6825 | } else { |
| 6826 | __ Seh(dst, src); |
| 6827 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6828 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6829 | case DataType::Type::kInt32: |
| 6830 | case DataType::Type::kInt64: |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 6831 | // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int |
| 6832 | // conversions, except when the input and output registers are the same and we are not |
| 6833 | // converting longs to shorter types. In these cases, do nothing. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6834 | if ((input_type == DataType::Type::kInt64) || (dst != src)) { |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 6835 | __ Sll(dst, src, 0); |
| 6836 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6837 | break; |
| 6838 | |
| 6839 | default: |
| 6840 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 6841 | << " to " << result_type; |
| 6842 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6843 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6844 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6845 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6846 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6847 | __ Dmtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6848 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6849 | __ Cvtsl(dst, FTMP); |
| 6850 | } else { |
| 6851 | __ Cvtdl(dst, FTMP); |
| 6852 | } |
| 6853 | } else { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6854 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6855 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6856 | __ Cvtsw(dst, FTMP); |
| 6857 | } else { |
| 6858 | __ Cvtdw(dst, FTMP); |
| 6859 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6860 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6861 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6862 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6863 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6864 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6865 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6866 | if (result_type == DataType::Type::kInt64) { |
| 6867 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6868 | __ TruncLS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6869 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6870 | __ TruncLD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6871 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6872 | __ Dmfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6873 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6874 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6875 | __ TruncWS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6876 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6877 | __ TruncWD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6878 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6879 | __ Mfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6880 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6881 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6882 | DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6883 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6884 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6885 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6886 | __ Cvtsd(dst, src); |
| 6887 | } else { |
| 6888 | __ Cvtds(dst, src); |
| 6889 | } |
| 6890 | } else { |
| 6891 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6892 | << " to " << result_type; |
| 6893 | } |
| 6894 | } |
| 6895 | |
| 6896 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 6897 | HandleShift(ushr); |
| 6898 | } |
| 6899 | |
| 6900 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 6901 | HandleShift(ushr); |
| 6902 | } |
| 6903 | |
| 6904 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 6905 | HandleBinaryOp(instruction); |
| 6906 | } |
| 6907 | |
| 6908 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 6909 | HandleBinaryOp(instruction); |
| 6910 | } |
| 6911 | |
| 6912 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6913 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6914 | LOG(FATAL) << "Unreachable"; |
| 6915 | } |
| 6916 | |
| 6917 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6918 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6919 | LOG(FATAL) << "Unreachable"; |
| 6920 | } |
| 6921 | |
| 6922 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6923 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6924 | } |
| 6925 | |
| 6926 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6927 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6928 | } |
| 6929 | |
| 6930 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6931 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6932 | } |
| 6933 | |
| 6934 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6935 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6936 | } |
| 6937 | |
| 6938 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6939 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6940 | } |
| 6941 | |
| 6942 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6943 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6944 | } |
| 6945 | |
| 6946 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6947 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6948 | } |
| 6949 | |
| 6950 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6951 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6952 | } |
| 6953 | |
| 6954 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6955 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6956 | } |
| 6957 | |
| 6958 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6959 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6960 | } |
| 6961 | |
| 6962 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6963 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6964 | } |
| 6965 | |
| 6966 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6967 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6968 | } |
| 6969 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6970 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6971 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6975 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6976 | } |
| 6977 | |
| 6978 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6979 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
| 6982 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6983 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6987 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6988 | } |
| 6989 | |
| 6990 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6991 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6995 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6996 | } |
| 6997 | |
| 6998 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6999 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7000 | } |
| 7001 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7002 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7003 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7004 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7005 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7006 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7007 | } |
| 7008 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7009 | void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg, |
| 7010 | int32_t lower_bound, |
| 7011 | uint32_t num_entries, |
| 7012 | HBasicBlock* switch_block, |
| 7013 | HBasicBlock* default_block) { |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7014 | // Create a set of compare/jumps. |
| 7015 | GpuRegister temp_reg = TMP; |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7016 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7017 | // Jump to default if index is negative |
| 7018 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 7019 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 7020 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); |
| 7021 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7022 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7023 | // Jump to successors[0] if value == lower_bound. |
| 7024 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 7025 | int32_t last_index = 0; |
| 7026 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7027 | __ Addiu(temp_reg, temp_reg, -2); |
| 7028 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7029 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7030 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7031 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 7032 | } |
| 7033 | if (num_entries - last_index == 2) { |
| 7034 | // The last missing case_value. |
| 7035 | __ Addiu(temp_reg, temp_reg, -1); |
| 7036 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7037 | } |
| 7038 | |
| 7039 | // And the default for any other value. |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7040 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 7041 | __ Bc(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7042 | } |
| 7043 | } |
| 7044 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7045 | void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg, |
| 7046 | int32_t lower_bound, |
| 7047 | uint32_t num_entries, |
| 7048 | HBasicBlock* switch_block, |
| 7049 | HBasicBlock* default_block) { |
| 7050 | // Create a jump table. |
| 7051 | std::vector<Mips64Label*> labels(num_entries); |
| 7052 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7053 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7054 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7055 | } |
| 7056 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 7057 | |
| 7058 | // Is the value in range? |
| 7059 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 7060 | __ LoadConst32(AT, num_entries); |
| 7061 | __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 7062 | |
| 7063 | // We are in the range of the table. |
| 7064 | // Load the target address from the jump table, indexing by the value. |
| 7065 | __ LoadLabelAddress(AT, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7066 | __ Dlsa(TMP, TMP, AT, 2); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7067 | __ Lw(TMP, TMP, 0); |
| 7068 | // Compute the absolute target address by adding the table start address |
| 7069 | // (the table contains offsets to targets relative to its start). |
| 7070 | __ Daddu(TMP, TMP, AT); |
| 7071 | // And jump. |
| 7072 | __ Jr(TMP); |
| 7073 | __ Nop(); |
| 7074 | } |
| 7075 | |
| 7076 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7077 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7078 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7079 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7080 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 7081 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 7082 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7083 | |
| 7084 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
| 7085 | GenTableBasedPackedSwitch(value_reg, |
| 7086 | lower_bound, |
| 7087 | num_entries, |
| 7088 | switch_block, |
| 7089 | default_block); |
| 7090 | } else { |
| 7091 | GenPackedSwitchWithCompares(value_reg, |
| 7092 | lower_bound, |
| 7093 | num_entries, |
| 7094 | switch_block, |
| 7095 | default_block); |
| 7096 | } |
| 7097 | } |
| 7098 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7099 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7100 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7101 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7102 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7103 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7104 | } |
| 7105 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7106 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7107 | LocationSummary* locations = instruction->GetLocations(); |
| 7108 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 7109 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7110 | instruction->GetIndex(), kMips64PointerSize).SizeValue(); |
| 7111 | __ LoadFromOffset(kLoadDoubleword, |
| 7112 | locations->Out().AsRegister<GpuRegister>(), |
| 7113 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7114 | method_offset); |
| 7115 | } else { |
| 7116 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 7117 | instruction->GetIndex(), kMips64PointerSize)); |
| 7118 | __ LoadFromOffset(kLoadDoubleword, |
| 7119 | locations->Out().AsRegister<GpuRegister>(), |
| 7120 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7121 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 7122 | __ LoadFromOffset(kLoadDoubleword, |
| 7123 | locations->Out().AsRegister<GpuRegister>(), |
| 7124 | locations->Out().AsRegister<GpuRegister>(), |
| 7125 | method_offset); |
| 7126 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7127 | } |
| 7128 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7129 | void LocationsBuilderMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7130 | ATTRIBUTE_UNUSED) { |
| 7131 | LOG(FATAL) << "Unreachable"; |
| 7132 | } |
| 7133 | |
| 7134 | void InstructionCodeGeneratorMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7135 | ATTRIBUTE_UNUSED) { |
| 7136 | LOG(FATAL) << "Unreachable"; |
| 7137 | } |
| 7138 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7139 | } // namespace mips64 |
| 7140 | } // namespace art |