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 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1064 | void ParallelMoveResolverMIPS64::ExchangeQuadSlots(int index1, int index2) { |
| 1065 | __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, index1); |
| 1066 | __ LoadFpuFromOffset(kLoadQuadword, FTMP2, SP, index2); |
| 1067 | __ StoreFpuToOffset(kStoreQuadword, FTMP, SP, index2); |
| 1068 | __ StoreFpuToOffset(kStoreQuadword, FTMP2, SP, index1); |
| 1069 | } |
| 1070 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1071 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 1072 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 1073 | } |
| 1074 | |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1075 | static dwarf::Reg DWARFReg(FpuRegister reg) { |
| 1076 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); |
| 1077 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1078 | |
| 1079 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 1080 | __ Bind(&frame_entry_label_); |
| 1081 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1082 | bool do_overflow_check = |
| 1083 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips64) || !IsLeafMethod(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1084 | |
| 1085 | if (do_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1086 | __ LoadFromOffset( |
| 1087 | kLoadWord, |
| 1088 | ZERO, |
| 1089 | SP, |
| 1090 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips64))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1091 | RecordPcInfo(nullptr, 0); |
| 1092 | } |
| 1093 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1094 | if (HasEmptyFrame()) { |
| 1095 | return; |
| 1096 | } |
| 1097 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1098 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1099 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips64)) { |
| 1100 | LOG(FATAL) << "Stack frame larger than " |
| 1101 | << GetStackOverflowReservedBytes(InstructionSet::kMips64) << " bytes"; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1102 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1103 | |
| 1104 | // Spill callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1105 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1106 | uint32_t ofs = GetFrameSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1107 | __ IncreaseFrameSize(ofs); |
| 1108 | |
| 1109 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1110 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1111 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1112 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1113 | __ StoreToOffset(kStoreDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1114 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1119 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1120 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1121 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1122 | __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs); |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1123 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1124 | } |
| 1125 | } |
| 1126 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1127 | // Save the current method if we need it. Note that we do not |
| 1128 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1129 | // in the SSA graph. |
| 1130 | if (RequiresCurrentMethod()) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1131 | __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1132 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1133 | |
| 1134 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1135 | // Initialize should_deoptimize flag to 0. |
| 1136 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1137 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 1141 | __ cfi().RememberState(); |
| 1142 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1143 | if (!HasEmptyFrame()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1144 | // Restore callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1145 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1146 | // For better instruction scheduling restore RA before other registers. |
| 1147 | uint32_t ofs = GetFrameSize(); |
| 1148 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1149 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1150 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1151 | ofs -= kMips64DoublewordSize; |
| 1152 | __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1153 | __ cfi().Restore(DWARFReg(reg)); |
| 1154 | } |
| 1155 | } |
| 1156 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1157 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1158 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1159 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 1160 | ofs -= kMips64DoublewordSize; |
| 1161 | __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs); |
| 1162 | __ cfi().Restore(DWARFReg(reg)); |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | __ DecreaseFrameSize(GetFrameSize()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1169 | __ Jic(RA, 0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1170 | |
| 1171 | __ cfi().RestoreState(); |
| 1172 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1173 | } |
| 1174 | |
| 1175 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 1176 | __ Bind(GetLabelOf(block)); |
| 1177 | } |
| 1178 | |
| 1179 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 1180 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1181 | DataType::Type dst_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1182 | if (source.Equals(destination)) { |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | // A valid move can always be inferred from the destination and source |
| 1187 | // locations. When moving from and to a register, the argument type can be |
| 1188 | // used to generate 32bit instead of 64bit moves. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1189 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1190 | DCHECK_EQ(unspecified_type, false); |
| 1191 | |
| 1192 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1193 | if (unspecified_type) { |
| 1194 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1195 | if (source.IsStackSlot() || |
| 1196 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1197 | || src_cst->IsFloatConstant() |
| 1198 | || src_cst->IsNullConstant()))) { |
| 1199 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1200 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1201 | } else { |
| 1202 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1203 | // type is appropriate. Else the source is a register, and since the |
| 1204 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1205 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1206 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1207 | } |
| 1208 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1209 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1210 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1211 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1212 | // Move to GPR/FPR from stack |
| 1213 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1214 | if (DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1215 | __ LoadFpuFromOffset(load_type, |
| 1216 | destination.AsFpuRegister<FpuRegister>(), |
| 1217 | SP, |
| 1218 | source.GetStackIndex()); |
| 1219 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1220 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1221 | __ LoadFromOffset(load_type, |
| 1222 | destination.AsRegister<GpuRegister>(), |
| 1223 | SP, |
| 1224 | source.GetStackIndex()); |
| 1225 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1226 | } else if (source.IsSIMDStackSlot()) { |
| 1227 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1228 | destination.AsFpuRegister<FpuRegister>(), |
| 1229 | SP, |
| 1230 | source.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1231 | } else if (source.IsConstant()) { |
| 1232 | // Move to GPR/FPR from constant |
| 1233 | GpuRegister gpr = AT; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1234 | if (!DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1235 | gpr = destination.AsRegister<GpuRegister>(); |
| 1236 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1237 | if (dst_type == DataType::Type::kInt32 || dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1238 | int32_t value = GetInt32ValueOf(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 | __ LoadConst32(gpr, value); |
| 1243 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1244 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1245 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1246 | if (DataType::IsFloatingPointType(dst_type) && value == 0) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1247 | gpr = ZERO; |
| 1248 | } else { |
| 1249 | __ LoadConst64(gpr, value); |
| 1250 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1251 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1252 | if (dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1253 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1254 | } else if (dst_type == DataType::Type::kFloat64) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1255 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 1256 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1257 | } else if (source.IsRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1258 | if (destination.IsRegister()) { |
| 1259 | // Move to GPR from GPR |
| 1260 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 1261 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1262 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1263 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1264 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1265 | } else { |
| 1266 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1267 | } |
| 1268 | } |
| 1269 | } else if (source.IsFpuRegister()) { |
| 1270 | if (destination.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1271 | if (GetGraph()->HasSIMD()) { |
| 1272 | __ MoveV(VectorRegisterFrom(destination), |
| 1273 | VectorRegisterFrom(source)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1274 | } else { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1275 | // Move to FPR from FPR |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1276 | if (dst_type == DataType::Type::kFloat32) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1277 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1278 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1279 | DCHECK_EQ(dst_type, DataType::Type::kFloat64); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1280 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1281 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1282 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1283 | } else { |
| 1284 | DCHECK(destination.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1285 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1286 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1287 | } else { |
| 1288 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1289 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1290 | } |
| 1291 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1292 | } else if (destination.IsSIMDStackSlot()) { |
| 1293 | if (source.IsFpuRegister()) { |
| 1294 | __ StoreFpuToOffset(kStoreQuadword, |
| 1295 | source.AsFpuRegister<FpuRegister>(), |
| 1296 | SP, |
| 1297 | destination.GetStackIndex()); |
| 1298 | } else { |
| 1299 | DCHECK(source.IsSIMDStackSlot()); |
| 1300 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1301 | FTMP, |
| 1302 | SP, |
| 1303 | source.GetStackIndex()); |
| 1304 | __ StoreFpuToOffset(kStoreQuadword, |
| 1305 | FTMP, |
| 1306 | SP, |
| 1307 | destination.GetStackIndex()); |
| 1308 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1309 | } else { // The destination is not a register. It must be a stack slot. |
| 1310 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1311 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1312 | if (unspecified_type) { |
| 1313 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1314 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1315 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1316 | dst_type = |
| 1317 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1318 | } |
| 1319 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1320 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1321 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1322 | // Move to stack from GPR/FPR |
| 1323 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1324 | if (source.IsRegister()) { |
| 1325 | __ StoreToOffset(store_type, |
| 1326 | source.AsRegister<GpuRegister>(), |
| 1327 | SP, |
| 1328 | destination.GetStackIndex()); |
| 1329 | } else { |
| 1330 | __ StoreFpuToOffset(store_type, |
| 1331 | source.AsFpuRegister<FpuRegister>(), |
| 1332 | SP, |
| 1333 | destination.GetStackIndex()); |
| 1334 | } |
| 1335 | } else if (source.IsConstant()) { |
| 1336 | // Move to stack from constant |
| 1337 | HConstant* src_cst = source.GetConstant(); |
| 1338 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1339 | GpuRegister gpr = ZERO; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1340 | if (destination.IsStackSlot()) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1341 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); |
| 1342 | if (value != 0) { |
| 1343 | gpr = TMP; |
| 1344 | __ LoadConst32(gpr, value); |
| 1345 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1346 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1347 | DCHECK(destination.IsDoubleStackSlot()); |
| 1348 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); |
| 1349 | if (value != 0) { |
| 1350 | gpr = TMP; |
| 1351 | __ LoadConst64(gpr, value); |
| 1352 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1353 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1354 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1355 | } else { |
| 1356 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 1357 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 1358 | // Move to stack from stack |
| 1359 | if (destination.IsStackSlot()) { |
| 1360 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1361 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 1362 | } else { |
| 1363 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 1364 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 1365 | } |
| 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1370 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1371 | DCHECK(!loc1.IsConstant()); |
| 1372 | DCHECK(!loc2.IsConstant()); |
| 1373 | |
| 1374 | if (loc1.Equals(loc2)) { |
| 1375 | return; |
| 1376 | } |
| 1377 | |
| 1378 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 1379 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1380 | bool is_simd1 = loc1.IsSIMDStackSlot(); |
| 1381 | bool is_simd2 = loc2.IsSIMDStackSlot(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1382 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 1383 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 1384 | |
| 1385 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 1386 | // Swap 2 GPRs |
| 1387 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 1388 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 1389 | __ Move(TMP, r2); |
| 1390 | __ Move(r2, r1); |
| 1391 | __ Move(r1, TMP); |
| 1392 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 1393 | // Swap 2 FPRs |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1394 | if (GetGraph()->HasSIMD()) { |
| 1395 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1)); |
| 1396 | __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2)); |
| 1397 | __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP)); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1398 | } else { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1399 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 1400 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
| 1401 | if (type == DataType::Type::kFloat32) { |
| 1402 | __ MovS(FTMP, r1); |
| 1403 | __ MovS(r1, r2); |
| 1404 | __ MovS(r2, FTMP); |
| 1405 | } else { |
| 1406 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| 1407 | __ MovD(FTMP, r1); |
| 1408 | __ MovD(r1, r2); |
| 1409 | __ MovD(r2, FTMP); |
| 1410 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1411 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1412 | } else if (is_slot1 != is_slot2) { |
| 1413 | // Swap GPR/FPR and stack slot |
| 1414 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 1415 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 1416 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 1417 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1418 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1419 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 1420 | if (reg_loc.IsFpuRegister()) { |
| 1421 | __ StoreFpuToOffset(store_type, |
| 1422 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 1423 | SP, |
| 1424 | mem_loc.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1425 | if (mem_loc.IsStackSlot()) { |
| 1426 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1427 | } else { |
| 1428 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 1429 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1430 | } |
| 1431 | } else { |
| 1432 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 1433 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 1434 | } |
| 1435 | } else if (is_slot1 && is_slot2) { |
| 1436 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 1437 | loc2.GetStackIndex(), |
| 1438 | loc1.IsDoubleStackSlot()); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1439 | } else if (is_simd1 && is_simd2) { |
| 1440 | move_resolver_.ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex()); |
| 1441 | } else if ((is_fp_reg1 && is_simd2) || (is_fp_reg2 && is_simd1)) { |
| 1442 | Location fp_reg_loc = is_fp_reg1 ? loc1 : loc2; |
| 1443 | Location mem_loc = is_fp_reg1 ? loc2 : loc1; |
| 1444 | __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, mem_loc.GetStackIndex()); |
| 1445 | __ StoreFpuToOffset(kStoreQuadword, |
| 1446 | fp_reg_loc.AsFpuRegister<FpuRegister>(), |
| 1447 | SP, |
| 1448 | mem_loc.GetStackIndex()); |
| 1449 | __ MoveV(VectorRegisterFrom(fp_reg_loc), static_cast<VectorRegister>(FTMP)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1450 | } else { |
| 1451 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 1452 | } |
| 1453 | } |
| 1454 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1455 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 1456 | DCHECK(location.IsRegister()); |
| 1457 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 1458 | } |
| 1459 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1460 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1461 | if (location.IsRegister()) { |
| 1462 | locations->AddTemp(location); |
| 1463 | } else { |
| 1464 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1465 | } |
| 1466 | } |
| 1467 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1468 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, |
| 1469 | GpuRegister value, |
| 1470 | bool value_can_be_null) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1471 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1472 | GpuRegister card = AT; |
| 1473 | GpuRegister temp = TMP; |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1474 | if (value_can_be_null) { |
| 1475 | __ Beqzc(value, &done); |
| 1476 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1477 | __ LoadFromOffset(kLoadDoubleword, |
| 1478 | card, |
| 1479 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1480 | Thread::CardTableOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1481 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1482 | __ Daddu(temp, card, temp); |
| 1483 | __ Sb(card, temp, 0); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1484 | if (value_can_be_null) { |
| 1485 | __ Bind(&done); |
| 1486 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1489 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1490 | inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches( |
| 1491 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1492 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1493 | for (const PcRelativePatchInfo& info : infos) { |
| 1494 | const DexFile& dex_file = info.target_dex_file; |
| 1495 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1496 | DCHECK(info.label.IsBound()); |
| 1497 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
| 1498 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1499 | uint32_t pc_rel_offset = __ GetLabelLocation(&info_high.label); |
| 1500 | 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] | 1501 | } |
| 1502 | } |
| 1503 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1504 | void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1505 | DCHECK(linker_patches->empty()); |
| 1506 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1507 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1508 | method_bss_entry_patches_.size() + |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1509 | pc_relative_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1510 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1511 | pc_relative_string_patches_.size() + |
| 1512 | string_bss_entry_patches_.size(); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1513 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1514 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1515 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1516 | pc_relative_method_patches_, linker_patches); |
| 1517 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1518 | pc_relative_type_patches_, linker_patches); |
| 1519 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 1520 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1521 | } else { |
| 1522 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1523 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 1524 | pc_relative_type_patches_, linker_patches); |
| 1525 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 1526 | pc_relative_string_patches_, linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1527 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1528 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1529 | method_bss_entry_patches_, linker_patches); |
| 1530 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1531 | type_bss_entry_patches_, linker_patches); |
| 1532 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1533 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1534 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1535 | } |
| 1536 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1537 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1538 | MethodReference target_method, |
| 1539 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1540 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1541 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1542 | info_high, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1543 | &pc_relative_method_patches_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1544 | } |
| 1545 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1546 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1547 | MethodReference target_method, |
| 1548 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1549 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1550 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1551 | info_high, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1552 | &method_bss_entry_patches_); |
| 1553 | } |
| 1554 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1555 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1556 | const DexFile& dex_file, |
| 1557 | dex::TypeIndex type_index, |
| 1558 | const PcRelativePatchInfo* info_high) { |
| 1559 | 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] | 1560 | } |
| 1561 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1562 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1563 | const DexFile& dex_file, |
| 1564 | dex::TypeIndex type_index, |
| 1565 | const PcRelativePatchInfo* info_high) { |
| 1566 | 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] | 1567 | } |
| 1568 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1569 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1570 | const DexFile& dex_file, |
| 1571 | dex::StringIndex string_index, |
| 1572 | const PcRelativePatchInfo* info_high) { |
| 1573 | 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] | 1574 | } |
| 1575 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1576 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewStringBssEntryPatch( |
| 1577 | const DexFile& dex_file, |
| 1578 | dex::StringIndex string_index, |
| 1579 | const PcRelativePatchInfo* info_high) { |
| 1580 | return NewPcRelativePatch(dex_file, string_index.index_, info_high, &string_bss_entry_patches_); |
| 1581 | } |
| 1582 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1583 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1584 | const DexFile& dex_file, |
| 1585 | uint32_t offset_or_index, |
| 1586 | const PcRelativePatchInfo* info_high, |
| 1587 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1588 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1589 | return &patches->back(); |
| 1590 | } |
| 1591 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1592 | Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1593 | return map->GetOrCreate( |
| 1594 | value, |
| 1595 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1596 | } |
| 1597 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1598 | Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) { |
| 1599 | return uint64_literals_.GetOrCreate( |
| 1600 | value, |
| 1601 | [this, value]() { return __ NewLiteral<uint64_t>(value); }); |
| 1602 | } |
| 1603 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1604 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1605 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1606 | } |
| 1607 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1608 | void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
| 1609 | GpuRegister out, |
| 1610 | PcRelativePatchInfo* info_low) { |
| 1611 | DCHECK(!info_high->patch_info_high); |
| 1612 | __ Bind(&info_high->label); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1613 | // Add the high half of a 32-bit offset to PC. |
| 1614 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1615 | // 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] | 1616 | // offset to `out` (e.g. ld, jialc, daddiu). |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1617 | if (info_low != nullptr) { |
| 1618 | DCHECK_EQ(info_low->patch_info_high, info_high); |
| 1619 | __ Bind(&info_low->label); |
| 1620 | } |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1621 | } |
| 1622 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1623 | Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file, |
| 1624 | dex::StringIndex string_index, |
| 1625 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1626 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1627 | return jit_string_patches_.GetOrCreate( |
| 1628 | StringReference(&dex_file, string_index), |
| 1629 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1630 | } |
| 1631 | |
| 1632 | Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 1633 | dex::TypeIndex type_index, |
| 1634 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1635 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1636 | return jit_class_patches_.GetOrCreate( |
| 1637 | TypeReference(&dex_file, type_index), |
| 1638 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1639 | } |
| 1640 | |
| 1641 | void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code, |
| 1642 | const uint8_t* roots_data, |
| 1643 | const Literal* literal, |
| 1644 | uint64_t index_in_table) const { |
| 1645 | uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel()); |
| 1646 | uintptr_t address = |
| 1647 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1648 | reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address); |
| 1649 | } |
| 1650 | |
| 1651 | void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1652 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1653 | const StringReference& string_reference = entry.first; |
| 1654 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1655 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1656 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1657 | } |
| 1658 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1659 | const TypeReference& type_reference = entry.first; |
| 1660 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1661 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1662 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1663 | } |
| 1664 | } |
| 1665 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1666 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1667 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1668 | blocked_core_registers_[ZERO] = true; |
| 1669 | blocked_core_registers_[K0] = true; |
| 1670 | blocked_core_registers_[K1] = true; |
| 1671 | blocked_core_registers_[GP] = true; |
| 1672 | blocked_core_registers_[SP] = true; |
| 1673 | blocked_core_registers_[RA] = true; |
| 1674 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1675 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 1676 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1677 | blocked_core_registers_[AT] = true; |
| 1678 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1679 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1680 | blocked_fpu_registers_[FTMP] = true; |
| 1681 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1682 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1683 | // To be used just for MSA instructions. |
| 1684 | blocked_fpu_registers_[FTMP2] = true; |
| 1685 | } |
| 1686 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1687 | // Reserve suspend and thread registers. |
| 1688 | blocked_core_registers_[S0] = true; |
| 1689 | blocked_core_registers_[TR] = true; |
| 1690 | |
| 1691 | // Reserve T9 for function calls |
| 1692 | blocked_core_registers_[T9] = true; |
| 1693 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 1694 | if (GetGraph()->IsDebuggable()) { |
| 1695 | // Stubs do not save callee-save floating point registers. If the graph |
| 1696 | // is debuggable, we need to deal with these registers differently. For |
| 1697 | // now, just block them. |
| 1698 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1699 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1700 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1701 | } |
| 1702 | } |
| 1703 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1704 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1705 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1706 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1710 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1711 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1715 | __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword, |
| 1716 | FpuRegister(reg_id), |
| 1717 | SP, |
| 1718 | stack_index); |
| 1719 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1723 | __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword, |
| 1724 | FpuRegister(reg_id), |
| 1725 | SP, |
| 1726 | stack_index); |
| 1727 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1731 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1735 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1738 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1739 | HInstruction* instruction, |
| 1740 | uint32_t dex_pc, |
| 1741 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1742 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1743 | GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1744 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1745 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1746 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1749 | void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1750 | HInstruction* instruction, |
| 1751 | SlowPathCode* slow_path) { |
| 1752 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1753 | GenerateInvokeRuntime(entry_point_offset); |
| 1754 | } |
| 1755 | |
| 1756 | void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| 1757 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 1758 | __ Jalr(T9); |
| 1759 | __ Nop(); |
| 1760 | } |
| 1761 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1762 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1763 | GpuRegister class_reg) { |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 1764 | __ LoadFromOffset(kLoadSignedByte, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1765 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1766 | __ Bltc(TMP, AT, slow_path->GetEntryLabel()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1767 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1768 | __ Sync(0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1769 | __ Bind(slow_path->GetExitLabel()); |
| 1770 | } |
| 1771 | |
| 1772 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1773 | __ Sync(0); // only stype 0 is supported |
| 1774 | } |
| 1775 | |
| 1776 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1777 | HBasicBlock* successor) { |
| 1778 | SuspendCheckSlowPathMIPS64* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1779 | down_cast<SuspendCheckSlowPathMIPS64*>(instruction->GetSlowPath()); |
| 1780 | |
| 1781 | if (slow_path == nullptr) { |
| 1782 | slow_path = |
| 1783 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1784 | instruction->SetSlowPath(slow_path); |
| 1785 | codegen_->AddSlowPath(slow_path); |
| 1786 | if (successor != nullptr) { |
| 1787 | DCHECK(successor->IsLoopHeader()); |
| 1788 | } |
| 1789 | } else { |
| 1790 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1791 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1792 | |
| 1793 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1794 | TMP, |
| 1795 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1796 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1797 | if (successor == nullptr) { |
| 1798 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1799 | __ Bind(slow_path->GetReturnLabel()); |
| 1800 | } else { |
| 1801 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1802 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1803 | // slow_path will return to GetLabelOf(successor). |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1808 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1809 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1810 | assembler_(codegen->GetAssembler()), |
| 1811 | codegen_(codegen) {} |
| 1812 | |
| 1813 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1814 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1815 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1816 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1817 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1818 | case DataType::Type::kInt32: |
| 1819 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1820 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1821 | HInstruction* right = instruction->InputAt(1); |
| 1822 | bool can_use_imm = false; |
| 1823 | if (right->IsConstant()) { |
| 1824 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1825 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1826 | can_use_imm = IsUint<16>(imm); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1827 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1828 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1829 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 1830 | if (instruction->IsSub()) { |
| 1831 | if (!(type == DataType::Type::kInt32 && imm == INT32_MIN)) { |
| 1832 | imm = -imm; |
| 1833 | } |
| 1834 | } |
| 1835 | if (type == DataType::Type::kInt32) { |
| 1836 | can_use_imm = IsInt<16>(imm) || (Low16Bits(imm) == 0) || single_use; |
| 1837 | } else { |
| 1838 | can_use_imm = IsInt<16>(imm) || (IsInt<32>(imm) && (Low16Bits(imm) == 0)) || single_use; |
| 1839 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1840 | } |
| 1841 | } |
| 1842 | if (can_use_imm) |
| 1843 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1844 | else |
| 1845 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1846 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1847 | } |
| 1848 | break; |
| 1849 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1850 | case DataType::Type::kFloat32: |
| 1851 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1852 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1853 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1854 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1855 | break; |
| 1856 | |
| 1857 | default: |
| 1858 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1863 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1864 | LocationSummary* locations = instruction->GetLocations(); |
| 1865 | |
| 1866 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1867 | case DataType::Type::kInt32: |
| 1868 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1869 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1870 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1871 | Location rhs_location = locations->InAt(1); |
| 1872 | |
| 1873 | GpuRegister rhs_reg = ZERO; |
| 1874 | int64_t rhs_imm = 0; |
| 1875 | bool use_imm = rhs_location.IsConstant(); |
| 1876 | if (use_imm) { |
| 1877 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1878 | } else { |
| 1879 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1880 | } |
| 1881 | |
| 1882 | if (instruction->IsAnd()) { |
| 1883 | if (use_imm) |
| 1884 | __ Andi(dst, lhs, rhs_imm); |
| 1885 | else |
| 1886 | __ And(dst, lhs, rhs_reg); |
| 1887 | } else if (instruction->IsOr()) { |
| 1888 | if (use_imm) |
| 1889 | __ Ori(dst, lhs, rhs_imm); |
| 1890 | else |
| 1891 | __ Or(dst, lhs, rhs_reg); |
| 1892 | } else if (instruction->IsXor()) { |
| 1893 | if (use_imm) |
| 1894 | __ Xori(dst, lhs, rhs_imm); |
| 1895 | else |
| 1896 | __ Xor(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1897 | } else if (instruction->IsAdd() || instruction->IsSub()) { |
| 1898 | if (instruction->IsSub()) { |
| 1899 | rhs_imm = -rhs_imm; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1900 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1901 | if (type == DataType::Type::kInt32) { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1902 | if (use_imm) { |
| 1903 | if (IsInt<16>(rhs_imm)) { |
| 1904 | __ Addiu(dst, lhs, rhs_imm); |
| 1905 | } else { |
| 1906 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 1907 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 1908 | if (rhs_imm_low < 0) { |
| 1909 | rhs_imm_high += 1; |
| 1910 | } |
| 1911 | __ Aui(dst, lhs, rhs_imm_high); |
| 1912 | if (rhs_imm_low != 0) { |
| 1913 | __ Addiu(dst, dst, rhs_imm_low); |
| 1914 | } |
| 1915 | } |
| 1916 | } else { |
| 1917 | if (instruction->IsAdd()) { |
| 1918 | __ Addu(dst, lhs, rhs_reg); |
| 1919 | } else { |
| 1920 | DCHECK(instruction->IsSub()); |
| 1921 | __ Subu(dst, lhs, rhs_reg); |
| 1922 | } |
| 1923 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1924 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1925 | if (use_imm) { |
| 1926 | if (IsInt<16>(rhs_imm)) { |
| 1927 | __ Daddiu(dst, lhs, rhs_imm); |
| 1928 | } else if (IsInt<32>(rhs_imm)) { |
| 1929 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 1930 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 1931 | bool overflow_hi16 = false; |
| 1932 | if (rhs_imm_low < 0) { |
| 1933 | rhs_imm_high += 1; |
| 1934 | overflow_hi16 = (rhs_imm_high == -32768); |
| 1935 | } |
| 1936 | __ Daui(dst, lhs, rhs_imm_high); |
| 1937 | if (rhs_imm_low != 0) { |
| 1938 | __ Daddiu(dst, dst, rhs_imm_low); |
| 1939 | } |
| 1940 | if (overflow_hi16) { |
| 1941 | __ Dahi(dst, 1); |
| 1942 | } |
| 1943 | } else { |
| 1944 | int16_t rhs_imm_low = Low16Bits(Low32Bits(rhs_imm)); |
| 1945 | if (rhs_imm_low < 0) { |
| 1946 | rhs_imm += (INT64_C(1) << 16); |
| 1947 | } |
| 1948 | int16_t rhs_imm_upper = High16Bits(Low32Bits(rhs_imm)); |
| 1949 | if (rhs_imm_upper < 0) { |
| 1950 | rhs_imm += (INT64_C(1) << 32); |
| 1951 | } |
| 1952 | int16_t rhs_imm_high = Low16Bits(High32Bits(rhs_imm)); |
| 1953 | if (rhs_imm_high < 0) { |
| 1954 | rhs_imm += (INT64_C(1) << 48); |
| 1955 | } |
| 1956 | int16_t rhs_imm_top = High16Bits(High32Bits(rhs_imm)); |
| 1957 | GpuRegister tmp = lhs; |
| 1958 | if (rhs_imm_low != 0) { |
| 1959 | __ Daddiu(dst, tmp, rhs_imm_low); |
| 1960 | tmp = dst; |
| 1961 | } |
| 1962 | // Dahi and Dati must use the same input and output register, so we have to initialize |
| 1963 | // the dst register using Daddiu or Daui, even when the intermediate value is zero: |
| 1964 | // Daui(dst, lhs, 0). |
| 1965 | if ((rhs_imm_upper != 0) || (rhs_imm_low == 0)) { |
| 1966 | __ Daui(dst, tmp, rhs_imm_upper); |
| 1967 | } |
| 1968 | if (rhs_imm_high != 0) { |
| 1969 | __ Dahi(dst, rhs_imm_high); |
| 1970 | } |
| 1971 | if (rhs_imm_top != 0) { |
| 1972 | __ Dati(dst, rhs_imm_top); |
| 1973 | } |
| 1974 | } |
| 1975 | } else if (instruction->IsAdd()) { |
| 1976 | __ Daddu(dst, lhs, rhs_reg); |
| 1977 | } else { |
| 1978 | DCHECK(instruction->IsSub()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1979 | __ Dsubu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1980 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1981 | } |
| 1982 | } |
| 1983 | break; |
| 1984 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1985 | case DataType::Type::kFloat32: |
| 1986 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1987 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1988 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1989 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1990 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1991 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1992 | __ AddS(dst, lhs, rhs); |
| 1993 | else |
| 1994 | __ AddD(dst, lhs, rhs); |
| 1995 | } else if (instruction->IsSub()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1996 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1997 | __ SubS(dst, lhs, rhs); |
| 1998 | else |
| 1999 | __ SubD(dst, lhs, rhs); |
| 2000 | } else { |
| 2001 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 2002 | } |
| 2003 | break; |
| 2004 | } |
| 2005 | default: |
| 2006 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2011 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2012 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2013 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2014 | DataType::Type type = instr->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2015 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2016 | case DataType::Type::kInt32: |
| 2017 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2018 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2019 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2020 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2021 | break; |
| 2022 | } |
| 2023 | default: |
| 2024 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2025 | } |
| 2026 | } |
| 2027 | |
| 2028 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2029 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2030 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2031 | DataType::Type type = instr->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2032 | |
| 2033 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2034 | case DataType::Type::kInt32: |
| 2035 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2036 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2037 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2038 | Location rhs_location = locations->InAt(1); |
| 2039 | |
| 2040 | GpuRegister rhs_reg = ZERO; |
| 2041 | int64_t rhs_imm = 0; |
| 2042 | bool use_imm = rhs_location.IsConstant(); |
| 2043 | if (use_imm) { |
| 2044 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 2045 | } else { |
| 2046 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 2047 | } |
| 2048 | |
| 2049 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2050 | uint32_t shift_value = rhs_imm & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2051 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2052 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2053 | if (shift_value == 0) { |
| 2054 | if (dst != lhs) { |
| 2055 | __ Move(dst, lhs); |
| 2056 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2057 | } else if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2058 | if (instr->IsShl()) { |
| 2059 | __ Sll(dst, lhs, shift_value); |
| 2060 | } else if (instr->IsShr()) { |
| 2061 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2062 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2063 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2064 | } else { |
| 2065 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2066 | } |
| 2067 | } else { |
| 2068 | if (shift_value < 32) { |
| 2069 | if (instr->IsShl()) { |
| 2070 | __ Dsll(dst, lhs, shift_value); |
| 2071 | } else if (instr->IsShr()) { |
| 2072 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2073 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2074 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2075 | } else { |
| 2076 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2077 | } |
| 2078 | } else { |
| 2079 | shift_value -= 32; |
| 2080 | if (instr->IsShl()) { |
| 2081 | __ Dsll32(dst, lhs, shift_value); |
| 2082 | } else if (instr->IsShr()) { |
| 2083 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2084 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2085 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2086 | } else { |
| 2087 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2092 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2093 | if (instr->IsShl()) { |
| 2094 | __ Sllv(dst, lhs, rhs_reg); |
| 2095 | } else if (instr->IsShr()) { |
| 2096 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2097 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2098 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2099 | } else { |
| 2100 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2101 | } |
| 2102 | } else { |
| 2103 | if (instr->IsShl()) { |
| 2104 | __ Dsllv(dst, lhs, rhs_reg); |
| 2105 | } else if (instr->IsShr()) { |
| 2106 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2107 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2108 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2109 | } else { |
| 2110 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2111 | } |
| 2112 | } |
| 2113 | } |
| 2114 | break; |
| 2115 | } |
| 2116 | default: |
| 2117 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 2122 | HandleBinaryOp(instruction); |
| 2123 | } |
| 2124 | |
| 2125 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 2126 | HandleBinaryOp(instruction); |
| 2127 | } |
| 2128 | |
| 2129 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 2130 | HandleBinaryOp(instruction); |
| 2131 | } |
| 2132 | |
| 2133 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 2134 | HandleBinaryOp(instruction); |
| 2135 | } |
| 2136 | |
| 2137 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2138 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2139 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2140 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2141 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2142 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2143 | object_array_get_with_read_barrier |
| 2144 | ? LocationSummary::kCallOnSlowPath |
| 2145 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2146 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2147 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2148 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2149 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2150 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2151 | if (DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2152 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2153 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2154 | // The output overlaps in the case of an object array get with |
| 2155 | // read barriers enabled: we do not want the move to overwrite the |
| 2156 | // array's location, as we need it to emit the read barrier. |
| 2157 | locations->SetOut(Location::RequiresRegister(), |
| 2158 | object_array_get_with_read_barrier |
| 2159 | ? Location::kOutputOverlap |
| 2160 | : Location::kNoOutputOverlap); |
| 2161 | } |
| 2162 | // We need a temporary register for the read barrier marking slow |
| 2163 | // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier. |
| 2164 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2165 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2166 | ? !kBakerReadBarrierThunksEnableForFields |
| 2167 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2168 | if (temp_needed) { |
| 2169 | locations->AddTemp(Location::RequiresRegister()); |
| 2170 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2171 | } |
| 2172 | } |
| 2173 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2174 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) { |
| 2175 | auto null_checker = [codegen, instruction]() { |
| 2176 | codegen->MaybeRecordImplicitNullCheck(instruction); |
| 2177 | }; |
| 2178 | return null_checker; |
| 2179 | } |
| 2180 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2181 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 2182 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2183 | Location obj_loc = locations->InAt(0); |
| 2184 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 2185 | Location out_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2186 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2187 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2188 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2189 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2190 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2191 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2192 | instruction->IsStringCharAt(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2193 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2194 | case DataType::Type::kBool: |
| 2195 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2196 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2197 | if (index.IsConstant()) { |
| 2198 | size_t offset = |
| 2199 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2200 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2201 | } else { |
| 2202 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2203 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2204 | } |
| 2205 | break; |
| 2206 | } |
| 2207 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2208 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2209 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2210 | if (index.IsConstant()) { |
| 2211 | size_t offset = |
| 2212 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2213 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2214 | } else { |
| 2215 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2216 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2217 | } |
| 2218 | break; |
| 2219 | } |
| 2220 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2221 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2222 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2223 | if (maybe_compressed_char_at) { |
| 2224 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2225 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2226 | __ Dext(TMP, TMP, 0, 1); |
| 2227 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2228 | "Expecting 0=compressed, 1=uncompressed"); |
| 2229 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2230 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2231 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2232 | if (maybe_compressed_char_at) { |
| 2233 | Mips64Label uncompressed_load, done; |
| 2234 | __ Bnezc(TMP, &uncompressed_load); |
| 2235 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2236 | out, |
| 2237 | obj, |
| 2238 | data_offset + (const_index << TIMES_1)); |
| 2239 | __ Bc(&done); |
| 2240 | __ Bind(&uncompressed_load); |
| 2241 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2242 | out, |
| 2243 | obj, |
| 2244 | data_offset + (const_index << TIMES_2)); |
| 2245 | __ Bind(&done); |
| 2246 | } else { |
| 2247 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2248 | out, |
| 2249 | obj, |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2250 | data_offset + (const_index << TIMES_2), |
| 2251 | null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2252 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2253 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2254 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 2255 | if (maybe_compressed_char_at) { |
| 2256 | Mips64Label uncompressed_load, done; |
| 2257 | __ Bnezc(TMP, &uncompressed_load); |
| 2258 | __ Daddu(TMP, obj, index_reg); |
| 2259 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2260 | __ Bc(&done); |
| 2261 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2262 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2263 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2264 | __ Bind(&done); |
| 2265 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2266 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2267 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2268 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2269 | } |
| 2270 | break; |
| 2271 | } |
| 2272 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2273 | case DataType::Type::kInt16: { |
| 2274 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2275 | if (index.IsConstant()) { |
| 2276 | size_t offset = |
| 2277 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2278 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
| 2279 | } else { |
| 2280 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
| 2281 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2282 | } |
| 2283 | break; |
| 2284 | } |
| 2285 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2286 | case DataType::Type::kInt32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2287 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2288 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2289 | LoadOperandType load_type = |
| 2290 | (type == DataType::Type::kReference) ? kLoadUnsignedWord : kLoadWord; |
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_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2294 | __ LoadFromOffset(load_type, 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_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2297 | __ LoadFromOffset(load_type, 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::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2303 | static_assert( |
| 2304 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2305 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2306 | // /* HeapReference<Object> */ out = |
| 2307 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2308 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2309 | bool temp_needed = index.IsConstant() |
| 2310 | ? !kBakerReadBarrierThunksEnableForFields |
| 2311 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2312 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2313 | // Note that a potential implicit null check is handled in this |
| 2314 | // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2315 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2316 | if (index.IsConstant()) { |
| 2317 | // Array load with a constant index can be treated as a field load. |
| 2318 | size_t offset = |
| 2319 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2320 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2321 | out_loc, |
| 2322 | obj, |
| 2323 | offset, |
| 2324 | temp, |
| 2325 | /* needs_null_check */ false); |
| 2326 | } else { |
| 2327 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2328 | out_loc, |
| 2329 | obj, |
| 2330 | data_offset, |
| 2331 | index, |
| 2332 | temp, |
| 2333 | /* needs_null_check */ false); |
| 2334 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2335 | } else { |
| 2336 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2337 | if (index.IsConstant()) { |
| 2338 | size_t offset = |
| 2339 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2340 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker); |
| 2341 | // If read barriers are enabled, emit read barriers other than |
| 2342 | // Baker's using a slow path (and also unpoison the loaded |
| 2343 | // reference, if heap poisoning is enabled). |
| 2344 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2345 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2346 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2347 | __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker); |
| 2348 | // If read barriers are enabled, emit read barriers other than |
| 2349 | // Baker's using a slow path (and also unpoison the loaded |
| 2350 | // reference, if heap poisoning is enabled). |
| 2351 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2352 | out_loc, |
| 2353 | out_loc, |
| 2354 | obj_loc, |
| 2355 | data_offset, |
| 2356 | index); |
| 2357 | } |
| 2358 | } |
| 2359 | break; |
| 2360 | } |
| 2361 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2362 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2363 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2364 | if (index.IsConstant()) { |
| 2365 | size_t offset = |
| 2366 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2367 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2368 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2369 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2370 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2371 | } |
| 2372 | break; |
| 2373 | } |
| 2374 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2375 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2376 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2377 | if (index.IsConstant()) { |
| 2378 | size_t offset = |
| 2379 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2380 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2381 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2382 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2383 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2384 | } |
| 2385 | break; |
| 2386 | } |
| 2387 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2388 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2389 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2390 | if (index.IsConstant()) { |
| 2391 | size_t offset = |
| 2392 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2393 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2394 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2395 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2396 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2397 | } |
| 2398 | break; |
| 2399 | } |
| 2400 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2401 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2402 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2403 | UNREACHABLE(); |
| 2404 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2408 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2409 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2410 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2411 | } |
| 2412 | |
| 2413 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2414 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2415 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2416 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2417 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2418 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2419 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2420 | // Mask out compression flag from String's array length. |
| 2421 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2422 | __ Srl(out, out, 1u); |
| 2423 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2426 | Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2427 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2428 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2429 | : Location::RequiresRegister(); |
| 2430 | } |
| 2431 | |
| 2432 | Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2433 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2434 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2435 | // but we should only prefer this if the constant has a single use. |
| 2436 | if (instruction->IsConstant() && |
| 2437 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2438 | instruction->GetUses().HasExactlyOneElement())) { |
| 2439 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2440 | // Otherwise fall through and require an FPU register for the constant. |
| 2441 | } |
| 2442 | return Location::RequiresFpuRegister(); |
| 2443 | } |
| 2444 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2445 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2446 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2447 | |
| 2448 | bool needs_write_barrier = |
| 2449 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2450 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2451 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2452 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2453 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2454 | may_need_runtime_call_for_type_check ? |
| 2455 | LocationSummary::kCallOnSlowPath : |
| 2456 | LocationSummary::kNoCall); |
| 2457 | |
| 2458 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2459 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2460 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2461 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2462 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2463 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2464 | } |
| 2465 | if (needs_write_barrier) { |
| 2466 | // Temporary register for the write barrier. |
| 2467 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 2472 | LocationSummary* locations = instruction->GetLocations(); |
| 2473 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2474 | Location index = locations->InAt(1); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2475 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2476 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2477 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2478 | bool needs_write_barrier = |
| 2479 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2480 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2481 | GpuRegister base_reg = index.IsConstant() ? obj : TMP; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2482 | |
| 2483 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2484 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2485 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2486 | case DataType::Type::kInt8: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2487 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2488 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2489 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2490 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2491 | __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>()); |
| 2492 | } |
| 2493 | if (value_location.IsConstant()) { |
| 2494 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2495 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2496 | } else { |
| 2497 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2498 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2499 | } |
| 2500 | break; |
| 2501 | } |
| 2502 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2503 | case DataType::Type::kUint16: |
| 2504 | case DataType::Type::kInt16: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2505 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2506 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2507 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2508 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2509 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2510 | } |
| 2511 | if (value_location.IsConstant()) { |
| 2512 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2513 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2514 | } else { |
| 2515 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2516 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2517 | } |
| 2518 | break; |
| 2519 | } |
| 2520 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2521 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2522 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2523 | if (index.IsConstant()) { |
| 2524 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2525 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2526 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2527 | } |
| 2528 | if (value_location.IsConstant()) { |
| 2529 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2530 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2531 | } else { |
| 2532 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2533 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2534 | } |
| 2535 | break; |
| 2536 | } |
| 2537 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2538 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2539 | if (value_location.IsConstant()) { |
| 2540 | // Just setting null. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2541 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2542 | if (index.IsConstant()) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2543 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2544 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2545 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2546 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2547 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2548 | DCHECK_EQ(value, 0); |
| 2549 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2550 | DCHECK(!needs_write_barrier); |
| 2551 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2552 | break; |
| 2553 | } |
| 2554 | |
| 2555 | DCHECK(needs_write_barrier); |
| 2556 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2557 | GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 2558 | GpuRegister temp2 = TMP; // Doesn't need to survive slow path. |
| 2559 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2560 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2561 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2562 | Mips64Label done; |
| 2563 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 2564 | |
| 2565 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2566 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS64(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2567 | codegen_->AddSlowPath(slow_path); |
| 2568 | if (instruction->GetValueCanBeNull()) { |
| 2569 | Mips64Label non_zero; |
| 2570 | __ Bnezc(value, &non_zero); |
| 2571 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2572 | if (index.IsConstant()) { |
| 2573 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2574 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2575 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2576 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2577 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2578 | __ Bc(&done); |
| 2579 | __ Bind(&non_zero); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2580 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2581 | |
| 2582 | // Note that when read barriers are enabled, the type checks |
| 2583 | // are performed without read barriers. This is fine, even in |
| 2584 | // the case where a class object is in the from-space after |
| 2585 | // the flip, as a comparison involving such a type would not |
| 2586 | // produce a false positive; it may of course produce a false |
| 2587 | // negative, in which case we would take the ArraySet slow |
| 2588 | // path. |
| 2589 | |
| 2590 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2591 | __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker); |
| 2592 | __ MaybeUnpoisonHeapReference(temp1); |
| 2593 | |
| 2594 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2595 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset); |
| 2596 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2597 | __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset); |
| 2598 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2599 | // nor `temp2`, as we are comparing two poisoned references. |
| 2600 | |
| 2601 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2602 | Mips64Label do_put; |
| 2603 | __ Beqc(temp1, temp2, &do_put); |
| 2604 | // If heap poisoning is enabled, the `temp1` reference has |
| 2605 | // not been unpoisoned yet; unpoison it now. |
| 2606 | __ MaybeUnpoisonHeapReference(temp1); |
| 2607 | |
| 2608 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2609 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset); |
| 2610 | // If heap poisoning is enabled, no need to unpoison |
| 2611 | // `temp1`, as we are comparing against null below. |
| 2612 | __ Bnezc(temp1, slow_path->GetEntryLabel()); |
| 2613 | __ Bind(&do_put); |
| 2614 | } else { |
| 2615 | __ Bnec(temp1, temp2, slow_path->GetEntryLabel()); |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | GpuRegister source = value; |
| 2620 | if (kPoisonHeapReferences) { |
| 2621 | // Note that in the case where `value` is a null reference, |
| 2622 | // we do not enter this block, as a null reference does not |
| 2623 | // need poisoning. |
| 2624 | __ Move(temp1, value); |
| 2625 | __ PoisonHeapReference(temp1); |
| 2626 | source = temp1; |
| 2627 | } |
| 2628 | |
| 2629 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2630 | if (index.IsConstant()) { |
| 2631 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2632 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2633 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2634 | } |
| 2635 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2636 | |
| 2637 | if (!may_need_runtime_call_for_type_check) { |
| 2638 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2639 | } |
| 2640 | |
| 2641 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2642 | |
| 2643 | if (done.IsLinked()) { |
| 2644 | __ Bind(&done); |
| 2645 | } |
| 2646 | |
| 2647 | if (slow_path != nullptr) { |
| 2648 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2649 | } |
| 2650 | break; |
| 2651 | } |
| 2652 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2653 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2654 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2655 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2656 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2657 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2658 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2659 | } |
| 2660 | if (value_location.IsConstant()) { |
| 2661 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2662 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2663 | } else { |
| 2664 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2665 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2666 | } |
| 2667 | break; |
| 2668 | } |
| 2669 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2670 | case DataType::Type::kFloat32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2671 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2672 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2673 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2674 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2675 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2676 | } |
| 2677 | if (value_location.IsConstant()) { |
| 2678 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2679 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2680 | } else { |
| 2681 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2682 | __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2683 | } |
| 2684 | break; |
| 2685 | } |
| 2686 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2687 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2688 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2689 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2690 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2691 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2692 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2693 | } |
| 2694 | if (value_location.IsConstant()) { |
| 2695 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2696 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2697 | } else { |
| 2698 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2699 | __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2700 | } |
| 2701 | break; |
| 2702 | } |
| 2703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2704 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2705 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2706 | UNREACHABLE(); |
| 2707 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2711 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2712 | InvokeRuntimeCallingConvention calling_convention; |
| 2713 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2714 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2715 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2716 | |
| 2717 | HInstruction* index = instruction->InputAt(0); |
| 2718 | HInstruction* length = instruction->InputAt(1); |
| 2719 | |
| 2720 | bool const_index = false; |
| 2721 | bool const_length = false; |
| 2722 | |
| 2723 | if (index->IsConstant()) { |
| 2724 | if (length->IsConstant()) { |
| 2725 | const_index = true; |
| 2726 | const_length = true; |
| 2727 | } else { |
| 2728 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 2729 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 2730 | const_index = true; |
| 2731 | } |
| 2732 | } |
| 2733 | } else if (length->IsConstant()) { |
| 2734 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 2735 | if (IsUint<15>(length_value)) { |
| 2736 | const_length = true; |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | locations->SetInAt(0, const_index |
| 2741 | ? Location::ConstantLocation(index->AsConstant()) |
| 2742 | : Location::RequiresRegister()); |
| 2743 | locations->SetInAt(1, const_length |
| 2744 | ? Location::ConstantLocation(length->AsConstant()) |
| 2745 | : Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2749 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2750 | Location index_loc = locations->InAt(0); |
| 2751 | Location length_loc = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2752 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2753 | if (length_loc.IsConstant()) { |
| 2754 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2755 | if (index_loc.IsConstant()) { |
| 2756 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2757 | if (index < 0 || index >= length) { |
| 2758 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2759 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2760 | codegen_->AddSlowPath(slow_path); |
| 2761 | __ Bc(slow_path->GetEntryLabel()); |
| 2762 | } else { |
| 2763 | // Nothing to be done. |
| 2764 | } |
| 2765 | return; |
| 2766 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2767 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2768 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2769 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2770 | codegen_->AddSlowPath(slow_path); |
| 2771 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2772 | if (length == 0) { |
| 2773 | __ Bc(slow_path->GetEntryLabel()); |
| 2774 | } else if (length == 1) { |
| 2775 | __ Bnezc(index, slow_path->GetEntryLabel()); |
| 2776 | } else { |
| 2777 | DCHECK(IsUint<15>(length)) << length; |
| 2778 | __ Sltiu(TMP, index, length); |
| 2779 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2780 | } |
| 2781 | } else { |
| 2782 | GpuRegister length = length_loc.AsRegister<GpuRegister>(); |
| 2783 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2784 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2785 | codegen_->AddSlowPath(slow_path); |
| 2786 | if (index_loc.IsConstant()) { |
| 2787 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2788 | if (index < 0) { |
| 2789 | __ Bc(slow_path->GetEntryLabel()); |
| 2790 | } else if (index == 0) { |
| 2791 | __ Blezc(length, slow_path->GetEntryLabel()); |
| 2792 | } else { |
| 2793 | DCHECK(IsInt<16>(index + 1)) << index; |
| 2794 | __ Sltiu(TMP, length, index + 1); |
| 2795 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 2796 | } |
| 2797 | } else { |
| 2798 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2799 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
| 2800 | } |
| 2801 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2804 | // Temp is used for read barrier. |
| 2805 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 2806 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2807 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2808 | (kUseBakerReadBarrier || |
| 2809 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2810 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2811 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2812 | return 1; |
| 2813 | } |
| 2814 | return 0; |
| 2815 | } |
| 2816 | |
| 2817 | // Extra temp is used for read barrier. |
| 2818 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 2819 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 2820 | } |
| 2821 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2822 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2823 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2824 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 2825 | |
| 2826 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 2827 | switch (type_check_kind) { |
| 2828 | case TypeCheckKind::kExactCheck: |
| 2829 | case TypeCheckKind::kAbstractClassCheck: |
| 2830 | case TypeCheckKind::kClassHierarchyCheck: |
| 2831 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2832 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2833 | ? LocationSummary::kCallOnSlowPath |
| 2834 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 2835 | break; |
| 2836 | case TypeCheckKind::kArrayCheck: |
| 2837 | case TypeCheckKind::kUnresolvedCheck: |
| 2838 | case TypeCheckKind::kInterfaceCheck: |
| 2839 | call_kind = LocationSummary::kCallOnSlowPath; |
| 2840 | break; |
| 2841 | } |
| 2842 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2843 | LocationSummary* locations = |
| 2844 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2845 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2846 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2847 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2851 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2852 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2853 | Location obj_loc = locations->InAt(0); |
| 2854 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2855 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2856 | Location temp_loc = locations->GetTemp(0); |
| 2857 | GpuRegister temp = temp_loc.AsRegister<GpuRegister>(); |
| 2858 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 2859 | DCHECK_LE(num_temps, 2u); |
| 2860 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2861 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2862 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2863 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2864 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2865 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 2866 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2867 | const uint32_t object_array_data_offset = |
| 2868 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 2869 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2870 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2871 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 2872 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 2873 | // read barriers is done for performance and code size reasons. |
| 2874 | bool is_type_check_slow_path_fatal = false; |
| 2875 | if (!kEmitCompilerReadBarrier) { |
| 2876 | is_type_check_slow_path_fatal = |
| 2877 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 2878 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2879 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2880 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 2881 | !instruction->CanThrowIntoCatchBlock(); |
| 2882 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2883 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2884 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 2885 | instruction, is_type_check_slow_path_fatal); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2886 | codegen_->AddSlowPath(slow_path); |
| 2887 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2888 | // Avoid this check if we know `obj` is not null. |
| 2889 | if (instruction->MustDoNullCheck()) { |
| 2890 | __ Beqzc(obj, &done); |
| 2891 | } |
| 2892 | |
| 2893 | switch (type_check_kind) { |
| 2894 | case TypeCheckKind::kExactCheck: |
| 2895 | case TypeCheckKind::kArrayCheck: { |
| 2896 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2897 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2898 | temp_loc, |
| 2899 | obj_loc, |
| 2900 | class_offset, |
| 2901 | maybe_temp2_loc, |
| 2902 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2903 | // Jump to slow path for throwing the exception or doing a |
| 2904 | // more involved array check. |
| 2905 | __ Bnec(temp, cls, slow_path->GetEntryLabel()); |
| 2906 | break; |
| 2907 | } |
| 2908 | |
| 2909 | case TypeCheckKind::kAbstractClassCheck: { |
| 2910 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2911 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2912 | temp_loc, |
| 2913 | obj_loc, |
| 2914 | class_offset, |
| 2915 | maybe_temp2_loc, |
| 2916 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2917 | // If the class is abstract, we eagerly fetch the super class of the |
| 2918 | // object to avoid doing a comparison we know will fail. |
| 2919 | Mips64Label loop; |
| 2920 | __ Bind(&loop); |
| 2921 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2922 | GenerateReferenceLoadOneRegister(instruction, |
| 2923 | temp_loc, |
| 2924 | super_offset, |
| 2925 | maybe_temp2_loc, |
| 2926 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2927 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2928 | // exception. |
| 2929 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2930 | // Otherwise, compare the classes. |
| 2931 | __ Bnec(temp, cls, &loop); |
| 2932 | break; |
| 2933 | } |
| 2934 | |
| 2935 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2936 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2937 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2938 | temp_loc, |
| 2939 | obj_loc, |
| 2940 | class_offset, |
| 2941 | maybe_temp2_loc, |
| 2942 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2943 | // Walk over the class hierarchy to find a match. |
| 2944 | Mips64Label loop; |
| 2945 | __ Bind(&loop); |
| 2946 | __ Beqc(temp, cls, &done); |
| 2947 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2948 | GenerateReferenceLoadOneRegister(instruction, |
| 2949 | temp_loc, |
| 2950 | super_offset, |
| 2951 | maybe_temp2_loc, |
| 2952 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2953 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2954 | // exception. Otherwise, jump to the beginning of the loop. |
| 2955 | __ Bnezc(temp, &loop); |
| 2956 | __ Bc(slow_path->GetEntryLabel()); |
| 2957 | break; |
| 2958 | } |
| 2959 | |
| 2960 | case TypeCheckKind::kArrayObjectCheck: { |
| 2961 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2962 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2963 | temp_loc, |
| 2964 | obj_loc, |
| 2965 | class_offset, |
| 2966 | maybe_temp2_loc, |
| 2967 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2968 | // Do an exact check. |
| 2969 | __ Beqc(temp, cls, &done); |
| 2970 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 2971 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2972 | GenerateReferenceLoadOneRegister(instruction, |
| 2973 | temp_loc, |
| 2974 | component_offset, |
| 2975 | maybe_temp2_loc, |
| 2976 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2977 | // If the component type is null, jump to the slow path to throw the exception. |
| 2978 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2979 | // Otherwise, the object is indeed an array, further check that this component |
| 2980 | // type is not a primitive type. |
| 2981 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 2982 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2983 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
| 2984 | break; |
| 2985 | } |
| 2986 | |
| 2987 | case TypeCheckKind::kUnresolvedCheck: |
| 2988 | // We always go into the type check slow path for the unresolved check case. |
| 2989 | // We cannot directly call the CheckCast runtime entry point |
| 2990 | // without resorting to a type checking slow path here (i.e. by |
| 2991 | // calling InvokeRuntime directly), as it would require to |
| 2992 | // assign fixed registers for the inputs of this HInstanceOf |
| 2993 | // instruction (following the runtime calling convention), which |
| 2994 | // might be cluttered by the potential first read barrier |
| 2995 | // emission at the beginning of this method. |
| 2996 | __ Bc(slow_path->GetEntryLabel()); |
| 2997 | break; |
| 2998 | |
| 2999 | case TypeCheckKind::kInterfaceCheck: { |
| 3000 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3001 | // positives by doing this. |
| 3002 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3003 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3004 | temp_loc, |
| 3005 | obj_loc, |
| 3006 | class_offset, |
| 3007 | maybe_temp2_loc, |
| 3008 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3009 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3010 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3011 | temp_loc, |
| 3012 | temp_loc, |
| 3013 | iftable_offset, |
| 3014 | maybe_temp2_loc, |
| 3015 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3016 | // Iftable is never null. |
| 3017 | __ Lw(TMP, temp, array_length_offset); |
| 3018 | // Loop through the iftable and check if any class matches. |
| 3019 | Mips64Label loop; |
| 3020 | __ Bind(&loop); |
| 3021 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 3022 | __ Lwu(AT, temp, object_array_data_offset); |
| 3023 | __ MaybeUnpoisonHeapReference(AT); |
| 3024 | // Go to next interface. |
| 3025 | __ Daddiu(temp, temp, 2 * kHeapReferenceSize); |
| 3026 | __ Addiu(TMP, TMP, -2); |
| 3027 | // Compare the classes and continue the loop if they do not match. |
| 3028 | __ Bnec(AT, cls, &loop); |
| 3029 | break; |
| 3030 | } |
| 3031 | } |
| 3032 | |
| 3033 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3034 | __ Bind(slow_path->GetExitLabel()); |
| 3035 | } |
| 3036 | |
| 3037 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 3038 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3039 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3041 | if (check->HasUses()) { |
| 3042 | locations->SetOut(Location::SameAsFirstInput()); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 3047 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3048 | SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64( |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3049 | check->GetLoadClass(), |
| 3050 | check, |
| 3051 | check->GetDexPc(), |
| 3052 | true); |
| 3053 | codegen_->AddSlowPath(slow_path); |
| 3054 | GenerateClassInitializationCheck(slow_path, |
| 3055 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 3056 | } |
| 3057 | |
| 3058 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3059 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3060 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3061 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3062 | |
| 3063 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3064 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3065 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3066 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3067 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3068 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3069 | case DataType::Type::kInt32: |
| 3070 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3071 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3072 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3073 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3074 | break; |
| 3075 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3076 | case DataType::Type::kFloat32: |
| 3077 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3078 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3079 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3080 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3081 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3082 | |
| 3083 | default: |
| 3084 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3085 | } |
| 3086 | } |
| 3087 | |
| 3088 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 3089 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3090 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3091 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3092 | |
| 3093 | // 0 if: left == right |
| 3094 | // 1 if: left > right |
| 3095 | // -1 if: left < right |
| 3096 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3097 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3098 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3099 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3100 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3101 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3102 | case DataType::Type::kInt32: |
| 3103 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3104 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3105 | Location rhs_location = locations->InAt(1); |
| 3106 | bool use_imm = rhs_location.IsConstant(); |
| 3107 | GpuRegister rhs = ZERO; |
| 3108 | if (use_imm) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3109 | if (in_type == DataType::Type::kInt64) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3110 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3111 | if (value != 0) { |
| 3112 | rhs = AT; |
| 3113 | __ LoadConst64(rhs, value); |
| 3114 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3115 | } else { |
| 3116 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3117 | if (value != 0) { |
| 3118 | rhs = AT; |
| 3119 | __ LoadConst32(rhs, value); |
| 3120 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3121 | } |
| 3122 | } else { |
| 3123 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 3124 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3125 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3126 | __ Slt(res, rhs, lhs); |
| 3127 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3128 | break; |
| 3129 | } |
| 3130 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3131 | case DataType::Type::kFloat32: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3132 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3133 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3134 | Mips64Label done; |
| 3135 | __ CmpEqS(FTMP, lhs, rhs); |
| 3136 | __ LoadConst32(res, 0); |
| 3137 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3138 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3139 | __ CmpLtS(FTMP, lhs, rhs); |
| 3140 | __ LoadConst32(res, -1); |
| 3141 | __ Bc1nez(FTMP, &done); |
| 3142 | __ LoadConst32(res, 1); |
| 3143 | } else { |
| 3144 | __ CmpLtS(FTMP, rhs, lhs); |
| 3145 | __ LoadConst32(res, 1); |
| 3146 | __ Bc1nez(FTMP, &done); |
| 3147 | __ LoadConst32(res, -1); |
| 3148 | } |
| 3149 | __ Bind(&done); |
| 3150 | break; |
| 3151 | } |
| 3152 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3153 | case DataType::Type::kFloat64: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3154 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3155 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3156 | Mips64Label done; |
| 3157 | __ CmpEqD(FTMP, lhs, rhs); |
| 3158 | __ LoadConst32(res, 0); |
| 3159 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3160 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3161 | __ CmpLtD(FTMP, lhs, rhs); |
| 3162 | __ LoadConst32(res, -1); |
| 3163 | __ Bc1nez(FTMP, &done); |
| 3164 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3165 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3166 | __ CmpLtD(FTMP, rhs, lhs); |
| 3167 | __ LoadConst32(res, 1); |
| 3168 | __ Bc1nez(FTMP, &done); |
| 3169 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3170 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3171 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3172 | break; |
| 3173 | } |
| 3174 | |
| 3175 | default: |
| 3176 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3177 | } |
| 3178 | } |
| 3179 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3180 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3181 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3182 | switch (instruction->InputAt(0)->GetType()) { |
| 3183 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3184 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3185 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3186 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3187 | break; |
| 3188 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3189 | case DataType::Type::kFloat32: |
| 3190 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3191 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3192 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3193 | break; |
| 3194 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3195 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3196 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3197 | } |
| 3198 | } |
| 3199 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3200 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3201 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3202 | return; |
| 3203 | } |
| 3204 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3205 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3206 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3207 | switch (type) { |
| 3208 | default: |
| 3209 | // Integer case. |
| 3210 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 3211 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3212 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3213 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 3214 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3215 | case DataType::Type::kFloat32: |
| 3216 | case DataType::Type::kFloat64: |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3217 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3218 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3219 | } |
| 3220 | } |
| 3221 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3222 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3223 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3224 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3225 | |
| 3226 | LocationSummary* locations = instruction->GetLocations(); |
| 3227 | Location second = locations->InAt(1); |
| 3228 | DCHECK(second.IsConstant()); |
| 3229 | |
| 3230 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3231 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3232 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3233 | DCHECK(imm == 1 || imm == -1); |
| 3234 | |
| 3235 | if (instruction->IsRem()) { |
| 3236 | __ Move(out, ZERO); |
| 3237 | } else { |
| 3238 | if (imm == -1) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3239 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3240 | __ Subu(out, ZERO, dividend); |
| 3241 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3242 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3243 | __ Dsubu(out, ZERO, dividend); |
| 3244 | } |
| 3245 | } else if (out != dividend) { |
| 3246 | __ Move(out, dividend); |
| 3247 | } |
| 3248 | } |
| 3249 | } |
| 3250 | |
| 3251 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3252 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3253 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3254 | |
| 3255 | LocationSummary* locations = instruction->GetLocations(); |
| 3256 | Location second = locations->InAt(1); |
| 3257 | DCHECK(second.IsConstant()); |
| 3258 | |
| 3259 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3260 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3261 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3262 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3263 | int ctz_imm = CTZ(abs_imm); |
| 3264 | |
| 3265 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3266 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3267 | if (ctz_imm == 1) { |
| 3268 | // Fast path for division by +/-2, which is very common. |
| 3269 | __ Srl(TMP, dividend, 31); |
| 3270 | } else { |
| 3271 | __ Sra(TMP, dividend, 31); |
| 3272 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3273 | } |
| 3274 | __ Addu(out, dividend, TMP); |
| 3275 | __ Sra(out, out, ctz_imm); |
| 3276 | if (imm < 0) { |
| 3277 | __ Subu(out, ZERO, out); |
| 3278 | } |
| 3279 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3280 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3281 | if (ctz_imm == 1) { |
| 3282 | // Fast path for division by +/-2, which is very common. |
| 3283 | __ Dsrl32(TMP, dividend, 31); |
| 3284 | } else { |
| 3285 | __ Dsra32(TMP, dividend, 31); |
| 3286 | if (ctz_imm > 32) { |
| 3287 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3288 | } else { |
| 3289 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3290 | } |
| 3291 | } |
| 3292 | __ Daddu(out, dividend, TMP); |
| 3293 | if (ctz_imm < 32) { |
| 3294 | __ Dsra(out, out, ctz_imm); |
| 3295 | } else { |
| 3296 | __ Dsra32(out, out, ctz_imm - 32); |
| 3297 | } |
| 3298 | if (imm < 0) { |
| 3299 | __ Dsubu(out, ZERO, out); |
| 3300 | } |
| 3301 | } |
| 3302 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3303 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3304 | if (ctz_imm == 1) { |
| 3305 | // Fast path for modulo +/-2, which is very common. |
| 3306 | __ Sra(TMP, dividend, 31); |
| 3307 | __ Subu(out, dividend, TMP); |
| 3308 | __ Andi(out, out, 1); |
| 3309 | __ Addu(out, out, TMP); |
| 3310 | } else { |
| 3311 | __ Sra(TMP, dividend, 31); |
| 3312 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3313 | __ Addu(out, dividend, TMP); |
| 3314 | if (IsUint<16>(abs_imm - 1)) { |
| 3315 | __ Andi(out, out, abs_imm - 1); |
| 3316 | } else { |
| 3317 | __ Sll(out, out, 32 - ctz_imm); |
| 3318 | __ Srl(out, out, 32 - ctz_imm); |
| 3319 | } |
| 3320 | __ Subu(out, out, TMP); |
| 3321 | } |
| 3322 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3323 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3324 | if (ctz_imm == 1) { |
| 3325 | // Fast path for modulo +/-2, which is very common. |
| 3326 | __ Dsra32(TMP, dividend, 31); |
| 3327 | __ Dsubu(out, dividend, TMP); |
| 3328 | __ Andi(out, out, 1); |
| 3329 | __ Daddu(out, out, TMP); |
| 3330 | } else { |
| 3331 | __ Dsra32(TMP, dividend, 31); |
| 3332 | if (ctz_imm > 32) { |
| 3333 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3334 | } else { |
| 3335 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3336 | } |
| 3337 | __ Daddu(out, dividend, TMP); |
| 3338 | if (IsUint<16>(abs_imm - 1)) { |
| 3339 | __ Andi(out, out, abs_imm - 1); |
| 3340 | } else { |
| 3341 | if (ctz_imm > 32) { |
| 3342 | __ Dsll(out, out, 64 - ctz_imm); |
| 3343 | __ Dsrl(out, out, 64 - ctz_imm); |
| 3344 | } else { |
| 3345 | __ Dsll32(out, out, 32 - ctz_imm); |
| 3346 | __ Dsrl32(out, out, 32 - ctz_imm); |
| 3347 | } |
| 3348 | } |
| 3349 | __ Dsubu(out, out, TMP); |
| 3350 | } |
| 3351 | } |
| 3352 | } |
| 3353 | } |
| 3354 | |
| 3355 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3356 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3357 | |
| 3358 | LocationSummary* locations = instruction->GetLocations(); |
| 3359 | Location second = locations->InAt(1); |
| 3360 | DCHECK(second.IsConstant()); |
| 3361 | |
| 3362 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3363 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3364 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3365 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3366 | DataType::Type type = instruction->GetResultType(); |
| 3367 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3368 | |
| 3369 | int64_t magic; |
| 3370 | int shift; |
| 3371 | CalculateMagicAndShiftForDivRem(imm, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3372 | (type == DataType::Type::kInt64), |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3373 | &magic, |
| 3374 | &shift); |
| 3375 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3376 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3377 | __ LoadConst32(TMP, magic); |
| 3378 | __ MuhR6(TMP, dividend, TMP); |
| 3379 | |
| 3380 | if (imm > 0 && magic < 0) { |
| 3381 | __ Addu(TMP, TMP, dividend); |
| 3382 | } else if (imm < 0 && magic > 0) { |
| 3383 | __ Subu(TMP, TMP, dividend); |
| 3384 | } |
| 3385 | |
| 3386 | if (shift != 0) { |
| 3387 | __ Sra(TMP, TMP, shift); |
| 3388 | } |
| 3389 | |
| 3390 | if (instruction->IsDiv()) { |
| 3391 | __ Sra(out, TMP, 31); |
| 3392 | __ Subu(out, TMP, out); |
| 3393 | } else { |
| 3394 | __ Sra(AT, TMP, 31); |
| 3395 | __ Subu(AT, TMP, AT); |
| 3396 | __ LoadConst32(TMP, imm); |
| 3397 | __ MulR6(TMP, AT, TMP); |
| 3398 | __ Subu(out, dividend, TMP); |
| 3399 | } |
| 3400 | } else { |
| 3401 | __ LoadConst64(TMP, magic); |
| 3402 | __ Dmuh(TMP, dividend, TMP); |
| 3403 | |
| 3404 | if (imm > 0 && magic < 0) { |
| 3405 | __ Daddu(TMP, TMP, dividend); |
| 3406 | } else if (imm < 0 && magic > 0) { |
| 3407 | __ Dsubu(TMP, TMP, dividend); |
| 3408 | } |
| 3409 | |
| 3410 | if (shift >= 32) { |
| 3411 | __ Dsra32(TMP, TMP, shift - 32); |
| 3412 | } else if (shift > 0) { |
| 3413 | __ Dsra(TMP, TMP, shift); |
| 3414 | } |
| 3415 | |
| 3416 | if (instruction->IsDiv()) { |
| 3417 | __ Dsra32(out, TMP, 31); |
| 3418 | __ Dsubu(out, TMP, out); |
| 3419 | } else { |
| 3420 | __ Dsra32(AT, TMP, 31); |
| 3421 | __ Dsubu(AT, TMP, AT); |
| 3422 | __ LoadConst64(TMP, imm); |
| 3423 | __ Dmul(TMP, AT, TMP); |
| 3424 | __ Dsubu(out, dividend, TMP); |
| 3425 | } |
| 3426 | } |
| 3427 | } |
| 3428 | |
| 3429 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3430 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3431 | DataType::Type type = instruction->GetResultType(); |
| 3432 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3433 | |
| 3434 | LocationSummary* locations = instruction->GetLocations(); |
| 3435 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3436 | Location second = locations->InAt(1); |
| 3437 | |
| 3438 | if (second.IsConstant()) { |
| 3439 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3440 | if (imm == 0) { |
| 3441 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3442 | } else if (imm == 1 || imm == -1) { |
| 3443 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3444 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3445 | DivRemByPowerOfTwo(instruction); |
| 3446 | } else { |
| 3447 | DCHECK(imm <= -2 || imm >= 2); |
| 3448 | GenerateDivRemWithAnyConstant(instruction); |
| 3449 | } |
| 3450 | } else { |
| 3451 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3452 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 3453 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3454 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3455 | __ DivR6(out, dividend, divisor); |
| 3456 | else |
| 3457 | __ Ddiv(out, dividend, divisor); |
| 3458 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3459 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3460 | __ ModR6(out, dividend, divisor); |
| 3461 | else |
| 3462 | __ Dmod(out, dividend, divisor); |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| 3466 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3467 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 3468 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3469 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3470 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3471 | case DataType::Type::kInt32: |
| 3472 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3473 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3474 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3475 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3476 | break; |
| 3477 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3478 | case DataType::Type::kFloat32: |
| 3479 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3480 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3481 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3482 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3483 | break; |
| 3484 | |
| 3485 | default: |
| 3486 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3491 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3492 | LocationSummary* locations = instruction->GetLocations(); |
| 3493 | |
| 3494 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3495 | case DataType::Type::kInt32: |
| 3496 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3497 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3498 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3499 | case DataType::Type::kFloat32: |
| 3500 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3501 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3502 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3503 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3504 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3505 | __ DivS(dst, lhs, rhs); |
| 3506 | else |
| 3507 | __ DivD(dst, lhs, rhs); |
| 3508 | break; |
| 3509 | } |
| 3510 | default: |
| 3511 | LOG(FATAL) << "Unexpected div type " << type; |
| 3512 | } |
| 3513 | } |
| 3514 | |
| 3515 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3516 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3517 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3521 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3522 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3523 | codegen_->AddSlowPath(slow_path); |
| 3524 | Location value = instruction->GetLocations()->InAt(0); |
| 3525 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3526 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3527 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3528 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3529 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3530 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | if (value.IsConstant()) { |
| 3534 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 3535 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3536 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3537 | } else { |
| 3538 | // A division by a non-null constant is valid. We don't need to perform |
| 3539 | // any check, so simply fall through. |
| 3540 | } |
| 3541 | } else { |
| 3542 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3543 | } |
| 3544 | } |
| 3545 | |
| 3546 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3547 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3548 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3549 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3550 | } |
| 3551 | |
| 3552 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3553 | // Will be generated at use site. |
| 3554 | } |
| 3555 | |
| 3556 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 3557 | exit->SetLocations(nullptr); |
| 3558 | } |
| 3559 | |
| 3560 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3561 | } |
| 3562 | |
| 3563 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 3564 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3565 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3566 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3570 | // Will be generated at use site. |
| 3571 | } |
| 3572 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3573 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3574 | DCHECK(!successor->IsExitBlock()); |
| 3575 | HBasicBlock* block = got->GetBlock(); |
| 3576 | HInstruction* previous = got->GetPrevious(); |
| 3577 | HLoopInformation* info = block->GetLoopInformation(); |
| 3578 | |
| 3579 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3580 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3581 | return; |
| 3582 | } |
| 3583 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3584 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3585 | } |
| 3586 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3587 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3588 | } |
| 3589 | } |
| 3590 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3591 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 3592 | got->SetLocations(nullptr); |
| 3593 | } |
| 3594 | |
| 3595 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 3596 | HandleGoto(got, got->GetSuccessor()); |
| 3597 | } |
| 3598 | |
| 3599 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3600 | try_boundary->SetLocations(nullptr); |
| 3601 | } |
| 3602 | |
| 3603 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3604 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3605 | if (!successor->IsExitBlock()) { |
| 3606 | HandleGoto(try_boundary, successor); |
| 3607 | } |
| 3608 | } |
| 3609 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3610 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 3611 | bool is64bit, |
| 3612 | LocationSummary* locations) { |
| 3613 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3614 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3615 | Location rhs_location = locations->InAt(1); |
| 3616 | GpuRegister rhs_reg = ZERO; |
| 3617 | int64_t rhs_imm = 0; |
| 3618 | bool use_imm = rhs_location.IsConstant(); |
| 3619 | if (use_imm) { |
| 3620 | if (is64bit) { |
| 3621 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3622 | } else { |
| 3623 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3624 | } |
| 3625 | } else { |
| 3626 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3627 | } |
| 3628 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3629 | |
| 3630 | switch (cond) { |
| 3631 | case kCondEQ: |
| 3632 | case kCondNE: |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3633 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3634 | if (rhs_imm == 0) { |
| 3635 | if (cond == kCondEQ) { |
| 3636 | __ Sltiu(dst, lhs, 1); |
| 3637 | } else { |
| 3638 | __ Sltu(dst, ZERO, lhs); |
| 3639 | } |
| 3640 | } else { |
| 3641 | if (is64bit) { |
| 3642 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3643 | } else { |
| 3644 | __ Addiu(dst, lhs, -rhs_imm); |
| 3645 | } |
| 3646 | if (cond == kCondEQ) { |
| 3647 | __ Sltiu(dst, dst, 1); |
| 3648 | } else { |
| 3649 | __ Sltu(dst, ZERO, dst); |
| 3650 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3651 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3652 | } else { |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3653 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3654 | __ Xori(dst, lhs, rhs_imm); |
| 3655 | } else { |
| 3656 | if (use_imm) { |
| 3657 | rhs_reg = TMP; |
| 3658 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3659 | } |
| 3660 | __ Xor(dst, lhs, rhs_reg); |
| 3661 | } |
| 3662 | if (cond == kCondEQ) { |
| 3663 | __ Sltiu(dst, dst, 1); |
| 3664 | } else { |
| 3665 | __ Sltu(dst, ZERO, dst); |
| 3666 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3667 | } |
| 3668 | break; |
| 3669 | |
| 3670 | case kCondLT: |
| 3671 | case kCondGE: |
| 3672 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3673 | __ Slti(dst, lhs, rhs_imm); |
| 3674 | } else { |
| 3675 | if (use_imm) { |
| 3676 | rhs_reg = TMP; |
| 3677 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3678 | } |
| 3679 | __ Slt(dst, lhs, rhs_reg); |
| 3680 | } |
| 3681 | if (cond == kCondGE) { |
| 3682 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3683 | // only the slt instruction but no sge. |
| 3684 | __ Xori(dst, dst, 1); |
| 3685 | } |
| 3686 | break; |
| 3687 | |
| 3688 | case kCondLE: |
| 3689 | case kCondGT: |
| 3690 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3691 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3692 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3693 | if (cond == kCondGT) { |
| 3694 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3695 | // only the slti instruction but no sgti. |
| 3696 | __ Xori(dst, dst, 1); |
| 3697 | } |
| 3698 | } else { |
| 3699 | if (use_imm) { |
| 3700 | rhs_reg = TMP; |
| 3701 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3702 | } |
| 3703 | __ Slt(dst, rhs_reg, lhs); |
| 3704 | if (cond == kCondLE) { |
| 3705 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3706 | // only the slt instruction but no sle. |
| 3707 | __ Xori(dst, dst, 1); |
| 3708 | } |
| 3709 | } |
| 3710 | break; |
| 3711 | |
| 3712 | case kCondB: |
| 3713 | case kCondAE: |
| 3714 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3715 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3716 | // the comparison and thus lets us compare directly with |
| 3717 | // unsigned values in the ranges [0, 0x7fff] and |
| 3718 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3719 | __ Sltiu(dst, lhs, rhs_imm); |
| 3720 | } else { |
| 3721 | if (use_imm) { |
| 3722 | rhs_reg = TMP; |
| 3723 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3724 | } |
| 3725 | __ Sltu(dst, lhs, rhs_reg); |
| 3726 | } |
| 3727 | if (cond == kCondAE) { |
| 3728 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3729 | // only the sltu instruction but no sgeu. |
| 3730 | __ Xori(dst, dst, 1); |
| 3731 | } |
| 3732 | break; |
| 3733 | |
| 3734 | case kCondBE: |
| 3735 | case kCondA: |
| 3736 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3737 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3738 | // Note that this only works if rhs + 1 does not overflow |
| 3739 | // to 0, hence the check above. |
| 3740 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3741 | // the comparison and thus lets us compare directly with |
| 3742 | // unsigned values in the ranges [0, 0x7fff] and |
| 3743 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3744 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3745 | if (cond == kCondA) { |
| 3746 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3747 | // only the sltiu instruction but no sgtiu. |
| 3748 | __ Xori(dst, dst, 1); |
| 3749 | } |
| 3750 | } else { |
| 3751 | if (use_imm) { |
| 3752 | rhs_reg = TMP; |
| 3753 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3754 | } |
| 3755 | __ Sltu(dst, rhs_reg, lhs); |
| 3756 | if (cond == kCondBE) { |
| 3757 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3758 | // only the sltu instruction but no sleu. |
| 3759 | __ Xori(dst, dst, 1); |
| 3760 | } |
| 3761 | } |
| 3762 | break; |
| 3763 | } |
| 3764 | } |
| 3765 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3766 | bool InstructionCodeGeneratorMIPS64::MaterializeIntLongCompare(IfCondition cond, |
| 3767 | bool is64bit, |
| 3768 | LocationSummary* input_locations, |
| 3769 | GpuRegister dst) { |
| 3770 | GpuRegister lhs = input_locations->InAt(0).AsRegister<GpuRegister>(); |
| 3771 | Location rhs_location = input_locations->InAt(1); |
| 3772 | GpuRegister rhs_reg = ZERO; |
| 3773 | int64_t rhs_imm = 0; |
| 3774 | bool use_imm = rhs_location.IsConstant(); |
| 3775 | if (use_imm) { |
| 3776 | if (is64bit) { |
| 3777 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3778 | } else { |
| 3779 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3780 | } |
| 3781 | } else { |
| 3782 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3783 | } |
| 3784 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3785 | |
| 3786 | switch (cond) { |
| 3787 | case kCondEQ: |
| 3788 | case kCondNE: |
| 3789 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3790 | if (is64bit) { |
| 3791 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3792 | } else { |
| 3793 | __ Addiu(dst, lhs, -rhs_imm); |
| 3794 | } |
| 3795 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 3796 | __ Xori(dst, lhs, rhs_imm); |
| 3797 | } else { |
| 3798 | if (use_imm) { |
| 3799 | rhs_reg = TMP; |
| 3800 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3801 | } |
| 3802 | __ Xor(dst, lhs, rhs_reg); |
| 3803 | } |
| 3804 | return (cond == kCondEQ); |
| 3805 | |
| 3806 | case kCondLT: |
| 3807 | case kCondGE: |
| 3808 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3809 | __ Slti(dst, lhs, rhs_imm); |
| 3810 | } else { |
| 3811 | if (use_imm) { |
| 3812 | rhs_reg = TMP; |
| 3813 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3814 | } |
| 3815 | __ Slt(dst, lhs, rhs_reg); |
| 3816 | } |
| 3817 | return (cond == kCondGE); |
| 3818 | |
| 3819 | case kCondLE: |
| 3820 | case kCondGT: |
| 3821 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3822 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3823 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3824 | return (cond == kCondGT); |
| 3825 | } else { |
| 3826 | if (use_imm) { |
| 3827 | rhs_reg = TMP; |
| 3828 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3829 | } |
| 3830 | __ Slt(dst, rhs_reg, lhs); |
| 3831 | return (cond == kCondLE); |
| 3832 | } |
| 3833 | |
| 3834 | case kCondB: |
| 3835 | case kCondAE: |
| 3836 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3837 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3838 | // the comparison and thus lets us compare directly with |
| 3839 | // unsigned values in the ranges [0, 0x7fff] and |
| 3840 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3841 | __ Sltiu(dst, lhs, rhs_imm); |
| 3842 | } else { |
| 3843 | if (use_imm) { |
| 3844 | rhs_reg = TMP; |
| 3845 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3846 | } |
| 3847 | __ Sltu(dst, lhs, rhs_reg); |
| 3848 | } |
| 3849 | return (cond == kCondAE); |
| 3850 | |
| 3851 | case kCondBE: |
| 3852 | case kCondA: |
| 3853 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3854 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3855 | // Note that this only works if rhs + 1 does not overflow |
| 3856 | // to 0, hence the check above. |
| 3857 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3858 | // the comparison and thus lets us compare directly with |
| 3859 | // unsigned values in the ranges [0, 0x7fff] and |
| 3860 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3861 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3862 | return (cond == kCondA); |
| 3863 | } else { |
| 3864 | if (use_imm) { |
| 3865 | rhs_reg = TMP; |
| 3866 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3867 | } |
| 3868 | __ Sltu(dst, rhs_reg, lhs); |
| 3869 | return (cond == kCondBE); |
| 3870 | } |
| 3871 | } |
| 3872 | } |
| 3873 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3874 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 3875 | bool is64bit, |
| 3876 | LocationSummary* locations, |
| 3877 | Mips64Label* label) { |
| 3878 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3879 | Location rhs_location = locations->InAt(1); |
| 3880 | GpuRegister rhs_reg = ZERO; |
| 3881 | int64_t rhs_imm = 0; |
| 3882 | bool use_imm = rhs_location.IsConstant(); |
| 3883 | if (use_imm) { |
| 3884 | if (is64bit) { |
| 3885 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3886 | } else { |
| 3887 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3888 | } |
| 3889 | } else { |
| 3890 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3891 | } |
| 3892 | |
| 3893 | if (use_imm && rhs_imm == 0) { |
| 3894 | switch (cond) { |
| 3895 | case kCondEQ: |
| 3896 | case kCondBE: // <= 0 if zero |
| 3897 | __ Beqzc(lhs, label); |
| 3898 | break; |
| 3899 | case kCondNE: |
| 3900 | case kCondA: // > 0 if non-zero |
| 3901 | __ Bnezc(lhs, label); |
| 3902 | break; |
| 3903 | case kCondLT: |
| 3904 | __ Bltzc(lhs, label); |
| 3905 | break; |
| 3906 | case kCondGE: |
| 3907 | __ Bgezc(lhs, label); |
| 3908 | break; |
| 3909 | case kCondLE: |
| 3910 | __ Blezc(lhs, label); |
| 3911 | break; |
| 3912 | case kCondGT: |
| 3913 | __ Bgtzc(lhs, label); |
| 3914 | break; |
| 3915 | case kCondB: // always false |
| 3916 | break; |
| 3917 | case kCondAE: // always true |
| 3918 | __ Bc(label); |
| 3919 | break; |
| 3920 | } |
| 3921 | } else { |
| 3922 | if (use_imm) { |
| 3923 | rhs_reg = TMP; |
| 3924 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3925 | } |
| 3926 | switch (cond) { |
| 3927 | case kCondEQ: |
| 3928 | __ Beqc(lhs, rhs_reg, label); |
| 3929 | break; |
| 3930 | case kCondNE: |
| 3931 | __ Bnec(lhs, rhs_reg, label); |
| 3932 | break; |
| 3933 | case kCondLT: |
| 3934 | __ Bltc(lhs, rhs_reg, label); |
| 3935 | break; |
| 3936 | case kCondGE: |
| 3937 | __ Bgec(lhs, rhs_reg, label); |
| 3938 | break; |
| 3939 | case kCondLE: |
| 3940 | __ Bgec(rhs_reg, lhs, label); |
| 3941 | break; |
| 3942 | case kCondGT: |
| 3943 | __ Bltc(rhs_reg, lhs, label); |
| 3944 | break; |
| 3945 | case kCondB: |
| 3946 | __ Bltuc(lhs, rhs_reg, label); |
| 3947 | break; |
| 3948 | case kCondAE: |
| 3949 | __ Bgeuc(lhs, rhs_reg, label); |
| 3950 | break; |
| 3951 | case kCondBE: |
| 3952 | __ Bgeuc(rhs_reg, lhs, label); |
| 3953 | break; |
| 3954 | case kCondA: |
| 3955 | __ Bltuc(rhs_reg, lhs, label); |
| 3956 | break; |
| 3957 | } |
| 3958 | } |
| 3959 | } |
| 3960 | |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3961 | void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond, |
| 3962 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3963 | DataType::Type type, |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3964 | LocationSummary* locations) { |
| 3965 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3966 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3967 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3968 | if (type == DataType::Type::kFloat32) { |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3969 | switch (cond) { |
| 3970 | case kCondEQ: |
| 3971 | __ CmpEqS(FTMP, lhs, rhs); |
| 3972 | __ Mfc1(dst, FTMP); |
| 3973 | __ Andi(dst, dst, 1); |
| 3974 | break; |
| 3975 | case kCondNE: |
| 3976 | __ CmpEqS(FTMP, lhs, rhs); |
| 3977 | __ Mfc1(dst, FTMP); |
| 3978 | __ Addiu(dst, dst, 1); |
| 3979 | break; |
| 3980 | case kCondLT: |
| 3981 | if (gt_bias) { |
| 3982 | __ CmpLtS(FTMP, lhs, rhs); |
| 3983 | } else { |
| 3984 | __ CmpUltS(FTMP, lhs, rhs); |
| 3985 | } |
| 3986 | __ Mfc1(dst, FTMP); |
| 3987 | __ Andi(dst, dst, 1); |
| 3988 | break; |
| 3989 | case kCondLE: |
| 3990 | if (gt_bias) { |
| 3991 | __ CmpLeS(FTMP, lhs, rhs); |
| 3992 | } else { |
| 3993 | __ CmpUleS(FTMP, lhs, rhs); |
| 3994 | } |
| 3995 | __ Mfc1(dst, FTMP); |
| 3996 | __ Andi(dst, dst, 1); |
| 3997 | break; |
| 3998 | case kCondGT: |
| 3999 | if (gt_bias) { |
| 4000 | __ CmpUltS(FTMP, rhs, lhs); |
| 4001 | } else { |
| 4002 | __ CmpLtS(FTMP, rhs, lhs); |
| 4003 | } |
| 4004 | __ Mfc1(dst, FTMP); |
| 4005 | __ Andi(dst, dst, 1); |
| 4006 | break; |
| 4007 | case kCondGE: |
| 4008 | if (gt_bias) { |
| 4009 | __ CmpUleS(FTMP, rhs, lhs); |
| 4010 | } else { |
| 4011 | __ CmpLeS(FTMP, rhs, lhs); |
| 4012 | } |
| 4013 | __ Mfc1(dst, FTMP); |
| 4014 | __ Andi(dst, dst, 1); |
| 4015 | break; |
| 4016 | default: |
| 4017 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4018 | UNREACHABLE(); |
| 4019 | } |
| 4020 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4021 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 4022 | switch (cond) { |
| 4023 | case kCondEQ: |
| 4024 | __ CmpEqD(FTMP, lhs, rhs); |
| 4025 | __ Mfc1(dst, FTMP); |
| 4026 | __ Andi(dst, dst, 1); |
| 4027 | break; |
| 4028 | case kCondNE: |
| 4029 | __ CmpEqD(FTMP, lhs, rhs); |
| 4030 | __ Mfc1(dst, FTMP); |
| 4031 | __ Addiu(dst, dst, 1); |
| 4032 | break; |
| 4033 | case kCondLT: |
| 4034 | if (gt_bias) { |
| 4035 | __ CmpLtD(FTMP, lhs, rhs); |
| 4036 | } else { |
| 4037 | __ CmpUltD(FTMP, lhs, rhs); |
| 4038 | } |
| 4039 | __ Mfc1(dst, FTMP); |
| 4040 | __ Andi(dst, dst, 1); |
| 4041 | break; |
| 4042 | case kCondLE: |
| 4043 | if (gt_bias) { |
| 4044 | __ CmpLeD(FTMP, lhs, rhs); |
| 4045 | } else { |
| 4046 | __ CmpUleD(FTMP, lhs, rhs); |
| 4047 | } |
| 4048 | __ Mfc1(dst, FTMP); |
| 4049 | __ Andi(dst, dst, 1); |
| 4050 | break; |
| 4051 | case kCondGT: |
| 4052 | if (gt_bias) { |
| 4053 | __ CmpUltD(FTMP, rhs, lhs); |
| 4054 | } else { |
| 4055 | __ CmpLtD(FTMP, rhs, lhs); |
| 4056 | } |
| 4057 | __ Mfc1(dst, FTMP); |
| 4058 | __ Andi(dst, dst, 1); |
| 4059 | break; |
| 4060 | case kCondGE: |
| 4061 | if (gt_bias) { |
| 4062 | __ CmpUleD(FTMP, rhs, lhs); |
| 4063 | } else { |
| 4064 | __ CmpLeD(FTMP, rhs, lhs); |
| 4065 | } |
| 4066 | __ Mfc1(dst, FTMP); |
| 4067 | __ Andi(dst, dst, 1); |
| 4068 | break; |
| 4069 | default: |
| 4070 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4071 | UNREACHABLE(); |
| 4072 | } |
| 4073 | } |
| 4074 | } |
| 4075 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4076 | bool InstructionCodeGeneratorMIPS64::MaterializeFpCompare(IfCondition cond, |
| 4077 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4078 | DataType::Type type, |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4079 | LocationSummary* input_locations, |
| 4080 | FpuRegister dst) { |
| 4081 | FpuRegister lhs = input_locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4082 | FpuRegister rhs = input_locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4083 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4084 | switch (cond) { |
| 4085 | case kCondEQ: |
| 4086 | __ CmpEqS(dst, lhs, rhs); |
| 4087 | return false; |
| 4088 | case kCondNE: |
| 4089 | __ CmpEqS(dst, lhs, rhs); |
| 4090 | return true; |
| 4091 | case kCondLT: |
| 4092 | if (gt_bias) { |
| 4093 | __ CmpLtS(dst, lhs, rhs); |
| 4094 | } else { |
| 4095 | __ CmpUltS(dst, lhs, rhs); |
| 4096 | } |
| 4097 | return false; |
| 4098 | case kCondLE: |
| 4099 | if (gt_bias) { |
| 4100 | __ CmpLeS(dst, lhs, rhs); |
| 4101 | } else { |
| 4102 | __ CmpUleS(dst, lhs, rhs); |
| 4103 | } |
| 4104 | return false; |
| 4105 | case kCondGT: |
| 4106 | if (gt_bias) { |
| 4107 | __ CmpUltS(dst, rhs, lhs); |
| 4108 | } else { |
| 4109 | __ CmpLtS(dst, rhs, lhs); |
| 4110 | } |
| 4111 | return false; |
| 4112 | case kCondGE: |
| 4113 | if (gt_bias) { |
| 4114 | __ CmpUleS(dst, rhs, lhs); |
| 4115 | } else { |
| 4116 | __ CmpLeS(dst, rhs, lhs); |
| 4117 | } |
| 4118 | return false; |
| 4119 | default: |
| 4120 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4121 | UNREACHABLE(); |
| 4122 | } |
| 4123 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4124 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4125 | switch (cond) { |
| 4126 | case kCondEQ: |
| 4127 | __ CmpEqD(dst, lhs, rhs); |
| 4128 | return false; |
| 4129 | case kCondNE: |
| 4130 | __ CmpEqD(dst, lhs, rhs); |
| 4131 | return true; |
| 4132 | case kCondLT: |
| 4133 | if (gt_bias) { |
| 4134 | __ CmpLtD(dst, lhs, rhs); |
| 4135 | } else { |
| 4136 | __ CmpUltD(dst, lhs, rhs); |
| 4137 | } |
| 4138 | return false; |
| 4139 | case kCondLE: |
| 4140 | if (gt_bias) { |
| 4141 | __ CmpLeD(dst, lhs, rhs); |
| 4142 | } else { |
| 4143 | __ CmpUleD(dst, lhs, rhs); |
| 4144 | } |
| 4145 | return false; |
| 4146 | case kCondGT: |
| 4147 | if (gt_bias) { |
| 4148 | __ CmpUltD(dst, rhs, lhs); |
| 4149 | } else { |
| 4150 | __ CmpLtD(dst, rhs, lhs); |
| 4151 | } |
| 4152 | return false; |
| 4153 | case kCondGE: |
| 4154 | if (gt_bias) { |
| 4155 | __ CmpUleD(dst, rhs, lhs); |
| 4156 | } else { |
| 4157 | __ CmpLeD(dst, rhs, lhs); |
| 4158 | } |
| 4159 | return false; |
| 4160 | default: |
| 4161 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4162 | UNREACHABLE(); |
| 4163 | } |
| 4164 | } |
| 4165 | } |
| 4166 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4167 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 4168 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4169 | DataType::Type type, |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4170 | LocationSummary* locations, |
| 4171 | Mips64Label* label) { |
| 4172 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4173 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4174 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4175 | switch (cond) { |
| 4176 | case kCondEQ: |
| 4177 | __ CmpEqS(FTMP, lhs, rhs); |
| 4178 | __ Bc1nez(FTMP, label); |
| 4179 | break; |
| 4180 | case kCondNE: |
| 4181 | __ CmpEqS(FTMP, lhs, rhs); |
| 4182 | __ Bc1eqz(FTMP, label); |
| 4183 | break; |
| 4184 | case kCondLT: |
| 4185 | if (gt_bias) { |
| 4186 | __ CmpLtS(FTMP, lhs, rhs); |
| 4187 | } else { |
| 4188 | __ CmpUltS(FTMP, lhs, rhs); |
| 4189 | } |
| 4190 | __ Bc1nez(FTMP, label); |
| 4191 | break; |
| 4192 | case kCondLE: |
| 4193 | if (gt_bias) { |
| 4194 | __ CmpLeS(FTMP, lhs, rhs); |
| 4195 | } else { |
| 4196 | __ CmpUleS(FTMP, lhs, rhs); |
| 4197 | } |
| 4198 | __ Bc1nez(FTMP, label); |
| 4199 | break; |
| 4200 | case kCondGT: |
| 4201 | if (gt_bias) { |
| 4202 | __ CmpUltS(FTMP, rhs, lhs); |
| 4203 | } else { |
| 4204 | __ CmpLtS(FTMP, rhs, lhs); |
| 4205 | } |
| 4206 | __ Bc1nez(FTMP, label); |
| 4207 | break; |
| 4208 | case kCondGE: |
| 4209 | if (gt_bias) { |
| 4210 | __ CmpUleS(FTMP, rhs, lhs); |
| 4211 | } else { |
| 4212 | __ CmpLeS(FTMP, rhs, lhs); |
| 4213 | } |
| 4214 | __ Bc1nez(FTMP, label); |
| 4215 | break; |
| 4216 | default: |
| 4217 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4218 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4219 | } |
| 4220 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4221 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4222 | switch (cond) { |
| 4223 | case kCondEQ: |
| 4224 | __ CmpEqD(FTMP, lhs, rhs); |
| 4225 | __ Bc1nez(FTMP, label); |
| 4226 | break; |
| 4227 | case kCondNE: |
| 4228 | __ CmpEqD(FTMP, lhs, rhs); |
| 4229 | __ Bc1eqz(FTMP, label); |
| 4230 | break; |
| 4231 | case kCondLT: |
| 4232 | if (gt_bias) { |
| 4233 | __ CmpLtD(FTMP, lhs, rhs); |
| 4234 | } else { |
| 4235 | __ CmpUltD(FTMP, lhs, rhs); |
| 4236 | } |
| 4237 | __ Bc1nez(FTMP, label); |
| 4238 | break; |
| 4239 | case kCondLE: |
| 4240 | if (gt_bias) { |
| 4241 | __ CmpLeD(FTMP, lhs, rhs); |
| 4242 | } else { |
| 4243 | __ CmpUleD(FTMP, lhs, rhs); |
| 4244 | } |
| 4245 | __ Bc1nez(FTMP, label); |
| 4246 | break; |
| 4247 | case kCondGT: |
| 4248 | if (gt_bias) { |
| 4249 | __ CmpUltD(FTMP, rhs, lhs); |
| 4250 | } else { |
| 4251 | __ CmpLtD(FTMP, rhs, lhs); |
| 4252 | } |
| 4253 | __ Bc1nez(FTMP, label); |
| 4254 | break; |
| 4255 | case kCondGE: |
| 4256 | if (gt_bias) { |
| 4257 | __ CmpUleD(FTMP, rhs, lhs); |
| 4258 | } else { |
| 4259 | __ CmpLeD(FTMP, rhs, lhs); |
| 4260 | } |
| 4261 | __ Bc1nez(FTMP, label); |
| 4262 | break; |
| 4263 | default: |
| 4264 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4265 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4266 | } |
| 4267 | } |
| 4268 | } |
| 4269 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4270 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4271 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4272 | Mips64Label* true_target, |
| 4273 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4274 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4275 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4276 | if (true_target == nullptr && false_target == nullptr) { |
| 4277 | // Nothing to do. The code always falls through. |
| 4278 | return; |
| 4279 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4280 | // Constant condition, statically compared against "true" (integer value 1). |
| 4281 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4282 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4283 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4284 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4285 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4286 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4287 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4288 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4289 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4290 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4291 | return; |
| 4292 | } |
| 4293 | |
| 4294 | // The following code generates these patterns: |
| 4295 | // (1) true_target == nullptr && false_target != nullptr |
| 4296 | // - opposite condition true => branch to false_target |
| 4297 | // (2) true_target != nullptr && false_target == nullptr |
| 4298 | // - condition true => branch to true_target |
| 4299 | // (3) true_target != nullptr && false_target != nullptr |
| 4300 | // - condition true => branch to true_target |
| 4301 | // - branch to false_target |
| 4302 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4303 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4304 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4305 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4306 | if (true_target == nullptr) { |
| 4307 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 4308 | } else { |
| 4309 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 4310 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4311 | } else { |
| 4312 | // The condition instruction has not been materialized, use its inputs as |
| 4313 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4314 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4315 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4316 | LocationSummary* locations = cond->GetLocations(); |
| 4317 | IfCondition if_cond = condition->GetCondition(); |
| 4318 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4319 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4320 | if (true_target == nullptr) { |
| 4321 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4322 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4323 | } |
| 4324 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4325 | switch (type) { |
| 4326 | default: |
| 4327 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 4328 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4329 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4330 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 4331 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4332 | case DataType::Type::kFloat32: |
| 4333 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4334 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4335 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4336 | } |
| 4337 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4338 | |
| 4339 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4340 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4341 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4342 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4343 | } |
| 4344 | } |
| 4345 | |
| 4346 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4347 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4348 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4349 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4350 | } |
| 4351 | } |
| 4352 | |
| 4353 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4354 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4355 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4356 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4357 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4358 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4359 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4360 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4364 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4365 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 4366 | InvokeRuntimeCallingConvention calling_convention; |
| 4367 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4368 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4369 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4370 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4371 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4372 | } |
| 4373 | } |
| 4374 | |
| 4375 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4376 | SlowPathCodeMIPS64* slow_path = |
| 4377 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4378 | GenerateTestAndBranch(deoptimize, |
| 4379 | /* condition_input_index */ 0, |
| 4380 | slow_path->GetEntryLabel(), |
| 4381 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4382 | } |
| 4383 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4384 | // This function returns true if a conditional move can be generated for HSelect. |
| 4385 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4386 | // branches and regular moves. |
| 4387 | // |
| 4388 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4389 | // |
| 4390 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4391 | // are two distinct tasks, this function does both because they share quite a bit |
| 4392 | // of common logic. |
| 4393 | static bool CanMoveConditionally(HSelect* select, LocationSummary* locations_to_set) { |
| 4394 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4395 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4396 | HCondition* condition = cond->AsCondition(); |
| 4397 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4398 | DataType::Type cond_type = |
| 4399 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 4400 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4401 | |
| 4402 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4403 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4404 | bool is_true_value_zero_constant = |
| 4405 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4406 | bool is_false_value_zero_constant = |
| 4407 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4408 | |
| 4409 | bool can_move_conditionally = false; |
| 4410 | bool use_const_for_false_in = false; |
| 4411 | bool use_const_for_true_in = false; |
| 4412 | |
| 4413 | if (!cond->IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4414 | if (!DataType::IsFloatingPointType(cond_type)) { |
| 4415 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4416 | // Moving int/long on int/long condition. |
| 4417 | if (is_true_value_zero_constant) { |
| 4418 | // seleqz out_reg, false_reg, cond_reg |
| 4419 | can_move_conditionally = true; |
| 4420 | use_const_for_true_in = true; |
| 4421 | } else if (is_false_value_zero_constant) { |
| 4422 | // selnez out_reg, true_reg, cond_reg |
| 4423 | can_move_conditionally = true; |
| 4424 | use_const_for_false_in = true; |
| 4425 | } else if (materialized) { |
| 4426 | // Not materializing unmaterialized int conditions |
| 4427 | // to keep the instruction count low. |
| 4428 | // selnez AT, true_reg, cond_reg |
| 4429 | // seleqz TMP, false_reg, cond_reg |
| 4430 | // or out_reg, AT, TMP |
| 4431 | can_move_conditionally = true; |
| 4432 | } |
| 4433 | } else { |
| 4434 | // Moving float/double on int/long condition. |
| 4435 | if (materialized) { |
| 4436 | // Not materializing unmaterialized int conditions |
| 4437 | // to keep the instruction count low. |
| 4438 | can_move_conditionally = true; |
| 4439 | if (is_true_value_zero_constant) { |
| 4440 | // sltu TMP, ZERO, cond_reg |
| 4441 | // mtc1 TMP, temp_cond_reg |
| 4442 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4443 | use_const_for_true_in = true; |
| 4444 | } else if (is_false_value_zero_constant) { |
| 4445 | // sltu TMP, ZERO, cond_reg |
| 4446 | // mtc1 TMP, temp_cond_reg |
| 4447 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4448 | use_const_for_false_in = true; |
| 4449 | } else { |
| 4450 | // sltu TMP, ZERO, cond_reg |
| 4451 | // mtc1 TMP, temp_cond_reg |
| 4452 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4453 | // mov.fmt out_reg, temp_cond_reg |
| 4454 | } |
| 4455 | } |
| 4456 | } |
| 4457 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4458 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4459 | // Moving int/long on float/double condition. |
| 4460 | can_move_conditionally = true; |
| 4461 | if (is_true_value_zero_constant) { |
| 4462 | // mfc1 TMP, temp_cond_reg |
| 4463 | // seleqz out_reg, false_reg, TMP |
| 4464 | use_const_for_true_in = true; |
| 4465 | } else if (is_false_value_zero_constant) { |
| 4466 | // mfc1 TMP, temp_cond_reg |
| 4467 | // selnez out_reg, true_reg, TMP |
| 4468 | use_const_for_false_in = true; |
| 4469 | } else { |
| 4470 | // mfc1 TMP, temp_cond_reg |
| 4471 | // selnez AT, true_reg, TMP |
| 4472 | // seleqz TMP, false_reg, TMP |
| 4473 | // or out_reg, AT, TMP |
| 4474 | } |
| 4475 | } else { |
| 4476 | // Moving float/double on float/double condition. |
| 4477 | can_move_conditionally = true; |
| 4478 | if (is_true_value_zero_constant) { |
| 4479 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4480 | use_const_for_true_in = true; |
| 4481 | } else if (is_false_value_zero_constant) { |
| 4482 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4483 | use_const_for_false_in = true; |
| 4484 | } else { |
| 4485 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4486 | // mov.fmt out_reg, temp_cond_reg |
| 4487 | } |
| 4488 | } |
| 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | if (can_move_conditionally) { |
| 4493 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4494 | } else { |
| 4495 | DCHECK(!use_const_for_false_in); |
| 4496 | DCHECK(!use_const_for_true_in); |
| 4497 | } |
| 4498 | |
| 4499 | if (locations_to_set != nullptr) { |
| 4500 | if (use_const_for_false_in) { |
| 4501 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4502 | } else { |
| 4503 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4504 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4505 | ? Location::RequiresFpuRegister() |
| 4506 | : Location::RequiresRegister()); |
| 4507 | } |
| 4508 | if (use_const_for_true_in) { |
| 4509 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4510 | } else { |
| 4511 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4512 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4513 | ? Location::RequiresFpuRegister() |
| 4514 | : Location::RequiresRegister()); |
| 4515 | } |
| 4516 | if (materialized) { |
| 4517 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4518 | } |
| 4519 | |
| 4520 | if (can_move_conditionally) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4521 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4522 | ? Location::RequiresFpuRegister() |
| 4523 | : Location::RequiresRegister()); |
| 4524 | } else { |
| 4525 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | return can_move_conditionally; |
| 4530 | } |
| 4531 | |
| 4532 | |
| 4533 | void InstructionCodeGeneratorMIPS64::GenConditionalMove(HSelect* select) { |
| 4534 | LocationSummary* locations = select->GetLocations(); |
| 4535 | Location dst = locations->Out(); |
| 4536 | Location false_src = locations->InAt(0); |
| 4537 | Location true_src = locations->InAt(1); |
| 4538 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4539 | GpuRegister cond_reg = TMP; |
| 4540 | FpuRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4541 | DataType::Type cond_type = DataType::Type::kInt32; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4542 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4543 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4544 | |
| 4545 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4546 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<GpuRegister>(); |
| 4547 | } else { |
| 4548 | HCondition* condition = cond->AsCondition(); |
| 4549 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4550 | IfCondition if_cond = condition->GetCondition(); |
| 4551 | cond_type = condition->InputAt(0)->GetType(); |
| 4552 | switch (cond_type) { |
| 4553 | default: |
| 4554 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4555 | /* is64bit */ false, |
| 4556 | cond_locations, |
| 4557 | cond_reg); |
| 4558 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4559 | case DataType::Type::kInt64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4560 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4561 | /* is64bit */ true, |
| 4562 | cond_locations, |
| 4563 | cond_reg); |
| 4564 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4565 | case DataType::Type::kFloat32: |
| 4566 | case DataType::Type::kFloat64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4567 | cond_inverted = MaterializeFpCompare(if_cond, |
| 4568 | condition->IsGtBias(), |
| 4569 | cond_type, |
| 4570 | cond_locations, |
| 4571 | fcond_reg); |
| 4572 | break; |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | if (true_src.IsConstant()) { |
| 4577 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4578 | } |
| 4579 | if (false_src.IsConstant()) { |
| 4580 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4581 | } |
| 4582 | |
| 4583 | switch (dst_type) { |
| 4584 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4585 | if (DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4586 | __ Mfc1(cond_reg, fcond_reg); |
| 4587 | } |
| 4588 | if (true_src.IsConstant()) { |
| 4589 | if (cond_inverted) { |
| 4590 | __ Selnez(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4591 | } else { |
| 4592 | __ Seleqz(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4593 | } |
| 4594 | } else if (false_src.IsConstant()) { |
| 4595 | if (cond_inverted) { |
| 4596 | __ Seleqz(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4597 | } else { |
| 4598 | __ Selnez(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4599 | } |
| 4600 | } else { |
| 4601 | DCHECK_NE(cond_reg, AT); |
| 4602 | if (cond_inverted) { |
| 4603 | __ Seleqz(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4604 | __ Selnez(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4605 | } else { |
| 4606 | __ Selnez(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4607 | __ Seleqz(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4608 | } |
| 4609 | __ Or(dst.AsRegister<GpuRegister>(), AT, TMP); |
| 4610 | } |
| 4611 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4612 | case DataType::Type::kFloat32: { |
| 4613 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4614 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4615 | __ Sltu(TMP, ZERO, cond_reg); |
| 4616 | __ Mtc1(TMP, fcond_reg); |
| 4617 | } |
| 4618 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4619 | if (true_src.IsConstant()) { |
| 4620 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4621 | if (cond_inverted) { |
| 4622 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4623 | } else { |
| 4624 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4625 | } |
| 4626 | } else if (false_src.IsConstant()) { |
| 4627 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4628 | if (cond_inverted) { |
| 4629 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4630 | } else { |
| 4631 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4632 | } |
| 4633 | } else { |
| 4634 | if (cond_inverted) { |
| 4635 | __ SelS(fcond_reg, |
| 4636 | true_src.AsFpuRegister<FpuRegister>(), |
| 4637 | false_src.AsFpuRegister<FpuRegister>()); |
| 4638 | } else { |
| 4639 | __ SelS(fcond_reg, |
| 4640 | false_src.AsFpuRegister<FpuRegister>(), |
| 4641 | true_src.AsFpuRegister<FpuRegister>()); |
| 4642 | } |
| 4643 | __ MovS(dst_reg, fcond_reg); |
| 4644 | } |
| 4645 | break; |
| 4646 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4647 | case DataType::Type::kFloat64: { |
| 4648 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4649 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4650 | __ Sltu(TMP, ZERO, cond_reg); |
| 4651 | __ Mtc1(TMP, fcond_reg); |
| 4652 | } |
| 4653 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4654 | if (true_src.IsConstant()) { |
| 4655 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4656 | if (cond_inverted) { |
| 4657 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4658 | } else { |
| 4659 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4660 | } |
| 4661 | } else if (false_src.IsConstant()) { |
| 4662 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4663 | if (cond_inverted) { |
| 4664 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4665 | } else { |
| 4666 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4667 | } |
| 4668 | } else { |
| 4669 | if (cond_inverted) { |
| 4670 | __ SelD(fcond_reg, |
| 4671 | true_src.AsFpuRegister<FpuRegister>(), |
| 4672 | false_src.AsFpuRegister<FpuRegister>()); |
| 4673 | } else { |
| 4674 | __ SelD(fcond_reg, |
| 4675 | false_src.AsFpuRegister<FpuRegister>(), |
| 4676 | true_src.AsFpuRegister<FpuRegister>()); |
| 4677 | } |
| 4678 | __ MovD(dst_reg, fcond_reg); |
| 4679 | } |
| 4680 | break; |
| 4681 | } |
| 4682 | } |
| 4683 | } |
| 4684 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4685 | void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4686 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4687 | LocationSummary(flag, LocationSummary::kNoCall); |
| 4688 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4691 | void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4692 | __ LoadFromOffset(kLoadWord, |
| 4693 | flag->GetLocations()->Out().AsRegister<GpuRegister>(), |
| 4694 | SP, |
| 4695 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4698 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4699 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4700 | CanMoveConditionally(select, locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4701 | } |
| 4702 | |
| 4703 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4704 | if (CanMoveConditionally(select, /* locations_to_set */ nullptr)) { |
| 4705 | GenConditionalMove(select); |
| 4706 | } else { |
| 4707 | LocationSummary* locations = select->GetLocations(); |
| 4708 | Mips64Label false_target; |
| 4709 | GenerateTestAndBranch(select, |
| 4710 | /* condition_input_index */ 2, |
| 4711 | /* true_target */ nullptr, |
| 4712 | &false_target); |
| 4713 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4714 | __ Bind(&false_target); |
| 4715 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4718 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4719 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4720 | } |
| 4721 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4722 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4723 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | void CodeGeneratorMIPS64::GenerateNop() { |
| 4727 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4730 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4731 | const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4732 | DataType::Type field_type = field_info.GetFieldType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4733 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4734 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4735 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4736 | instruction, |
| 4737 | object_field_get_with_read_barrier |
| 4738 | ? LocationSummary::kCallOnSlowPath |
| 4739 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4740 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4741 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4742 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4743 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4744 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4745 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4746 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4747 | // The output overlaps in the case of an object field get with |
| 4748 | // read barriers enabled: we do not want the move to overwrite the |
| 4749 | // object's location, as we need it to emit the read barrier. |
| 4750 | locations->SetOut(Location::RequiresRegister(), |
| 4751 | object_field_get_with_read_barrier |
| 4752 | ? Location::kOutputOverlap |
| 4753 | : Location::kNoOutputOverlap); |
| 4754 | } |
| 4755 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4756 | // We need a temporary register for the read barrier marking slow |
| 4757 | // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4758 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 4759 | locations->AddTemp(Location::RequiresRegister()); |
| 4760 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4761 | } |
| 4762 | } |
| 4763 | |
| 4764 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 4765 | const FieldInfo& field_info) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4766 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4767 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4768 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4769 | Location obj_loc = locations->InAt(0); |
| 4770 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 4771 | Location dst_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4772 | LoadOperandType load_type = kLoadUnsignedByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4773 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4774 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
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: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4780 | load_type = kLoadUnsignedByte; |
| 4781 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4782 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4783 | load_type = kLoadSignedByte; |
| 4784 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4785 | case DataType::Type::kUint16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4786 | load_type = kLoadUnsignedHalfword; |
| 4787 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4788 | case DataType::Type::kInt16: |
| 4789 | load_type = kLoadSignedHalfword; |
| 4790 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4791 | case DataType::Type::kInt32: |
| 4792 | case DataType::Type::kFloat32: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4793 | load_type = kLoadWord; |
| 4794 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4795 | case DataType::Type::kInt64: |
| 4796 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4797 | load_type = kLoadDoubleword; |
| 4798 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4799 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4800 | load_type = kLoadUnsignedWord; |
| 4801 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4802 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4803 | LOG(FATAL) << "Unreachable type " << type; |
| 4804 | UNREACHABLE(); |
| 4805 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4806 | if (!DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4807 | DCHECK(dst_loc.IsRegister()); |
| 4808 | GpuRegister dst = dst_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4809 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4810 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 4811 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4812 | Location temp_loc = |
| 4813 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4814 | // Note that a potential implicit null check is handled in this |
| 4815 | // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4816 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4817 | dst_loc, |
| 4818 | obj, |
| 4819 | offset, |
| 4820 | temp_loc, |
| 4821 | /* needs_null_check */ true); |
| 4822 | if (is_volatile) { |
| 4823 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4824 | } |
| 4825 | } else { |
| 4826 | __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker); |
| 4827 | if (is_volatile) { |
| 4828 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4829 | } |
| 4830 | // If read barriers are enabled, emit read barriers other than |
| 4831 | // Baker's using a slow path (and also unpoison the loaded |
| 4832 | // reference, if heap poisoning is enabled). |
| 4833 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 4834 | } |
| 4835 | } else { |
| 4836 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
| 4837 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4838 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4839 | DCHECK(dst_loc.IsFpuRegister()); |
| 4840 | FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4841 | __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4842 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4843 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4844 | // Memory barriers, in the case of references, are handled in the |
| 4845 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4846 | if (is_volatile && (type != DataType::Type::kReference)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4847 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4848 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 4852 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 4853 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4854 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4855 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4856 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4857 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4858 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4859 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4860 | } |
| 4861 | } |
| 4862 | |
| 4863 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4864 | const FieldInfo& field_info, |
| 4865 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4866 | DataType::Type type = field_info.GetFieldType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4867 | LocationSummary* locations = instruction->GetLocations(); |
| 4868 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4869 | Location value_location = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4870 | StoreOperandType store_type = kStoreByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4871 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4872 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4873 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4874 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4875 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4876 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4877 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4878 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4879 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4880 | store_type = kStoreByte; |
| 4881 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4882 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4883 | case DataType::Type::kInt16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4884 | store_type = kStoreHalfword; |
| 4885 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4886 | case DataType::Type::kInt32: |
| 4887 | case DataType::Type::kFloat32: |
| 4888 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4889 | store_type = kStoreWord; |
| 4890 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4891 | case DataType::Type::kInt64: |
| 4892 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4893 | store_type = kStoreDoubleword; |
| 4894 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4895 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4896 | LOG(FATAL) << "Unreachable type " << type; |
| 4897 | UNREACHABLE(); |
| 4898 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4899 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4900 | if (is_volatile) { |
| 4901 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4902 | } |
| 4903 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4904 | if (value_location.IsConstant()) { |
| 4905 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4906 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4907 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4908 | if (!DataType::IsFloatingPointType(type)) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4909 | DCHECK(value_location.IsRegister()); |
| 4910 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
| 4911 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4912 | // Note that in the case where `value` is a null reference, |
| 4913 | // we do not enter this block, as a null reference does not |
| 4914 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4915 | DCHECK_EQ(type, DataType::Type::kReference); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4916 | __ PoisonHeapReference(TMP, src); |
| 4917 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 4918 | } else { |
| 4919 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 4920 | } |
| 4921 | } else { |
| 4922 | DCHECK(value_location.IsFpuRegister()); |
| 4923 | FpuRegister src = value_location.AsFpuRegister<FpuRegister>(); |
| 4924 | __ StoreFpuToOffset(store_type, src, obj, offset, null_checker); |
| 4925 | } |
| 4926 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4927 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4928 | if (needs_write_barrier) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4929 | DCHECK(value_location.IsRegister()); |
| 4930 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4931 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4932 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4933 | |
| 4934 | if (is_volatile) { |
| 4935 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4936 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4940 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4941 | } |
| 4942 | |
| 4943 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4944 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4945 | } |
| 4946 | |
| 4947 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4948 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4949 | } |
| 4950 | |
| 4951 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4952 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4953 | } |
| 4954 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4955 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister( |
| 4956 | HInstruction* instruction, |
| 4957 | Location out, |
| 4958 | uint32_t offset, |
| 4959 | Location maybe_temp, |
| 4960 | ReadBarrierOption read_barrier_option) { |
| 4961 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4962 | if (read_barrier_option == kWithReadBarrier) { |
| 4963 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4964 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 4965 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4966 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4967 | if (kUseBakerReadBarrier) { |
| 4968 | // Load with fast path based Baker's read barrier. |
| 4969 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4970 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4971 | out, |
| 4972 | out_reg, |
| 4973 | offset, |
| 4974 | maybe_temp, |
| 4975 | /* needs_null_check */ false); |
| 4976 | } else { |
| 4977 | // Load with slow path based read barrier. |
| 4978 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4979 | // in the following move operation, as we will need it for the |
| 4980 | // read barrier below. |
| 4981 | __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg); |
| 4982 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4983 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4984 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4985 | } |
| 4986 | } else { |
| 4987 | // Plain load with no read barrier. |
| 4988 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4989 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4990 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4991 | } |
| 4992 | } |
| 4993 | |
| 4994 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters( |
| 4995 | HInstruction* instruction, |
| 4996 | Location out, |
| 4997 | Location obj, |
| 4998 | uint32_t offset, |
| 4999 | Location maybe_temp, |
| 5000 | ReadBarrierOption read_barrier_option) { |
| 5001 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 5002 | GpuRegister obj_reg = obj.AsRegister<GpuRegister>(); |
| 5003 | if (read_barrier_option == kWithReadBarrier) { |
| 5004 | CHECK(kEmitCompilerReadBarrier); |
| 5005 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5006 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 5007 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 5008 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5009 | // Load with fast path based Baker's read barrier. |
| 5010 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5011 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5012 | out, |
| 5013 | obj_reg, |
| 5014 | offset, |
| 5015 | maybe_temp, |
| 5016 | /* needs_null_check */ false); |
| 5017 | } else { |
| 5018 | // Load with slow path based read barrier. |
| 5019 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5020 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 5021 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5022 | } |
| 5023 | } else { |
| 5024 | // Plain load with no read barrier. |
| 5025 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5026 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 5027 | __ MaybeUnpoisonHeapReference(out_reg); |
| 5028 | } |
| 5029 | } |
| 5030 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5031 | static inline int GetBakerMarkThunkNumber(GpuRegister reg) { |
| 5032 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 20, "Expecting equal"); |
| 5033 | if (reg >= V0 && reg <= T2) { // 13 consequtive regs. |
| 5034 | return reg - V0; |
| 5035 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 5036 | return 13 + (reg - S2); |
| 5037 | } else if (reg == S8) { // One more. |
| 5038 | return 19; |
| 5039 | } |
| 5040 | LOG(FATAL) << "Unexpected register " << reg; |
| 5041 | UNREACHABLE(); |
| 5042 | } |
| 5043 | |
| 5044 | static inline int GetBakerMarkFieldArrayThunkDisplacement(GpuRegister reg, bool short_offset) { |
| 5045 | int num = GetBakerMarkThunkNumber(reg) + |
| 5046 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 5047 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 5048 | } |
| 5049 | |
| 5050 | static inline int GetBakerMarkGcRootThunkDisplacement(GpuRegister reg) { |
| 5051 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 5052 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 5053 | } |
| 5054 | |
| 5055 | void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5056 | Location root, |
| 5057 | GpuRegister obj, |
| 5058 | uint32_t offset, |
| 5059 | ReadBarrierOption read_barrier_option, |
| 5060 | Mips64Label* label_low) { |
| 5061 | if (label_low != nullptr) { |
| 5062 | DCHECK_EQ(offset, 0x5678u); |
| 5063 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5064 | GpuRegister root_reg = root.AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5065 | if (read_barrier_option == kWithReadBarrier) { |
| 5066 | DCHECK(kEmitCompilerReadBarrier); |
| 5067 | if (kUseBakerReadBarrier) { |
| 5068 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5069 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5070 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 5071 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5072 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5073 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5074 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5075 | // vice versa. |
| 5076 | // |
| 5077 | // We use thunks for the slow path. That thunk checks the reference |
| 5078 | // and jumps to the entrypoint if needed. |
| 5079 | // |
| 5080 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5081 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5082 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5083 | // if (temp != nullptr) { |
| 5084 | // temp = &gc_root_thunk<root_reg> |
| 5085 | // root = temp(root) |
| 5086 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5087 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5088 | const int32_t entry_point_offset = |
| 5089 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5090 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 5091 | int16_t offset_low = Low16Bits(offset); |
| 5092 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 5093 | // extension in lwu. |
| 5094 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5095 | GpuRegister base = short_offset ? obj : TMP; |
| 5096 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5097 | // threads are suspended or running a checkpoint. |
| 5098 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5099 | if (!short_offset) { |
| 5100 | DCHECK(!label_low); |
| 5101 | __ Daui(base, obj, offset_high); |
| 5102 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5103 | Mips64Label skip_call; |
| 5104 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5105 | if (label_low != nullptr) { |
| 5106 | DCHECK(short_offset); |
| 5107 | __ Bind(label_low); |
| 5108 | } |
| 5109 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5110 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, base, offset_low); // Single instruction |
| 5111 | // in delay slot. |
| 5112 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5113 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5114 | } else { |
| 5115 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5116 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5117 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 5118 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 5119 | // is false, and vice versa. |
| 5120 | // |
| 5121 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5122 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5123 | // if (temp != null) { |
| 5124 | // root = temp(root) |
| 5125 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5126 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5127 | if (label_low != nullptr) { |
| 5128 | __ Bind(label_low); |
| 5129 | } |
| 5130 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5131 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5132 | static_assert( |
| 5133 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5134 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5135 | "have different sizes."); |
| 5136 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5137 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5138 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5139 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5140 | // Slow path marking the GC root `root`. |
| 5141 | Location temp = Location::RegisterLocation(T9); |
| 5142 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5143 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5144 | instruction, |
| 5145 | root, |
| 5146 | /*entrypoint*/ temp); |
| 5147 | codegen_->AddSlowPath(slow_path); |
| 5148 | |
| 5149 | const int32_t entry_point_offset = |
| 5150 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1); |
| 5151 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5152 | // threads are suspended or running a checkpoint. |
| 5153 | __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset); |
| 5154 | __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 5155 | __ Bind(slow_path->GetExitLabel()); |
| 5156 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5157 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5158 | if (label_low != nullptr) { |
| 5159 | __ Bind(label_low); |
| 5160 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5161 | // GC root loaded through a slow path for read barriers other |
| 5162 | // than Baker's. |
| 5163 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 5164 | __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset)); |
| 5165 | // /* mirror::Object* */ root = root->Read() |
| 5166 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5167 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5168 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5169 | if (label_low != nullptr) { |
| 5170 | __ Bind(label_low); |
| 5171 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5172 | // Plain GC root load with no read barrier. |
| 5173 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5174 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5175 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5176 | // do not have to unpoison `root_reg` here. |
| 5177 | } |
| 5178 | } |
| 5179 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5180 | void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5181 | Location ref, |
| 5182 | GpuRegister obj, |
| 5183 | uint32_t offset, |
| 5184 | Location temp, |
| 5185 | bool needs_null_check) { |
| 5186 | DCHECK(kEmitCompilerReadBarrier); |
| 5187 | DCHECK(kUseBakerReadBarrier); |
| 5188 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5189 | if (kBakerReadBarrierThunksEnableForFields) { |
| 5190 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5191 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5192 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5193 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5194 | // vice versa. |
| 5195 | // |
| 5196 | // We use thunks for the slow path. That thunk checks the reference |
| 5197 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5198 | // it issues a load-load memory barrier and returns to the original |
| 5199 | // reference load. |
| 5200 | // |
| 5201 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5202 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5203 | // if (temp != nullptr) { |
| 5204 | // temp = &field_array_thunk<holder_reg> |
| 5205 | // temp() |
| 5206 | // } |
| 5207 | // not_gray_return_address: |
| 5208 | // // If the offset is too large to fit into the lw instruction, we |
| 5209 | // // use an adjusted base register (TMP) here. This register |
| 5210 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 5211 | // // and the thunk benefits from it. |
| 5212 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 5213 | // gray_return_address: |
| 5214 | |
| 5215 | DCHECK(temp.IsInvalid()); |
| 5216 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5217 | const int32_t entry_point_offset = |
| 5218 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5219 | // There may have or may have not been a null check if the field offset is smaller than |
| 5220 | // the page size. |
| 5221 | // There must've been a null check in case it's actually a load from an array. |
| 5222 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 5223 | // do it than not. |
| 5224 | if (instruction->IsArrayGet()) { |
| 5225 | DCHECK(!needs_null_check); |
| 5226 | } |
| 5227 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 5228 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5229 | // threads are suspended or running a checkpoint. |
| 5230 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5231 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5232 | Mips64Label skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5233 | if (short_offset) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5234 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5235 | __ Nop(); // In forbidden slot. |
| 5236 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5237 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5238 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5239 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); // Single instruction. |
| 5240 | } else { |
| 5241 | int16_t offset_low = Low16Bits(offset); |
| 5242 | 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] | 5243 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5244 | __ Daui(TMP, obj, offset_high); // In delay slot. |
| 5245 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5246 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5247 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5248 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset_low); // Single instruction. |
| 5249 | } |
| 5250 | if (needs_null_check) { |
| 5251 | MaybeRecordImplicitNullCheck(instruction); |
| 5252 | } |
| 5253 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5254 | return; |
| 5255 | } |
| 5256 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5257 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5258 | Location no_index = Location::NoLocation(); |
| 5259 | ScaleFactor no_scale_factor = TIMES_1; |
| 5260 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5261 | ref, |
| 5262 | obj, |
| 5263 | offset, |
| 5264 | no_index, |
| 5265 | no_scale_factor, |
| 5266 | temp, |
| 5267 | needs_null_check); |
| 5268 | } |
| 5269 | |
| 5270 | void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5271 | Location ref, |
| 5272 | GpuRegister obj, |
| 5273 | uint32_t data_offset, |
| 5274 | Location index, |
| 5275 | Location temp, |
| 5276 | bool needs_null_check) { |
| 5277 | DCHECK(kEmitCompilerReadBarrier); |
| 5278 | DCHECK(kUseBakerReadBarrier); |
| 5279 | |
| 5280 | static_assert( |
| 5281 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5282 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5283 | ScaleFactor scale_factor = TIMES_4; |
| 5284 | |
| 5285 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 5286 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5287 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5288 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5289 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5290 | // vice versa. |
| 5291 | // |
| 5292 | // We use thunks for the slow path. That thunk checks the reference |
| 5293 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5294 | // it issues a load-load memory barrier and returns to the original |
| 5295 | // reference load. |
| 5296 | // |
| 5297 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5298 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5299 | // if (temp != nullptr) { |
| 5300 | // temp = &field_array_thunk<holder_reg> |
| 5301 | // temp() |
| 5302 | // } |
| 5303 | // not_gray_return_address: |
| 5304 | // // The element address is pre-calculated in the TMP register before the |
| 5305 | // // thunk invocation and the thunk benefits from it. |
| 5306 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 5307 | // gray_return_address: |
| 5308 | |
| 5309 | DCHECK(temp.IsInvalid()); |
| 5310 | DCHECK(index.IsValid()); |
| 5311 | const int32_t entry_point_offset = |
| 5312 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5313 | // We will not do the explicit null check in the thunk as some form of a null check |
| 5314 | // must've been done earlier. |
| 5315 | DCHECK(!needs_null_check); |
| 5316 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 5317 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5318 | // threads are suspended or running a checkpoint. |
| 5319 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5320 | Mips64Label skip_call; |
| 5321 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5322 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5323 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 5324 | __ Dlsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 5325 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5326 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5327 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 5328 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 5329 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, data_offset); // Single instruction. |
| 5330 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5331 | return; |
| 5332 | } |
| 5333 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5334 | // /* HeapReference<Object> */ ref = |
| 5335 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5336 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5337 | ref, |
| 5338 | obj, |
| 5339 | data_offset, |
| 5340 | index, |
| 5341 | scale_factor, |
| 5342 | temp, |
| 5343 | needs_null_check); |
| 5344 | } |
| 5345 | |
| 5346 | void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5347 | Location ref, |
| 5348 | GpuRegister obj, |
| 5349 | uint32_t offset, |
| 5350 | Location index, |
| 5351 | ScaleFactor scale_factor, |
| 5352 | Location temp, |
| 5353 | bool needs_null_check, |
| 5354 | bool always_update_field) { |
| 5355 | DCHECK(kEmitCompilerReadBarrier); |
| 5356 | DCHECK(kUseBakerReadBarrier); |
| 5357 | |
| 5358 | // In slow path based read barriers, the read barrier call is |
| 5359 | // inserted after the original load. However, in fast path based |
| 5360 | // Baker's read barriers, we need to perform the load of |
| 5361 | // mirror::Object::monitor_ *before* the original reference load. |
| 5362 | // This load-load ordering is required by the read barrier. |
| 5363 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5364 | // |
| 5365 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5366 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5367 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5368 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 5369 | // if (is_gray) { |
| 5370 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5371 | // } |
| 5372 | // |
| 5373 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5374 | // slightly more complex as it performs additional checks that we do |
| 5375 | // not do here for performance reasons. |
| 5376 | |
| 5377 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5378 | GpuRegister temp_reg = temp.AsRegister<GpuRegister>(); |
| 5379 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5380 | |
| 5381 | // /* int32_t */ monitor = obj->monitor_ |
| 5382 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 5383 | if (needs_null_check) { |
| 5384 | MaybeRecordImplicitNullCheck(instruction); |
| 5385 | } |
| 5386 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5387 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5388 | "art::LockWord and int32_t have different sizes."); |
| 5389 | |
| 5390 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 5391 | |
| 5392 | // The actual reference load. |
| 5393 | if (index.IsValid()) { |
| 5394 | // Load types involving an "index": ArrayGet, |
| 5395 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5396 | // intrinsics. |
| 5397 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5398 | if (index.IsConstant()) { |
| 5399 | size_t computed_offset = |
| 5400 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 5401 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset); |
| 5402 | } else { |
| 5403 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 5404 | if (scale_factor == TIMES_1) { |
| 5405 | __ Daddu(TMP, index_reg, obj); |
| 5406 | } else { |
| 5407 | __ Dlsa(TMP, index_reg, obj, scale_factor); |
| 5408 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5409 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset); |
| 5410 | } |
| 5411 | } else { |
| 5412 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5413 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); |
| 5414 | } |
| 5415 | |
| 5416 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5417 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5418 | |
| 5419 | // Slow path marking the object `ref` when it is gray. |
| 5420 | SlowPathCodeMIPS64* slow_path; |
| 5421 | if (always_update_field) { |
| 5422 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address |
| 5423 | // of the form `obj + field_offset`, where `obj` is a register and |
| 5424 | // `field_offset` is a register. Thus `offset` and `scale_factor` |
| 5425 | // above are expected to be null in this code path. |
| 5426 | DCHECK_EQ(offset, 0u); |
| 5427 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5428 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5429 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction, |
| 5430 | ref, |
| 5431 | obj, |
| 5432 | /* field_offset */ index, |
| 5433 | temp_reg); |
| 5434 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5435 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5436 | } |
| 5437 | AddSlowPath(slow_path); |
| 5438 | |
| 5439 | // if (rb_state == ReadBarrier::GrayState()) |
| 5440 | // ref = ReadBarrier::Mark(ref); |
| 5441 | // Given the numeric representation, it's enough to check the low bit of the |
| 5442 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 5443 | // performing a branch on less than zero. |
| 5444 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 5445 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 5446 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 5447 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 5448 | __ Bltzc(temp_reg, slow_path->GetEntryLabel()); |
| 5449 | __ Bind(slow_path->GetExitLabel()); |
| 5450 | } |
| 5451 | |
| 5452 | void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5453 | Location out, |
| 5454 | Location ref, |
| 5455 | Location obj, |
| 5456 | uint32_t offset, |
| 5457 | Location index) { |
| 5458 | DCHECK(kEmitCompilerReadBarrier); |
| 5459 | |
| 5460 | // Insert a slow path based read barrier *after* the reference load. |
| 5461 | // |
| 5462 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5463 | // reference will be carried out by the runtime within the slow |
| 5464 | // path. |
| 5465 | // |
| 5466 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5467 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5468 | // not used by the artReadBarrierSlow entry point. |
| 5469 | // |
| 5470 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5471 | SlowPathCodeMIPS64* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5472 | ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index); |
| 5473 | AddSlowPath(slow_path); |
| 5474 | |
| 5475 | __ Bc(slow_path->GetEntryLabel()); |
| 5476 | __ Bind(slow_path->GetExitLabel()); |
| 5477 | } |
| 5478 | |
| 5479 | void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5480 | Location out, |
| 5481 | Location ref, |
| 5482 | Location obj, |
| 5483 | uint32_t offset, |
| 5484 | Location index) { |
| 5485 | if (kEmitCompilerReadBarrier) { |
| 5486 | // Baker's read barriers shall be handled by the fast path |
| 5487 | // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5488 | DCHECK(!kUseBakerReadBarrier); |
| 5489 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5490 | // by the runtime within the slow path. |
| 5491 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 5492 | } else if (kPoisonHeapReferences) { |
| 5493 | __ UnpoisonHeapReference(out.AsRegister<GpuRegister>()); |
| 5494 | } |
| 5495 | } |
| 5496 | |
| 5497 | void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5498 | Location out, |
| 5499 | Location root) { |
| 5500 | DCHECK(kEmitCompilerReadBarrier); |
| 5501 | |
| 5502 | // Insert a slow path based read barrier *after* the GC root load. |
| 5503 | // |
| 5504 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5505 | // not need to do anything special for this here. |
| 5506 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5507 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5508 | AddSlowPath(slow_path); |
| 5509 | |
| 5510 | __ Bc(slow_path->GetEntryLabel()); |
| 5511 | __ Bind(slow_path->GetExitLabel()); |
| 5512 | } |
| 5513 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5514 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5515 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5516 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5517 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5518 | switch (type_check_kind) { |
| 5519 | case TypeCheckKind::kExactCheck: |
| 5520 | case TypeCheckKind::kAbstractClassCheck: |
| 5521 | case TypeCheckKind::kClassHierarchyCheck: |
| 5522 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5523 | call_kind = |
| 5524 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5525 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5526 | break; |
| 5527 | case TypeCheckKind::kArrayCheck: |
| 5528 | case TypeCheckKind::kUnresolvedCheck: |
| 5529 | case TypeCheckKind::kInterfaceCheck: |
| 5530 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5531 | break; |
| 5532 | } |
| 5533 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5534 | LocationSummary* locations = |
| 5535 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5536 | if (baker_read_barrier_slow_path) { |
| 5537 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5538 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5539 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5540 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5541 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5542 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5543 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5544 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5548 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5549 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5550 | Location obj_loc = locations->InAt(0); |
| 5551 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5552 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5553 | Location out_loc = locations->Out(); |
| 5554 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5555 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 5556 | DCHECK_LE(num_temps, 1u); |
| 5557 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5558 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5559 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5560 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5561 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5562 | Mips64Label done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5563 | SlowPathCodeMIPS64* slow_path = nullptr; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5564 | |
| 5565 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5566 | // Avoid this check if we know `obj` is not null. |
| 5567 | if (instruction->MustDoNullCheck()) { |
| 5568 | __ Move(out, ZERO); |
| 5569 | __ Beqzc(obj, &done); |
| 5570 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5571 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5572 | switch (type_check_kind) { |
| 5573 | case TypeCheckKind::kExactCheck: { |
| 5574 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5575 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5576 | out_loc, |
| 5577 | obj_loc, |
| 5578 | class_offset, |
| 5579 | maybe_temp_loc, |
| 5580 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5581 | // Classes must be equal for the instanceof to succeed. |
| 5582 | __ Xor(out, out, cls); |
| 5583 | __ Sltiu(out, out, 1); |
| 5584 | break; |
| 5585 | } |
| 5586 | |
| 5587 | case TypeCheckKind::kAbstractClassCheck: { |
| 5588 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5589 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5590 | out_loc, |
| 5591 | obj_loc, |
| 5592 | class_offset, |
| 5593 | maybe_temp_loc, |
| 5594 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5595 | // If the class is abstract, we eagerly fetch the super class of the |
| 5596 | // object to avoid doing a comparison we know will fail. |
| 5597 | Mips64Label loop; |
| 5598 | __ Bind(&loop); |
| 5599 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5600 | GenerateReferenceLoadOneRegister(instruction, |
| 5601 | out_loc, |
| 5602 | super_offset, |
| 5603 | maybe_temp_loc, |
| 5604 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5605 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5606 | __ Beqzc(out, &done); |
| 5607 | __ Bnec(out, cls, &loop); |
| 5608 | __ LoadConst32(out, 1); |
| 5609 | break; |
| 5610 | } |
| 5611 | |
| 5612 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5613 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5614 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5615 | out_loc, |
| 5616 | obj_loc, |
| 5617 | class_offset, |
| 5618 | maybe_temp_loc, |
| 5619 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5620 | // Walk over the class hierarchy to find a match. |
| 5621 | Mips64Label loop, success; |
| 5622 | __ Bind(&loop); |
| 5623 | __ Beqc(out, cls, &success); |
| 5624 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5625 | GenerateReferenceLoadOneRegister(instruction, |
| 5626 | out_loc, |
| 5627 | super_offset, |
| 5628 | maybe_temp_loc, |
| 5629 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5630 | __ Bnezc(out, &loop); |
| 5631 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5632 | __ Bc(&done); |
| 5633 | __ Bind(&success); |
| 5634 | __ LoadConst32(out, 1); |
| 5635 | break; |
| 5636 | } |
| 5637 | |
| 5638 | case TypeCheckKind::kArrayObjectCheck: { |
| 5639 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5640 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5641 | out_loc, |
| 5642 | obj_loc, |
| 5643 | class_offset, |
| 5644 | maybe_temp_loc, |
| 5645 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5646 | // Do an exact check. |
| 5647 | Mips64Label success; |
| 5648 | __ Beqc(out, cls, &success); |
| 5649 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5650 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5651 | GenerateReferenceLoadOneRegister(instruction, |
| 5652 | out_loc, |
| 5653 | component_offset, |
| 5654 | maybe_temp_loc, |
| 5655 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5656 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5657 | __ Beqzc(out, &done); |
| 5658 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5659 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5660 | __ Sltiu(out, out, 1); |
| 5661 | __ Bc(&done); |
| 5662 | __ Bind(&success); |
| 5663 | __ LoadConst32(out, 1); |
| 5664 | break; |
| 5665 | } |
| 5666 | |
| 5667 | case TypeCheckKind::kArrayCheck: { |
| 5668 | // No read barrier since the slow path will retry upon failure. |
| 5669 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5670 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5671 | out_loc, |
| 5672 | obj_loc, |
| 5673 | class_offset, |
| 5674 | maybe_temp_loc, |
| 5675 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5676 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5677 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5678 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5679 | codegen_->AddSlowPath(slow_path); |
| 5680 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
| 5681 | __ LoadConst32(out, 1); |
| 5682 | break; |
| 5683 | } |
| 5684 | |
| 5685 | case TypeCheckKind::kUnresolvedCheck: |
| 5686 | case TypeCheckKind::kInterfaceCheck: { |
| 5687 | // Note that we indeed only call on slow path, but we always go |
| 5688 | // into the slow path for the unresolved and interface check |
| 5689 | // cases. |
| 5690 | // |
| 5691 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5692 | // entry point without resorting to a type checking slow path |
| 5693 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5694 | // require to assign fixed registers for the inputs of this |
| 5695 | // HInstanceOf instruction (following the runtime calling |
| 5696 | // convention), which might be cluttered by the potential first |
| 5697 | // read barrier emission at the beginning of this method. |
| 5698 | // |
| 5699 | // TODO: Introduce a new runtime entry point taking the object |
| 5700 | // to test (instead of its class) as argument, and let it deal |
| 5701 | // with the read barrier issues. This will let us refactor this |
| 5702 | // case of the `switch` code as it was previously (with a direct |
| 5703 | // call to the runtime not using a type checking slow path). |
| 5704 | // This should also be beneficial for the other cases above. |
| 5705 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5706 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5707 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5708 | codegen_->AddSlowPath(slow_path); |
| 5709 | __ Bc(slow_path->GetEntryLabel()); |
| 5710 | break; |
| 5711 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5712 | } |
| 5713 | |
| 5714 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5715 | |
| 5716 | if (slow_path != nullptr) { |
| 5717 | __ Bind(slow_path->GetExitLabel()); |
| 5718 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5719 | } |
| 5720 | |
| 5721 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5722 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5723 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5724 | } |
| 5725 | |
| 5726 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5727 | // Will be generated at use site. |
| 5728 | } |
| 5729 | |
| 5730 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5731 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5732 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5733 | } |
| 5734 | |
| 5735 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5736 | // Will be generated at use site. |
| 5737 | } |
| 5738 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 5739 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5740 | // The trampoline uses the same calling convention as dex calling conventions, |
| 5741 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 5742 | // the method_idx. |
| 5743 | HandleInvoke(invoke); |
| 5744 | } |
| 5745 | |
| 5746 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5747 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 5748 | } |
| 5749 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5750 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 5751 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 5752 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5753 | } |
| 5754 | |
| 5755 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5756 | HandleInvoke(invoke); |
| 5757 | // The register T0 is required to be used for the hidden argument in |
| 5758 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 5759 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 5760 | } |
| 5761 | |
| 5762 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5763 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5764 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5765 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5766 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5767 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5768 | |
| 5769 | // Set the hidden argument. |
| 5770 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 5771 | invoke->GetDexMethodIndex()); |
| 5772 | |
| 5773 | // temp = object->GetClass(); |
| 5774 | if (receiver.IsStackSlot()) { |
| 5775 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 5776 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 5777 | } else { |
| 5778 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 5779 | } |
| 5780 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5781 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5782 | // emit a read barrier for the previous class reference load. |
| 5783 | // However this is not required in practice, as this is an |
| 5784 | // intermediate/temporary reference and because the current |
| 5785 | // concurrent copying collector keeps the from-space memory |
| 5786 | // intact/accessible until the end of the marking phase (the |
| 5787 | // concurrent copying collector may not in the future). |
| 5788 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5789 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 5790 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 5791 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5792 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5793 | // temp = temp->GetImtEntryAt(method_offset); |
| 5794 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5795 | // T9 = temp->GetEntryPoint(); |
| 5796 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5797 | // T9(); |
| 5798 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5799 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5800 | DCHECK(!codegen_->IsLeafMethod()); |
| 5801 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5802 | } |
| 5803 | |
| 5804 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5805 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5806 | if (intrinsic.TryDispatch(invoke)) { |
| 5807 | return; |
| 5808 | } |
| 5809 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5810 | HandleInvoke(invoke); |
| 5811 | } |
| 5812 | |
| 5813 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5814 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5815 | // art::PrepareForRegisterAllocation. |
| 5816 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5817 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5818 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5819 | if (intrinsic.TryDispatch(invoke)) { |
| 5820 | return; |
| 5821 | } |
| 5822 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5823 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5824 | } |
| 5825 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 5826 | void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5827 | HandleInvoke(invoke); |
| 5828 | } |
| 5829 | |
| 5830 | void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5831 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 5832 | } |
| 5833 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5834 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5835 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5836 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 5837 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5838 | return true; |
| 5839 | } |
| 5840 | return false; |
| 5841 | } |
| 5842 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5843 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5844 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5845 | bool fallback_load = false; |
| 5846 | switch (desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5847 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5848 | case HLoadString::LoadKind::kBootImageInternTable: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5849 | case HLoadString::LoadKind::kBssEntry: |
| 5850 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5851 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5852 | case HLoadString::LoadKind::kJitTableAddress: |
| 5853 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5854 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5855 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5856 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5857 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5858 | } |
| 5859 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5860 | desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5861 | } |
| 5862 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5863 | } |
| 5864 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5865 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 5866 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5867 | bool fallback_load = false; |
| 5868 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5869 | case HLoadClass::LoadKind::kInvalid: |
| 5870 | LOG(FATAL) << "UNREACHABLE"; |
| 5871 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5872 | case HLoadClass::LoadKind::kReferrersClass: |
| 5873 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5874 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5875 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5876 | case HLoadClass::LoadKind::kBssEntry: |
| 5877 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5878 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5879 | case HLoadClass::LoadKind::kJitTableAddress: |
| 5880 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5881 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5882 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5883 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5884 | break; |
| 5885 | } |
| 5886 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5887 | desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5888 | } |
| 5889 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5890 | } |
| 5891 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5892 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 5893 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5894 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5895 | // On MIPS64 we support all dispatch types. |
| 5896 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5897 | } |
| 5898 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5899 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall( |
| 5900 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5901 | // 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] | 5902 | 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] | 5903 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5904 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 5905 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5906 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5907 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5908 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5909 | uint32_t offset = |
| 5910 | GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5911 | __ LoadFromOffset(kLoadDoubleword, |
| 5912 | temp.AsRegister<GpuRegister>(), |
| 5913 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5914 | offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5915 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5916 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5917 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5918 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5919 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5920 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 5921 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5922 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5923 | NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5924 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 5925 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), info_high); |
| 5926 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5927 | __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5928 | break; |
| 5929 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5930 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5931 | __ LoadLiteral(temp.AsRegister<GpuRegister>(), |
| 5932 | kLoadDoubleword, |
| 5933 | DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5934 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5935 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5936 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5937 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5938 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 5939 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
| 5940 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5941 | __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5942 | break; |
| 5943 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5944 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 5945 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5946 | return; // No code pointer retrieval; the runtime performs the call directly. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5947 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5948 | } |
| 5949 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5950 | switch (code_ptr_location) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5951 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5952 | __ Balc(&frame_entry_label_); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5953 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5954 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5955 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 5956 | __ LoadFromOffset(kLoadDoubleword, |
| 5957 | T9, |
| 5958 | callee_method.AsRegister<GpuRegister>(), |
| 5959 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5960 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5961 | // T9() |
| 5962 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5963 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5964 | break; |
| 5965 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5966 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5967 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5968 | DCHECK(!IsLeafMethod()); |
| 5969 | } |
| 5970 | |
| 5971 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5972 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5973 | // art::PrepareForRegisterAllocation. |
| 5974 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5975 | |
| 5976 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5977 | return; |
| 5978 | } |
| 5979 | |
| 5980 | LocationSummary* locations = invoke->GetLocations(); |
| 5981 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 5982 | locations->HasTemps() |
| 5983 | ? locations->GetTemp(0) |
| 5984 | : Location::NoLocation()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5985 | } |
| 5986 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5987 | void CodeGeneratorMIPS64::GenerateVirtualCall( |
| 5988 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5989 | // Use the calling convention instead of the location of the receiver, as |
| 5990 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5991 | // slow path, the arguments have been moved to the right place, so here we are |
| 5992 | // guaranteed that the receiver is the first register of the calling convention. |
| 5993 | InvokeDexCallingConvention calling_convention; |
| 5994 | GpuRegister receiver = calling_convention.GetRegisterAt(0); |
| 5995 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5996 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5997 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5998 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 5999 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6000 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6001 | |
| 6002 | // temp = object->GetClass(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6003 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6004 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6005 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6006 | // emit a read barrier for the previous class reference load. |
| 6007 | // However this is not required in practice, as this is an |
| 6008 | // intermediate/temporary reference and because the current |
| 6009 | // concurrent copying collector keeps the from-space memory |
| 6010 | // intact/accessible until the end of the marking phase (the |
| 6011 | // concurrent copying collector may not in the future). |
| 6012 | __ MaybeUnpoisonHeapReference(temp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6013 | // temp = temp->GetMethodAt(method_offset); |
| 6014 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 6015 | // T9 = temp->GetEntryPoint(); |
| 6016 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 6017 | // T9(); |
| 6018 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 6019 | __ Nop(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6020 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6021 | } |
| 6022 | |
| 6023 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 6024 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 6025 | return; |
| 6026 | } |
| 6027 | |
| 6028 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6029 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6033 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6034 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6035 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6036 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6037 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6038 | return; |
| 6039 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6040 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6041 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6042 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6043 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6044 | ? LocationSummary::kCallOnSlowPath |
| 6045 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6046 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6047 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 6048 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6049 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6050 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6051 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6052 | } |
| 6053 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6054 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6055 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6056 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6057 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6058 | InvokeRuntimeCallingConvention calling_convention; |
| 6059 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6060 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6061 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6062 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6063 | } |
| 6064 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6065 | } |
| 6066 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6067 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6068 | // move. |
| 6069 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6070 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6071 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6072 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6073 | return; |
| 6074 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6075 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6076 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6077 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6078 | Location out_loc = locations->Out(); |
| 6079 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6080 | GpuRegister current_method_reg = ZERO; |
| 6081 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6082 | load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6083 | current_method_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6084 | } |
| 6085 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6086 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6087 | ? kWithoutReadBarrier |
| 6088 | : kCompilerReadBarrierOption; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6089 | bool generate_null_check = false; |
| 6090 | switch (load_kind) { |
| 6091 | case HLoadClass::LoadKind::kReferrersClass: |
| 6092 | DCHECK(!cls->CanCallRuntime()); |
| 6093 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6094 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6095 | GenerateGcRootFieldLoad(cls, |
| 6096 | out_loc, |
| 6097 | current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6098 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 6099 | read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6100 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6101 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6102 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6103 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6104 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6105 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6106 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6107 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 6108 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6109 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 6110 | break; |
| 6111 | } |
| 6112 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6113 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6114 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6115 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6116 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6117 | __ LoadLiteral(out, |
| 6118 | kLoadUnsignedWord, |
| 6119 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6120 | break; |
| 6121 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6122 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6123 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6124 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
| 6125 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6126 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6127 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 6128 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6129 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6130 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6131 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6132 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6133 | if (masked_hash != 0) { |
| 6134 | __ Daddiu(out, out, -masked_hash); |
| 6135 | } |
| 6136 | break; |
| 6137 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6138 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6139 | CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high = |
| 6140 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6141 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6142 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6143 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, out); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6144 | GenerateGcRootFieldLoad(cls, |
| 6145 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6146 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6147 | /* placeholder */ 0x5678, |
| 6148 | read_barrier_option, |
| 6149 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6150 | generate_null_check = true; |
| 6151 | break; |
| 6152 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6153 | case HLoadClass::LoadKind::kJitTableAddress: |
| 6154 | __ LoadLiteral(out, |
| 6155 | kLoadUnsignedWord, |
| 6156 | codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6157 | cls->GetTypeIndex(), |
| 6158 | cls->GetClass())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6159 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6160 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6161 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6162 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6163 | LOG(FATAL) << "UNREACHABLE"; |
| 6164 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6168 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6169 | SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6170 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6171 | codegen_->AddSlowPath(slow_path); |
| 6172 | if (generate_null_check) { |
| 6173 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6174 | } |
| 6175 | if (cls->MustGenerateClinitCheck()) { |
| 6176 | GenerateClassInitializationCheck(slow_path, out); |
| 6177 | } else { |
| 6178 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6179 | } |
| 6180 | } |
| 6181 | } |
| 6182 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6183 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6184 | return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6185 | } |
| 6186 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6187 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 6188 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6189 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6190 | locations->SetOut(Location::RequiresRegister()); |
| 6191 | } |
| 6192 | |
| 6193 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 6194 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6195 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 6196 | } |
| 6197 | |
| 6198 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6199 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6200 | } |
| 6201 | |
| 6202 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6203 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6204 | } |
| 6205 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6206 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6207 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6208 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6209 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6210 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6211 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6212 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6213 | } else { |
| 6214 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6215 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6216 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6217 | // Rely on the pResolveString and marking to save everything we need. |
| 6218 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6219 | InvokeRuntimeCallingConvention calling_convention; |
| 6220 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6221 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6222 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6223 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6224 | } |
| 6225 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6226 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6227 | } |
| 6228 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6229 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6230 | // move. |
| 6231 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6232 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6233 | LocationSummary* locations = load->GetLocations(); |
| 6234 | Location out_loc = locations->Out(); |
| 6235 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6236 | |
| 6237 | switch (load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6238 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6239 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6240 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6241 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6242 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6243 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
| 6244 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6245 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6246 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6247 | } |
| 6248 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6249 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6250 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6251 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6252 | __ LoadLiteral(out, |
| 6253 | kLoadUnsignedWord, |
| 6254 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6255 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6256 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6257 | case HLoadString::LoadKind::kBootImageInternTable: { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6258 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6259 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6260 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6261 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6262 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6263 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6264 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6265 | return; |
| 6266 | } |
| 6267 | case HLoadString::LoadKind::kBssEntry: { |
| 6268 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6269 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
| 6270 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 6271 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6272 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6273 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, out); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6274 | GenerateGcRootFieldLoad(load, |
| 6275 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6276 | out, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6277 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6278 | kCompilerReadBarrierOption, |
| 6279 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6280 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6281 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS64(load); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6282 | codegen_->AddSlowPath(slow_path); |
| 6283 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6284 | __ Bind(slow_path->GetExitLabel()); |
| 6285 | return; |
| 6286 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6287 | case HLoadString::LoadKind::kJitTableAddress: |
| 6288 | __ LoadLiteral(out, |
| 6289 | kLoadUnsignedWord, |
| 6290 | codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| 6291 | load->GetStringIndex(), |
| 6292 | load->GetString())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6293 | GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6294 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6295 | default: |
| 6296 | break; |
| 6297 | } |
| 6298 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6299 | // 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] | 6300 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6301 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6302 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6303 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| 6304 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6305 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6306 | } |
| 6307 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6308 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6309 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6310 | locations->SetOut(Location::ConstantLocation(constant)); |
| 6311 | } |
| 6312 | |
| 6313 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 6314 | // Will be generated at use site. |
| 6315 | } |
| 6316 | |
| 6317 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6318 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6319 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6320 | InvokeRuntimeCallingConvention calling_convention; |
| 6321 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6322 | } |
| 6323 | |
| 6324 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6325 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6326 | instruction, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6327 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6328 | if (instruction->IsEnter()) { |
| 6329 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6330 | } else { |
| 6331 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6332 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6333 | } |
| 6334 | |
| 6335 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 6336 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6337 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6338 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6339 | case DataType::Type::kInt32: |
| 6340 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6341 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6342 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6343 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6344 | break; |
| 6345 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6346 | case DataType::Type::kFloat32: |
| 6347 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6348 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6349 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 6350 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6351 | break; |
| 6352 | |
| 6353 | default: |
| 6354 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 6355 | } |
| 6356 | } |
| 6357 | |
| 6358 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6359 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6360 | LocationSummary* locations = instruction->GetLocations(); |
| 6361 | |
| 6362 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6363 | case DataType::Type::kInt32: |
| 6364 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6365 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6366 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6367 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6368 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6369 | __ MulR6(dst, lhs, rhs); |
| 6370 | else |
| 6371 | __ Dmul(dst, lhs, rhs); |
| 6372 | break; |
| 6373 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6374 | case DataType::Type::kFloat32: |
| 6375 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6376 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6377 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6378 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6379 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6380 | __ MulS(dst, lhs, rhs); |
| 6381 | else |
| 6382 | __ MulD(dst, lhs, rhs); |
| 6383 | break; |
| 6384 | } |
| 6385 | default: |
| 6386 | LOG(FATAL) << "Unexpected mul type " << type; |
| 6387 | } |
| 6388 | } |
| 6389 | |
| 6390 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 6391 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6392 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6393 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6394 | case DataType::Type::kInt32: |
| 6395 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6396 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6397 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6398 | break; |
| 6399 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6400 | case DataType::Type::kFloat32: |
| 6401 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6402 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6403 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6404 | break; |
| 6405 | |
| 6406 | default: |
| 6407 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 6408 | } |
| 6409 | } |
| 6410 | |
| 6411 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6412 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6413 | LocationSummary* locations = instruction->GetLocations(); |
| 6414 | |
| 6415 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6416 | case DataType::Type::kInt32: |
| 6417 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6418 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6419 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6420 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6421 | __ Subu(dst, ZERO, src); |
| 6422 | else |
| 6423 | __ Dsubu(dst, ZERO, src); |
| 6424 | break; |
| 6425 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6426 | case DataType::Type::kFloat32: |
| 6427 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6428 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6429 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6430 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6431 | __ NegS(dst, src); |
| 6432 | else |
| 6433 | __ NegD(dst, src); |
| 6434 | break; |
| 6435 | } |
| 6436 | default: |
| 6437 | LOG(FATAL) << "Unexpected neg type " << type; |
| 6438 | } |
| 6439 | } |
| 6440 | |
| 6441 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6442 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6443 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6444 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6445 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6446 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6447 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6448 | } |
| 6449 | |
| 6450 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6451 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6452 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6453 | QuickEntrypointEnum entrypoint = |
| 6454 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 6455 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6456 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6457 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6458 | } |
| 6459 | |
| 6460 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6461 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6462 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6463 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6464 | if (instruction->IsStringAlloc()) { |
| 6465 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6466 | } else { |
| 6467 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6468 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6469 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6470 | } |
| 6471 | |
| 6472 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6473 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6474 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6475 | if (instruction->IsStringAlloc()) { |
| 6476 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 6477 | GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 6478 | MemberOffset code_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6479 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6480 | __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 6481 | __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value()); |
| 6482 | __ Jalr(T9); |
| 6483 | __ Nop(); |
| 6484 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6485 | } else { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6486 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 6487 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6488 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6489 | } |
| 6490 | |
| 6491 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6492 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6493 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6494 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6495 | } |
| 6496 | |
| 6497 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6498 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6499 | LocationSummary* locations = instruction->GetLocations(); |
| 6500 | |
| 6501 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6502 | case DataType::Type::kInt32: |
| 6503 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6504 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6505 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6506 | __ Nor(dst, src, ZERO); |
| 6507 | break; |
| 6508 | } |
| 6509 | |
| 6510 | default: |
| 6511 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 6512 | } |
| 6513 | } |
| 6514 | |
| 6515 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6516 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6517 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6518 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6519 | } |
| 6520 | |
| 6521 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 6522 | LocationSummary* locations = instruction->GetLocations(); |
| 6523 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 6524 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6525 | 1); |
| 6526 | } |
| 6527 | |
| 6528 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6529 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6530 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6531 | } |
| 6532 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6533 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6534 | if (CanMoveNullCheckToUser(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6535 | return; |
| 6536 | } |
| 6537 | Location obj = instruction->GetLocations()->InAt(0); |
| 6538 | |
| 6539 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6540 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6541 | } |
| 6542 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6543 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6544 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6545 | new (GetScopedAllocator()) NullCheckSlowPathMIPS64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6546 | AddSlowPath(slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6547 | |
| 6548 | Location obj = instruction->GetLocations()->InAt(0); |
| 6549 | |
| 6550 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 6551 | } |
| 6552 | |
| 6553 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6554 | codegen_->GenerateNullCheck(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6555 | } |
| 6556 | |
| 6557 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 6558 | HandleBinaryOp(instruction); |
| 6559 | } |
| 6560 | |
| 6561 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 6562 | HandleBinaryOp(instruction); |
| 6563 | } |
| 6564 | |
| 6565 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6566 | LOG(FATAL) << "Unreachable"; |
| 6567 | } |
| 6568 | |
| 6569 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6570 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6571 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6572 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6573 | // The back edge will generate the suspend check. |
| 6574 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6575 | } |
| 6576 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6577 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6578 | } |
| 6579 | |
| 6580 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6581 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6582 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6583 | if (location.IsStackSlot()) { |
| 6584 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6585 | } else if (location.IsDoubleStackSlot()) { |
| 6586 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6587 | } |
| 6588 | locations->SetOut(location); |
| 6589 | } |
| 6590 | |
| 6591 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 6592 | ATTRIBUTE_UNUSED) { |
| 6593 | // Nothing to do, the parameter is already at its location. |
| 6594 | } |
| 6595 | |
| 6596 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6597 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6598 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6599 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6600 | } |
| 6601 | |
| 6602 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 6603 | ATTRIBUTE_UNUSED) { |
| 6604 | // Nothing to do, the method is already at its location. |
| 6605 | } |
| 6606 | |
| 6607 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6608 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6609 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6610 | locations->SetInAt(i, Location::Any()); |
| 6611 | } |
| 6612 | locations->SetOut(Location::Any()); |
| 6613 | } |
| 6614 | |
| 6615 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6616 | LOG(FATAL) << "Unreachable"; |
| 6617 | } |
| 6618 | |
| 6619 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6620 | DataType::Type type = rem->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6621 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6622 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 6623 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6624 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6625 | |
| 6626 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6627 | case DataType::Type::kInt32: |
| 6628 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6629 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6630 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6631 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6632 | break; |
| 6633 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6634 | case DataType::Type::kFloat32: |
| 6635 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6636 | InvokeRuntimeCallingConvention calling_convention; |
| 6637 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6638 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6639 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6640 | break; |
| 6641 | } |
| 6642 | |
| 6643 | default: |
| 6644 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6649 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6650 | |
| 6651 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6652 | case DataType::Type::kInt32: |
| 6653 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6654 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6655 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6656 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6657 | case DataType::Type::kFloat32: |
| 6658 | case DataType::Type::kFloat64: { |
| 6659 | QuickEntrypointEnum entrypoint = |
| 6660 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6661 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6662 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6663 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 6664 | } else { |
| 6665 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 6666 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6667 | break; |
| 6668 | } |
| 6669 | default: |
| 6670 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6671 | } |
| 6672 | } |
| 6673 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6674 | void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 6675 | constructor_fence->SetLocations(nullptr); |
| 6676 | } |
| 6677 | |
| 6678 | void InstructionCodeGeneratorMIPS64::VisitConstructorFence( |
| 6679 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 6680 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 6681 | } |
| 6682 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6683 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6684 | memory_barrier->SetLocations(nullptr); |
| 6685 | } |
| 6686 | |
| 6687 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6688 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 6689 | } |
| 6690 | |
| 6691 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6692 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6693 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6694 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 6695 | } |
| 6696 | |
| 6697 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 6698 | codegen_->GenerateFrameExit(); |
| 6699 | } |
| 6700 | |
| 6701 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 6702 | ret->SetLocations(nullptr); |
| 6703 | } |
| 6704 | |
| 6705 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 6706 | codegen_->GenerateFrameExit(); |
| 6707 | } |
| 6708 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6709 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { |
| 6710 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6711 | } |
| 6712 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6713 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { |
| 6714 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6715 | } |
| 6716 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6717 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 6718 | HandleShift(shl); |
| 6719 | } |
| 6720 | |
| 6721 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 6722 | HandleShift(shl); |
| 6723 | } |
| 6724 | |
| 6725 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 6726 | HandleShift(shr); |
| 6727 | } |
| 6728 | |
| 6729 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 6730 | HandleShift(shr); |
| 6731 | } |
| 6732 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6733 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 6734 | HandleBinaryOp(instruction); |
| 6735 | } |
| 6736 | |
| 6737 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 6738 | HandleBinaryOp(instruction); |
| 6739 | } |
| 6740 | |
| 6741 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6742 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6743 | } |
| 6744 | |
| 6745 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6746 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6747 | } |
| 6748 | |
| 6749 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6750 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6751 | } |
| 6752 | |
| 6753 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 6754 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6755 | } |
| 6756 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6757 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6758 | HUnresolvedInstanceFieldGet* instruction) { |
| 6759 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6760 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6761 | instruction, instruction->GetFieldType(), calling_convention); |
| 6762 | } |
| 6763 | |
| 6764 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6765 | HUnresolvedInstanceFieldGet* instruction) { |
| 6766 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6767 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6768 | instruction->GetFieldType(), |
| 6769 | instruction->GetFieldIndex(), |
| 6770 | instruction->GetDexPc(), |
| 6771 | calling_convention); |
| 6772 | } |
| 6773 | |
| 6774 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6775 | HUnresolvedInstanceFieldSet* instruction) { |
| 6776 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6777 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6778 | instruction, instruction->GetFieldType(), calling_convention); |
| 6779 | } |
| 6780 | |
| 6781 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6782 | HUnresolvedInstanceFieldSet* instruction) { |
| 6783 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6784 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6785 | instruction->GetFieldType(), |
| 6786 | instruction->GetFieldIndex(), |
| 6787 | instruction->GetDexPc(), |
| 6788 | calling_convention); |
| 6789 | } |
| 6790 | |
| 6791 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( |
| 6792 | HUnresolvedStaticFieldGet* instruction) { |
| 6793 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6794 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6795 | instruction, instruction->GetFieldType(), calling_convention); |
| 6796 | } |
| 6797 | |
| 6798 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( |
| 6799 | HUnresolvedStaticFieldGet* instruction) { |
| 6800 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6801 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6802 | instruction->GetFieldType(), |
| 6803 | instruction->GetFieldIndex(), |
| 6804 | instruction->GetDexPc(), |
| 6805 | calling_convention); |
| 6806 | } |
| 6807 | |
| 6808 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( |
| 6809 | HUnresolvedStaticFieldSet* instruction) { |
| 6810 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6811 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6812 | instruction, instruction->GetFieldType(), calling_convention); |
| 6813 | } |
| 6814 | |
| 6815 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( |
| 6816 | HUnresolvedStaticFieldSet* instruction) { |
| 6817 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6818 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6819 | instruction->GetFieldType(), |
| 6820 | instruction->GetFieldIndex(), |
| 6821 | instruction->GetDexPc(), |
| 6822 | calling_convention); |
| 6823 | } |
| 6824 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6825 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6826 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6827 | instruction, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 6828 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6829 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6830 | // registers in full width (since the runtime only saves/restores lower part). |
| 6831 | locations->SetCustomSlowPathCallerSaves( |
| 6832 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6833 | } |
| 6834 | |
| 6835 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6836 | HBasicBlock* block = instruction->GetBlock(); |
| 6837 | if (block->GetLoopInformation() != nullptr) { |
| 6838 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6839 | // The back edge will generate the suspend check. |
| 6840 | return; |
| 6841 | } |
| 6842 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6843 | // The goto will generate the suspend check. |
| 6844 | return; |
| 6845 | } |
| 6846 | GenerateSuspendCheck(instruction, nullptr); |
| 6847 | } |
| 6848 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6849 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6850 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6851 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6852 | InvokeRuntimeCallingConvention calling_convention; |
| 6853 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6854 | } |
| 6855 | |
| 6856 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6857 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6858 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6859 | } |
| 6860 | |
| 6861 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6862 | DataType::Type input_type = conversion->GetInputType(); |
| 6863 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6864 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6865 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6866 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6867 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6868 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6869 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6870 | } |
| 6871 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6872 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(conversion); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6873 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6874 | if (DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6875 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6876 | } else { |
| 6877 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6878 | } |
| 6879 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6880 | if (DataType::IsFloatingPointType(result_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6881 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6882 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6883 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6884 | } |
| 6885 | } |
| 6886 | |
| 6887 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6888 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6889 | DataType::Type result_type = conversion->GetResultType(); |
| 6890 | DataType::Type input_type = conversion->GetInputType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6891 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6892 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6893 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6894 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6895 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6896 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6897 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6898 | |
| 6899 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6900 | case DataType::Type::kUint8: |
| 6901 | __ Andi(dst, src, 0xFF); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6902 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6903 | case DataType::Type::kInt8: |
| 6904 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6905 | // Type conversion from long to types narrower than int is a result of code |
| 6906 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6907 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6908 | __ Sll(dst, src, 0); |
| 6909 | __ Seb(dst, dst); |
| 6910 | } else { |
| 6911 | __ Seb(dst, src); |
| 6912 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6913 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6914 | case DataType::Type::kUint16: |
| 6915 | __ Andi(dst, src, 0xFFFF); |
| 6916 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6917 | case DataType::Type::kInt16: |
| 6918 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6919 | // Type conversion from long to types narrower than int is a result of code |
| 6920 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6921 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6922 | __ Sll(dst, src, 0); |
| 6923 | __ Seh(dst, dst); |
| 6924 | } else { |
| 6925 | __ Seh(dst, src); |
| 6926 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6927 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6928 | case DataType::Type::kInt32: |
| 6929 | case DataType::Type::kInt64: |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 6930 | // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int |
| 6931 | // conversions, except when the input and output registers are the same and we are not |
| 6932 | // converting longs to shorter types. In these cases, do nothing. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6933 | if ((input_type == DataType::Type::kInt64) || (dst != src)) { |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 6934 | __ Sll(dst, src, 0); |
| 6935 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6936 | break; |
| 6937 | |
| 6938 | default: |
| 6939 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 6940 | << " to " << result_type; |
| 6941 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6942 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6943 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6944 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6945 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6946 | __ Dmtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6947 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6948 | __ Cvtsl(dst, FTMP); |
| 6949 | } else { |
| 6950 | __ Cvtdl(dst, FTMP); |
| 6951 | } |
| 6952 | } else { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6953 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6954 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6955 | __ Cvtsw(dst, FTMP); |
| 6956 | } else { |
| 6957 | __ Cvtdw(dst, FTMP); |
| 6958 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6959 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6960 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6961 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6962 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6963 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6964 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6965 | if (result_type == DataType::Type::kInt64) { |
| 6966 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6967 | __ TruncLS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6968 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6969 | __ TruncLD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6970 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6971 | __ Dmfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6972 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6973 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6974 | __ TruncWS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6975 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6976 | __ TruncWD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6977 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6978 | __ Mfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6979 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6980 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6981 | DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6982 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6983 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6984 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6985 | __ Cvtsd(dst, src); |
| 6986 | } else { |
| 6987 | __ Cvtds(dst, src); |
| 6988 | } |
| 6989 | } else { |
| 6990 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6991 | << " to " << result_type; |
| 6992 | } |
| 6993 | } |
| 6994 | |
| 6995 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 6996 | HandleShift(ushr); |
| 6997 | } |
| 6998 | |
| 6999 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 7000 | HandleShift(ushr); |
| 7001 | } |
| 7002 | |
| 7003 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 7004 | HandleBinaryOp(instruction); |
| 7005 | } |
| 7006 | |
| 7007 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 7008 | HandleBinaryOp(instruction); |
| 7009 | } |
| 7010 | |
| 7011 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7012 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7013 | LOG(FATAL) << "Unreachable"; |
| 7014 | } |
| 7015 | |
| 7016 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7017 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7018 | LOG(FATAL) << "Unreachable"; |
| 7019 | } |
| 7020 | |
| 7021 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7022 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7023 | } |
| 7024 | |
| 7025 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7026 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7027 | } |
| 7028 | |
| 7029 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7030 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7034 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7035 | } |
| 7036 | |
| 7037 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7038 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7039 | } |
| 7040 | |
| 7041 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7042 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7043 | } |
| 7044 | |
| 7045 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7046 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7047 | } |
| 7048 | |
| 7049 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7050 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7051 | } |
| 7052 | |
| 7053 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7054 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7055 | } |
| 7056 | |
| 7057 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7058 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7059 | } |
| 7060 | |
| 7061 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7062 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7063 | } |
| 7064 | |
| 7065 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7066 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7067 | } |
| 7068 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7069 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7070 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7071 | } |
| 7072 | |
| 7073 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7074 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7075 | } |
| 7076 | |
| 7077 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7078 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7079 | } |
| 7080 | |
| 7081 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7082 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7083 | } |
| 7084 | |
| 7085 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7086 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7087 | } |
| 7088 | |
| 7089 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7090 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7091 | } |
| 7092 | |
| 7093 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7094 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7098 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7099 | } |
| 7100 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7101 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7102 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7103 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7104 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7105 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7106 | } |
| 7107 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7108 | void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg, |
| 7109 | int32_t lower_bound, |
| 7110 | uint32_t num_entries, |
| 7111 | HBasicBlock* switch_block, |
| 7112 | HBasicBlock* default_block) { |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7113 | // Create a set of compare/jumps. |
| 7114 | GpuRegister temp_reg = TMP; |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7115 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7116 | // Jump to default if index is negative |
| 7117 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 7118 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 7119 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); |
| 7120 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7121 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7122 | // Jump to successors[0] if value == lower_bound. |
| 7123 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 7124 | int32_t last_index = 0; |
| 7125 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7126 | __ Addiu(temp_reg, temp_reg, -2); |
| 7127 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7128 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7129 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7130 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 7131 | } |
| 7132 | if (num_entries - last_index == 2) { |
| 7133 | // The last missing case_value. |
| 7134 | __ Addiu(temp_reg, temp_reg, -1); |
| 7135 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7136 | } |
| 7137 | |
| 7138 | // And the default for any other value. |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7139 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 7140 | __ Bc(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7141 | } |
| 7142 | } |
| 7143 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7144 | void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg, |
| 7145 | int32_t lower_bound, |
| 7146 | uint32_t num_entries, |
| 7147 | HBasicBlock* switch_block, |
| 7148 | HBasicBlock* default_block) { |
| 7149 | // Create a jump table. |
| 7150 | std::vector<Mips64Label*> labels(num_entries); |
| 7151 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7152 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7153 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7154 | } |
| 7155 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 7156 | |
| 7157 | // Is the value in range? |
| 7158 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 7159 | __ LoadConst32(AT, num_entries); |
| 7160 | __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 7161 | |
| 7162 | // We are in the range of the table. |
| 7163 | // Load the target address from the jump table, indexing by the value. |
| 7164 | __ LoadLabelAddress(AT, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7165 | __ Dlsa(TMP, TMP, AT, 2); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7166 | __ Lw(TMP, TMP, 0); |
| 7167 | // Compute the absolute target address by adding the table start address |
| 7168 | // (the table contains offsets to targets relative to its start). |
| 7169 | __ Daddu(TMP, TMP, AT); |
| 7170 | // And jump. |
| 7171 | __ Jr(TMP); |
| 7172 | __ Nop(); |
| 7173 | } |
| 7174 | |
| 7175 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7176 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7177 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7178 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7179 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 7180 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 7181 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7182 | |
| 7183 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
| 7184 | GenTableBasedPackedSwitch(value_reg, |
| 7185 | lower_bound, |
| 7186 | num_entries, |
| 7187 | switch_block, |
| 7188 | default_block); |
| 7189 | } else { |
| 7190 | GenPackedSwitchWithCompares(value_reg, |
| 7191 | lower_bound, |
| 7192 | num_entries, |
| 7193 | switch_block, |
| 7194 | default_block); |
| 7195 | } |
| 7196 | } |
| 7197 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7198 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7199 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7200 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7201 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7202 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7203 | } |
| 7204 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7205 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7206 | LocationSummary* locations = instruction->GetLocations(); |
| 7207 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 7208 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7209 | instruction->GetIndex(), kMips64PointerSize).SizeValue(); |
| 7210 | __ LoadFromOffset(kLoadDoubleword, |
| 7211 | locations->Out().AsRegister<GpuRegister>(), |
| 7212 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7213 | method_offset); |
| 7214 | } else { |
| 7215 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 7216 | instruction->GetIndex(), kMips64PointerSize)); |
| 7217 | __ LoadFromOffset(kLoadDoubleword, |
| 7218 | locations->Out().AsRegister<GpuRegister>(), |
| 7219 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7220 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 7221 | __ LoadFromOffset(kLoadDoubleword, |
| 7222 | locations->Out().AsRegister<GpuRegister>(), |
| 7223 | locations->Out().AsRegister<GpuRegister>(), |
| 7224 | method_offset); |
| 7225 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7226 | } |
| 7227 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7228 | void LocationsBuilderMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7229 | ATTRIBUTE_UNUSED) { |
| 7230 | LOG(FATAL) << "Unreachable"; |
| 7231 | } |
| 7232 | |
| 7233 | void InstructionCodeGeneratorMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7234 | ATTRIBUTE_UNUSED) { |
| 7235 | LOG(FATAL) << "Unreachable"; |
| 7236 | } |
| 7237 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7238 | } // namespace mips64 |
| 7239 | } // namespace art |