| 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 | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 19 | #include "art_method.h" | 
|  | 20 | #include "code_generator_utils.h" | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 21 | #include "entrypoints/quick/quick_entrypoints.h" | 
|  | 22 | #include "entrypoints/quick/quick_entrypoints_enum.h" | 
|  | 23 | #include "gc/accounting/card_table.h" | 
|  | 24 | #include "intrinsics.h" | 
| Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 25 | #include "intrinsics_mips64.h" | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" | 
|  | 27 | #include "mirror/class-inl.h" | 
|  | 28 | #include "offsets.h" | 
|  | 29 | #include "thread.h" | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 30 | #include "utils/assembler.h" | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 31 | #include "utils/mips64/assembler_mips64.h" | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 32 | #include "utils/stack_checks.h" | 
|  | 33 |  | 
|  | 34 | namespace art { | 
|  | 35 | namespace mips64 { | 
|  | 36 |  | 
|  | 37 | static constexpr int kCurrentMethodStackOffset = 0; | 
|  | 38 | static constexpr GpuRegister kMethodRegisterArgument = A0; | 
|  | 39 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 40 | Location Mips64ReturnLocation(Primitive::Type return_type) { | 
|  | 41 | switch (return_type) { | 
|  | 42 | case Primitive::kPrimBoolean: | 
|  | 43 | case Primitive::kPrimByte: | 
|  | 44 | case Primitive::kPrimChar: | 
|  | 45 | case Primitive::kPrimShort: | 
|  | 46 | case Primitive::kPrimInt: | 
|  | 47 | case Primitive::kPrimNot: | 
|  | 48 | case Primitive::kPrimLong: | 
|  | 49 | return Location::RegisterLocation(V0); | 
|  | 50 |  | 
|  | 51 | case Primitive::kPrimFloat: | 
|  | 52 | case Primitive::kPrimDouble: | 
|  | 53 | return Location::FpuRegisterLocation(F0); | 
|  | 54 |  | 
|  | 55 | case Primitive::kPrimVoid: | 
|  | 56 | return Location(); | 
|  | 57 | } | 
|  | 58 | UNREACHABLE(); | 
|  | 59 | } | 
|  | 60 |  | 
|  | 61 | Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(Primitive::Type type) const { | 
|  | 62 | return Mips64ReturnLocation(type); | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const { | 
|  | 66 | return Location::RegisterLocation(kMethodRegisterArgument); | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(Primitive::Type type) { | 
|  | 70 | Location next_location; | 
|  | 71 | if (type == Primitive::kPrimVoid) { | 
|  | 72 | LOG(FATAL) << "Unexpected parameter type " << type; | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | if (Primitive::IsFloatingPointType(type) && | 
|  | 76 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { | 
|  | 77 | next_location = Location::FpuRegisterLocation( | 
|  | 78 | calling_convention.GetFpuRegisterAt(float_index_++)); | 
|  | 79 | gp_index_++; | 
|  | 80 | } else if (!Primitive::IsFloatingPointType(type) && | 
|  | 81 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { | 
|  | 82 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++)); | 
|  | 83 | float_index_++; | 
|  | 84 | } else { | 
|  | 85 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); | 
|  | 86 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) | 
|  | 87 | : Location::StackSlot(stack_offset); | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | // Space on the stack is reserved for all arguments. | 
|  | 91 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; | 
|  | 92 |  | 
|  | 93 | // TODO: review | 
|  | 94 |  | 
|  | 95 | // TODO: shouldn't we use a whole machine word per argument on the stack? | 
|  | 96 | // Implicit 4-byte method pointer (and such) will cause misalignment. | 
|  | 97 |  | 
|  | 98 | return next_location; | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) { | 
|  | 102 | return Mips64ReturnLocation(type); | 
|  | 103 | } | 
|  | 104 |  | 
| Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 105 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. | 
|  | 106 | #define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 107 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64DoublewordSize, x).Int32Value() | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 108 |  | 
|  | 109 | class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { | 
|  | 110 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 111 | explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {} | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 112 |  | 
|  | 113 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 114 | LocationSummary* locations = instruction_->GetLocations(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 115 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); | 
|  | 116 | __ Bind(GetEntryLabel()); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 117 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 118 | // Live registers will be restored in the catch block if caught. | 
|  | 119 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 120 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 121 | // We're moving two locations to locations that could overlap, so we need a parallel | 
|  | 122 | // move resolver. | 
|  | 123 | InvokeRuntimeCallingConvention calling_convention; | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 124 | codegen->EmitParallelMoves(locations->InAt(0), | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 125 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
|  | 126 | Primitive::kPrimInt, | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 127 | locations->InAt(1), | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 128 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
|  | 129 | Primitive::kPrimInt); | 
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 130 | uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt() | 
|  | 131 | ? QUICK_ENTRY_POINT(pThrowStringBounds) | 
|  | 132 | : QUICK_ENTRY_POINT(pThrowArrayBounds); | 
|  | 133 | mips64_codegen->InvokeRuntime(entry_point_offset, | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 134 | instruction_, | 
|  | 135 | instruction_->GetDexPc(), | 
|  | 136 | this); | 
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 137 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 138 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); | 
|  | 139 | } | 
|  | 140 |  | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 141 | bool IsFatal() const OVERRIDE { return true; } | 
|  | 142 |  | 
| Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 143 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; } | 
|  | 144 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 145 | private: | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 146 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64); | 
|  | 147 | }; | 
|  | 148 |  | 
|  | 149 | class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { | 
|  | 150 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 151 | explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) : SlowPathCodeMIPS64(instruction) {} | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 152 |  | 
|  | 153 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 154 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); | 
|  | 155 | __ Bind(GetEntryLabel()); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 156 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 157 | // Live registers will be restored in the catch block if caught. | 
|  | 158 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 159 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 160 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), | 
|  | 161 | instruction_, | 
|  | 162 | instruction_->GetDexPc(), | 
|  | 163 | this); | 
|  | 164 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); | 
|  | 165 | } | 
|  | 166 |  | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 167 | bool IsFatal() const OVERRIDE { return true; } | 
|  | 168 |  | 
| Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 169 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; } | 
|  | 170 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 171 | private: | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 172 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64); | 
|  | 173 | }; | 
|  | 174 |  | 
|  | 175 | class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 { | 
|  | 176 | public: | 
|  | 177 | LoadClassSlowPathMIPS64(HLoadClass* cls, | 
|  | 178 | HInstruction* at, | 
|  | 179 | uint32_t dex_pc, | 
|  | 180 | bool do_clinit) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 181 | : SlowPathCodeMIPS64(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 182 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); | 
|  | 183 | } | 
|  | 184 |  | 
|  | 185 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 186 | LocationSummary* locations = at_->GetLocations(); | 
|  | 187 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); | 
|  | 188 |  | 
|  | 189 | __ Bind(GetEntryLabel()); | 
|  | 190 | SaveLiveRegisters(codegen, locations); | 
|  | 191 |  | 
|  | 192 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 193 | __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); | 
|  | 194 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) | 
|  | 195 | : QUICK_ENTRY_POINT(pInitializeType); | 
|  | 196 | mips64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); | 
|  | 197 | if (do_clinit_) { | 
|  | 198 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); | 
|  | 199 | } else { | 
|  | 200 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | // Move the class to the desired location. | 
|  | 204 | Location out = locations->Out(); | 
|  | 205 | if (out.IsValid()) { | 
|  | 206 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); | 
|  | 207 | Primitive::Type type = at_->GetType(); | 
|  | 208 | mips64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); | 
|  | 209 | } | 
|  | 210 |  | 
|  | 211 | RestoreLiveRegisters(codegen, locations); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 212 | __ Bc(GetExitLabel()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 213 | } | 
|  | 214 |  | 
| Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 215 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; } | 
|  | 216 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 217 | private: | 
|  | 218 | // The class this slow path will load. | 
|  | 219 | HLoadClass* const cls_; | 
|  | 220 |  | 
|  | 221 | // The instruction where this slow path is happening. | 
|  | 222 | // (Might be the load class or an initialization check). | 
|  | 223 | HInstruction* const at_; | 
|  | 224 |  | 
|  | 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: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 236 | explicit LoadStringSlowPathMIPS64(HLoadString* instruction) : SlowPathCodeMIPS64(instruction) {} | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 237 |  | 
|  | 238 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 239 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 240 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
|  | 241 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); | 
|  | 242 |  | 
|  | 243 | __ Bind(GetEntryLabel()); | 
|  | 244 | SaveLiveRegisters(codegen, locations); | 
|  | 245 |  | 
|  | 246 | InvokeRuntimeCallingConvention calling_convention; | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 247 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); | 
|  | 248 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 249 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), | 
|  | 250 | instruction_, | 
|  | 251 | instruction_->GetDexPc(), | 
|  | 252 | this); | 
|  | 253 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); | 
|  | 254 | Primitive::Type type = instruction_->GetType(); | 
|  | 255 | mips64_codegen->MoveLocation(locations->Out(), | 
|  | 256 | calling_convention.GetReturnLocation(type), | 
|  | 257 | type); | 
|  | 258 |  | 
|  | 259 | RestoreLiveRegisters(codegen, locations); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 260 | __ Bc(GetExitLabel()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 261 | } | 
|  | 262 |  | 
| Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 263 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; } | 
|  | 264 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 265 | private: | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 266 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64); | 
|  | 267 | }; | 
|  | 268 |  | 
|  | 269 | class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { | 
|  | 270 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 271 | explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {} | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 272 |  | 
|  | 273 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 274 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); | 
|  | 275 | __ Bind(GetEntryLabel()); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 276 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 277 | // Live registers will be restored in the catch block if caught. | 
|  | 278 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 279 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 280 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), | 
|  | 281 | instruction_, | 
|  | 282 | instruction_->GetDexPc(), | 
|  | 283 | this); | 
|  | 284 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); | 
|  | 285 | } | 
|  | 286 |  | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 287 | bool IsFatal() const OVERRIDE { return true; } | 
|  | 288 |  | 
| Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 289 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; } | 
|  | 290 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 291 | private: | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 292 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64); | 
|  | 293 | }; | 
|  | 294 |  | 
|  | 295 | class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { | 
|  | 296 | public: | 
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 297 | SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 298 | : SlowPathCodeMIPS64(instruction), successor_(successor) {} | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 299 |  | 
|  | 300 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 301 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); | 
|  | 302 | __ Bind(GetEntryLabel()); | 
|  | 303 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 304 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), | 
|  | 305 | instruction_, | 
|  | 306 | instruction_->GetDexPc(), | 
|  | 307 | this); | 
|  | 308 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); | 
|  | 309 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 310 | if (successor_ == nullptr) { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 311 | __ Bc(GetReturnLabel()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 312 | } else { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 313 | __ Bc(mips64_codegen->GetLabelOf(successor_)); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 314 | } | 
|  | 315 | } | 
|  | 316 |  | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 317 | Mips64Label* GetReturnLabel() { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 318 | DCHECK(successor_ == nullptr); | 
|  | 319 | return &return_label_; | 
|  | 320 | } | 
|  | 321 |  | 
| Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 322 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; } | 
|  | 323 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 324 | private: | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 325 | // If not null, the block to branch to after the suspend check. | 
|  | 326 | HBasicBlock* const successor_; | 
|  | 327 |  | 
|  | 328 | // 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] | 329 | Mips64Label return_label_; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 330 |  | 
|  | 331 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64); | 
|  | 332 | }; | 
|  | 333 |  | 
|  | 334 | class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { | 
|  | 335 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 336 | explicit TypeCheckSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {} | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 337 |  | 
|  | 338 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 339 | LocationSummary* locations = instruction_->GetLocations(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 340 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out(); | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 341 | uint32_t dex_pc = instruction_->GetDexPc(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 342 | DCHECK(instruction_->IsCheckCast() | 
|  | 343 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
|  | 344 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); | 
|  | 345 |  | 
|  | 346 | __ Bind(GetEntryLabel()); | 
|  | 347 | SaveLiveRegisters(codegen, locations); | 
|  | 348 |  | 
|  | 349 | // We're moving two locations to locations that could overlap, so we need a parallel | 
|  | 350 | // move resolver. | 
|  | 351 | InvokeRuntimeCallingConvention calling_convention; | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 352 | codegen->EmitParallelMoves(locations->InAt(1), | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 353 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
|  | 354 | Primitive::kPrimNot, | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 355 | object_class, | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 356 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
|  | 357 | Primitive::kPrimNot); | 
|  | 358 |  | 
|  | 359 | if (instruction_->IsInstanceOf()) { | 
|  | 360 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), | 
|  | 361 | instruction_, | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 362 | dex_pc, | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 363 | this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 364 | CheckEntrypointTypes< | 
|  | 365 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 366 | Primitive::Type ret_type = instruction_->GetType(); | 
|  | 367 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); | 
|  | 368 | mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 369 | } else { | 
|  | 370 | DCHECK(instruction_->IsCheckCast()); | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 371 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 372 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); | 
|  | 373 | } | 
|  | 374 |  | 
|  | 375 | RestoreLiveRegisters(codegen, locations); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 376 | __ Bc(GetExitLabel()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 377 | } | 
|  | 378 |  | 
| Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 379 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; } | 
|  | 380 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 381 | private: | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 382 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64); | 
|  | 383 | }; | 
|  | 384 |  | 
|  | 385 | class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 { | 
|  | 386 | public: | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 387 | explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 388 | : SlowPathCodeMIPS64(instruction) {} | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 389 |  | 
|  | 390 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 391 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 392 | __ Bind(GetEntryLabel()); | 
|  | 393 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 394 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), | 
|  | 395 | instruction_, | 
|  | 396 | instruction_->GetDexPc(), | 
|  | 397 | this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 398 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 399 | } | 
|  | 400 |  | 
| Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 401 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; } | 
|  | 402 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 403 | private: | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 404 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64); | 
|  | 405 | }; | 
|  | 406 |  | 
|  | 407 | CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph, | 
|  | 408 | const Mips64InstructionSetFeatures& isa_features, | 
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 409 | const CompilerOptions& compiler_options, | 
|  | 410 | OptimizingCompilerStats* stats) | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 411 | : CodeGenerator(graph, | 
|  | 412 | kNumberOfGpuRegisters, | 
|  | 413 | kNumberOfFpuRegisters, | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 414 | /* number_of_register_pairs */ 0, | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 415 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), | 
|  | 416 | arraysize(kCoreCalleeSaves)), | 
|  | 417 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), | 
|  | 418 | arraysize(kFpuCalleeSaves)), | 
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 419 | compiler_options, | 
|  | 420 | stats), | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 421 | block_labels_(nullptr), | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 422 | location_builder_(graph, this), | 
|  | 423 | instruction_visitor_(graph, this), | 
|  | 424 | move_resolver_(graph->GetArena(), this), | 
| Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 425 | assembler_(graph->GetArena()), | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 426 | isa_features_(isa_features) { | 
|  | 427 | // Save RA (containing the return address) to mimic Quick. | 
|  | 428 | AddAllocatedRegister(Location::RegisterLocation(RA)); | 
|  | 429 | } | 
|  | 430 |  | 
|  | 431 | #undef __ | 
| Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 432 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. | 
|  | 433 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 434 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64DoublewordSize, x).Int32Value() | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 435 |  | 
|  | 436 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 437 | // Ensure that we fix up branches. | 
|  | 438 | __ FinalizeCode(); | 
|  | 439 |  | 
|  | 440 | // Adjust native pc offsets in stack maps. | 
|  | 441 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { | 
|  | 442 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; | 
|  | 443 | uint32_t new_position = __ GetAdjustedPosition(old_position); | 
|  | 444 | DCHECK_GE(new_position, old_position); | 
|  | 445 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); | 
|  | 446 | } | 
|  | 447 |  | 
|  | 448 | // Adjust pc offsets for the disassembly information. | 
|  | 449 | if (disasm_info_ != nullptr) { | 
|  | 450 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); | 
|  | 451 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); | 
|  | 452 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); | 
|  | 453 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { | 
|  | 454 | it.second.start = __ GetAdjustedPosition(it.second.start); | 
|  | 455 | it.second.end = __ GetAdjustedPosition(it.second.end); | 
|  | 456 | } | 
|  | 457 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { | 
|  | 458 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); | 
|  | 459 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); | 
|  | 460 | } | 
|  | 461 | } | 
|  | 462 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 463 | CodeGenerator::Finalize(allocator); | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { | 
|  | 467 | return codegen_->GetAssembler(); | 
|  | 468 | } | 
|  | 469 |  | 
|  | 470 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 471 | MoveOperands* move = moves_[index]; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 472 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); | 
|  | 473 | } | 
|  | 474 |  | 
|  | 475 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 476 | MoveOperands* move = moves_[index]; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 477 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); | 
|  | 478 | } | 
|  | 479 |  | 
|  | 480 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { | 
|  | 481 | // Pop reg | 
|  | 482 | __ Ld(GpuRegister(reg), SP, 0); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 483 | __ DecreaseFrameSize(kMips64DoublewordSize); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 484 | } | 
|  | 485 |  | 
|  | 486 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { | 
|  | 487 | // Push reg | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 488 | __ IncreaseFrameSize(kMips64DoublewordSize); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 489 | __ Sd(GpuRegister(reg), SP, 0); | 
|  | 490 | } | 
|  | 491 |  | 
|  | 492 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { | 
|  | 493 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; | 
|  | 494 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; | 
|  | 495 | // Allocate a scratch register other than TMP, if available. | 
|  | 496 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be | 
|  | 497 | // automatically unspilled when the scratch scope object is destroyed). | 
|  | 498 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); | 
|  | 499 | // 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] | 500 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 501 | __ LoadFromOffset(load_type, | 
|  | 502 | GpuRegister(ensure_scratch.GetRegister()), | 
|  | 503 | SP, | 
|  | 504 | index1 + stack_offset); | 
|  | 505 | __ LoadFromOffset(load_type, | 
|  | 506 | TMP, | 
|  | 507 | SP, | 
|  | 508 | index2 + stack_offset); | 
|  | 509 | __ StoreToOffset(store_type, | 
|  | 510 | GpuRegister(ensure_scratch.GetRegister()), | 
|  | 511 | SP, | 
|  | 512 | index2 + stack_offset); | 
|  | 513 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); | 
|  | 514 | } | 
|  | 515 |  | 
|  | 516 | static dwarf::Reg DWARFReg(GpuRegister reg) { | 
|  | 517 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); | 
|  | 518 | } | 
|  | 519 |  | 
| David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 520 | static dwarf::Reg DWARFReg(FpuRegister reg) { | 
|  | 521 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); | 
|  | 522 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 523 |  | 
|  | 524 | void CodeGeneratorMIPS64::GenerateFrameEntry() { | 
|  | 525 | __ Bind(&frame_entry_label_); | 
|  | 526 |  | 
|  | 527 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod(); | 
|  | 528 |  | 
|  | 529 | if (do_overflow_check) { | 
|  | 530 | __ LoadFromOffset(kLoadWord, | 
|  | 531 | ZERO, | 
|  | 532 | SP, | 
|  | 533 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64))); | 
|  | 534 | RecordPcInfo(nullptr, 0); | 
|  | 535 | } | 
|  | 536 |  | 
|  | 537 | // TODO: anything related to T9/GP/GOT/PIC/.so's? | 
|  | 538 |  | 
|  | 539 | if (HasEmptyFrame()) { | 
|  | 540 | return; | 
|  | 541 | } | 
|  | 542 |  | 
|  | 543 | // Make sure the frame size isn't unreasonably large. Per the various APIs | 
|  | 544 | // it looks like it should always be less than 2GB in size, which allows | 
|  | 545 | // us using 32-bit signed offsets from the stack pointer. | 
|  | 546 | if (GetFrameSize() > 0x7FFFFFFF) | 
|  | 547 | LOG(FATAL) << "Stack frame larger than 2GB"; | 
|  | 548 |  | 
|  | 549 | // Spill callee-saved registers. | 
|  | 550 | // Note that their cumulative size is small and they can be indexed using | 
|  | 551 | // 16-bit offsets. | 
|  | 552 |  | 
|  | 553 | // TODO: increment/decrement SP in one step instead of two or remove this comment. | 
|  | 554 |  | 
|  | 555 | uint32_t ofs = FrameEntrySpillSize(); | 
|  | 556 | __ IncreaseFrameSize(ofs); | 
|  | 557 |  | 
|  | 558 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { | 
|  | 559 | GpuRegister reg = kCoreCalleeSaves[i]; | 
|  | 560 | if (allocated_registers_.ContainsCoreRegister(reg)) { | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 561 | ofs -= kMips64DoublewordSize; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 562 | __ Sd(reg, SP, ofs); | 
|  | 563 | __ cfi().RelOffset(DWARFReg(reg), ofs); | 
|  | 564 | } | 
|  | 565 | } | 
|  | 566 |  | 
|  | 567 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { | 
|  | 568 | FpuRegister reg = kFpuCalleeSaves[i]; | 
|  | 569 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 570 | ofs -= kMips64DoublewordSize; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 571 | __ Sdc1(reg, SP, ofs); | 
| David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 572 | __ cfi().RelOffset(DWARFReg(reg), ofs); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 573 | } | 
|  | 574 | } | 
|  | 575 |  | 
|  | 576 | // Allocate the rest of the frame and store the current method pointer | 
|  | 577 | // at its end. | 
|  | 578 |  | 
|  | 579 | __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); | 
|  | 580 |  | 
|  | 581 | static_assert(IsInt<16>(kCurrentMethodStackOffset), | 
|  | 582 | "kCurrentMethodStackOffset must fit into int16_t"); | 
|  | 583 | __ Sd(kMethodRegisterArgument, SP, kCurrentMethodStackOffset); | 
|  | 584 | } | 
|  | 585 |  | 
|  | 586 | void CodeGeneratorMIPS64::GenerateFrameExit() { | 
|  | 587 | __ cfi().RememberState(); | 
|  | 588 |  | 
|  | 589 | // TODO: anything related to T9/GP/GOT/PIC/.so's? | 
|  | 590 |  | 
|  | 591 | if (!HasEmptyFrame()) { | 
|  | 592 | // Deallocate the rest of the frame. | 
|  | 593 |  | 
|  | 594 | __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); | 
|  | 595 |  | 
|  | 596 | // Restore callee-saved registers. | 
|  | 597 | // Note that their cumulative size is small and they can be indexed using | 
|  | 598 | // 16-bit offsets. | 
|  | 599 |  | 
|  | 600 | // TODO: increment/decrement SP in one step instead of two or remove this comment. | 
|  | 601 |  | 
|  | 602 | uint32_t ofs = 0; | 
|  | 603 |  | 
|  | 604 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { | 
|  | 605 | FpuRegister reg = kFpuCalleeSaves[i]; | 
|  | 606 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { | 
|  | 607 | __ Ldc1(reg, SP, ofs); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 608 | ofs += kMips64DoublewordSize; | 
| David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 609 | __ cfi().Restore(DWARFReg(reg)); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 610 | } | 
|  | 611 | } | 
|  | 612 |  | 
|  | 613 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { | 
|  | 614 | GpuRegister reg = kCoreCalleeSaves[i]; | 
|  | 615 | if (allocated_registers_.ContainsCoreRegister(reg)) { | 
|  | 616 | __ Ld(reg, SP, ofs); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 617 | ofs += kMips64DoublewordSize; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 618 | __ cfi().Restore(DWARFReg(reg)); | 
|  | 619 | } | 
|  | 620 | } | 
|  | 621 |  | 
|  | 622 | DCHECK_EQ(ofs, FrameEntrySpillSize()); | 
|  | 623 | __ DecreaseFrameSize(ofs); | 
|  | 624 | } | 
|  | 625 |  | 
|  | 626 | __ Jr(RA); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 627 | __ Nop(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 628 |  | 
|  | 629 | __ cfi().RestoreState(); | 
|  | 630 | __ cfi().DefCFAOffset(GetFrameSize()); | 
|  | 631 | } | 
|  | 632 |  | 
|  | 633 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { | 
|  | 634 | __ Bind(GetLabelOf(block)); | 
|  | 635 | } | 
|  | 636 |  | 
|  | 637 | void CodeGeneratorMIPS64::MoveLocation(Location destination, | 
|  | 638 | Location source, | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 639 | Primitive::Type dst_type) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 640 | if (source.Equals(destination)) { | 
|  | 641 | return; | 
|  | 642 | } | 
|  | 643 |  | 
|  | 644 | // A valid move can always be inferred from the destination and source | 
|  | 645 | // locations. When moving from and to a register, the argument type can be | 
|  | 646 | // used to generate 32bit instead of 64bit moves. | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 647 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 648 | DCHECK_EQ(unspecified_type, false); | 
|  | 649 |  | 
|  | 650 | if (destination.IsRegister() || destination.IsFpuRegister()) { | 
|  | 651 | if (unspecified_type) { | 
|  | 652 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; | 
|  | 653 | if (source.IsStackSlot() || | 
|  | 654 | (src_cst != nullptr && (src_cst->IsIntConstant() | 
|  | 655 | || src_cst->IsFloatConstant() | 
|  | 656 | || src_cst->IsNullConstant()))) { | 
|  | 657 | // For stack slots and 32bit constants, a 64bit type is appropriate. | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 658 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 659 | } else { | 
|  | 660 | // If the source is a double stack slot or a 64bit constant, a 64bit | 
|  | 661 | // type is appropriate. Else the source is a register, and since the | 
|  | 662 | // type has not been specified, we chose a 64bit type to force a 64bit | 
|  | 663 | // move. | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 664 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 665 | } | 
|  | 666 | } | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 667 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || | 
|  | 668 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 669 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { | 
|  | 670 | // Move to GPR/FPR from stack | 
|  | 671 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 672 | if (Primitive::IsFloatingPointType(dst_type)) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 673 | __ LoadFpuFromOffset(load_type, | 
|  | 674 | destination.AsFpuRegister<FpuRegister>(), | 
|  | 675 | SP, | 
|  | 676 | source.GetStackIndex()); | 
|  | 677 | } else { | 
|  | 678 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. | 
|  | 679 | __ LoadFromOffset(load_type, | 
|  | 680 | destination.AsRegister<GpuRegister>(), | 
|  | 681 | SP, | 
|  | 682 | source.GetStackIndex()); | 
|  | 683 | } | 
|  | 684 | } else if (source.IsConstant()) { | 
|  | 685 | // Move to GPR/FPR from constant | 
|  | 686 | GpuRegister gpr = AT; | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 687 | if (!Primitive::IsFloatingPointType(dst_type)) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 688 | gpr = destination.AsRegister<GpuRegister>(); | 
|  | 689 | } | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 690 | if (dst_type == Primitive::kPrimInt || dst_type == Primitive::kPrimFloat) { | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 691 | int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant()); | 
|  | 692 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { | 
|  | 693 | gpr = ZERO; | 
|  | 694 | } else { | 
|  | 695 | __ LoadConst32(gpr, value); | 
|  | 696 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 697 | } else { | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 698 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); | 
|  | 699 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { | 
|  | 700 | gpr = ZERO; | 
|  | 701 | } else { | 
|  | 702 | __ LoadConst64(gpr, value); | 
|  | 703 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 704 | } | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 705 | if (dst_type == Primitive::kPrimFloat) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 706 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 707 | } else if (dst_type == Primitive::kPrimDouble) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 708 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); | 
|  | 709 | } | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 710 | } else if (source.IsRegister()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 711 | if (destination.IsRegister()) { | 
|  | 712 | // Move to GPR from GPR | 
|  | 713 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); | 
|  | 714 | } else { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 715 | DCHECK(destination.IsFpuRegister()); | 
|  | 716 | if (Primitive::Is64BitType(dst_type)) { | 
|  | 717 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); | 
|  | 718 | } else { | 
|  | 719 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); | 
|  | 720 | } | 
|  | 721 | } | 
|  | 722 | } else if (source.IsFpuRegister()) { | 
|  | 723 | if (destination.IsFpuRegister()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 724 | // Move to FPR from FPR | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 725 | if (dst_type == Primitive::kPrimFloat) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 726 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); | 
|  | 727 | } else { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 728 | DCHECK_EQ(dst_type, Primitive::kPrimDouble); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 729 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); | 
|  | 730 | } | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 731 | } else { | 
|  | 732 | DCHECK(destination.IsRegister()); | 
|  | 733 | if (Primitive::Is64BitType(dst_type)) { | 
|  | 734 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); | 
|  | 735 | } else { | 
|  | 736 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); | 
|  | 737 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 738 | } | 
|  | 739 | } | 
|  | 740 | } else {  // The destination is not a register. It must be a stack slot. | 
|  | 741 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); | 
|  | 742 | if (source.IsRegister() || source.IsFpuRegister()) { | 
|  | 743 | if (unspecified_type) { | 
|  | 744 | if (source.IsRegister()) { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 745 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 746 | } else { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 747 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 748 | } | 
|  | 749 | } | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 750 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && | 
|  | 751 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 752 | // Move to stack from GPR/FPR | 
|  | 753 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; | 
|  | 754 | if (source.IsRegister()) { | 
|  | 755 | __ StoreToOffset(store_type, | 
|  | 756 | source.AsRegister<GpuRegister>(), | 
|  | 757 | SP, | 
|  | 758 | destination.GetStackIndex()); | 
|  | 759 | } else { | 
|  | 760 | __ StoreFpuToOffset(store_type, | 
|  | 761 | source.AsFpuRegister<FpuRegister>(), | 
|  | 762 | SP, | 
|  | 763 | destination.GetStackIndex()); | 
|  | 764 | } | 
|  | 765 | } else if (source.IsConstant()) { | 
|  | 766 | // Move to stack from constant | 
|  | 767 | HConstant* src_cst = source.GetConstant(); | 
|  | 768 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 769 | GpuRegister gpr = ZERO; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 770 | if (destination.IsStackSlot()) { | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 771 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); | 
|  | 772 | if (value != 0) { | 
|  | 773 | gpr = TMP; | 
|  | 774 | __ LoadConst32(gpr, value); | 
|  | 775 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 776 | } else { | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 777 | DCHECK(destination.IsDoubleStackSlot()); | 
|  | 778 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); | 
|  | 779 | if (value != 0) { | 
|  | 780 | gpr = TMP; | 
|  | 781 | __ LoadConst64(gpr, value); | 
|  | 782 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 783 | } | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 784 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 785 | } else { | 
|  | 786 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); | 
|  | 787 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); | 
|  | 788 | // Move to stack from stack | 
|  | 789 | if (destination.IsStackSlot()) { | 
|  | 790 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); | 
|  | 791 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); | 
|  | 792 | } else { | 
|  | 793 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); | 
|  | 794 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); | 
|  | 795 | } | 
|  | 796 | } | 
|  | 797 | } | 
|  | 798 | } | 
|  | 799 |  | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 800 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, Primitive::Type type) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 801 | DCHECK(!loc1.IsConstant()); | 
|  | 802 | DCHECK(!loc2.IsConstant()); | 
|  | 803 |  | 
|  | 804 | if (loc1.Equals(loc2)) { | 
|  | 805 | return; | 
|  | 806 | } | 
|  | 807 |  | 
|  | 808 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); | 
|  | 809 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); | 
|  | 810 | bool is_fp_reg1 = loc1.IsFpuRegister(); | 
|  | 811 | bool is_fp_reg2 = loc2.IsFpuRegister(); | 
|  | 812 |  | 
|  | 813 | if (loc2.IsRegister() && loc1.IsRegister()) { | 
|  | 814 | // Swap 2 GPRs | 
|  | 815 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); | 
|  | 816 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); | 
|  | 817 | __ Move(TMP, r2); | 
|  | 818 | __ Move(r2, r1); | 
|  | 819 | __ Move(r1, TMP); | 
|  | 820 | } else if (is_fp_reg2 && is_fp_reg1) { | 
|  | 821 | // Swap 2 FPRs | 
|  | 822 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); | 
|  | 823 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 824 | if (type == Primitive::kPrimFloat) { | 
|  | 825 | __ MovS(FTMP, r1); | 
|  | 826 | __ MovS(r1, r2); | 
|  | 827 | __ MovS(r2, FTMP); | 
|  | 828 | } else { | 
|  | 829 | DCHECK_EQ(type, Primitive::kPrimDouble); | 
|  | 830 | __ MovD(FTMP, r1); | 
|  | 831 | __ MovD(r1, r2); | 
|  | 832 | __ MovD(r2, FTMP); | 
|  | 833 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 834 | } else if (is_slot1 != is_slot2) { | 
|  | 835 | // Swap GPR/FPR and stack slot | 
|  | 836 | Location reg_loc = is_slot1 ? loc2 : loc1; | 
|  | 837 | Location mem_loc = is_slot1 ? loc1 : loc2; | 
|  | 838 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; | 
|  | 839 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; | 
|  | 840 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. | 
|  | 841 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); | 
|  | 842 | if (reg_loc.IsFpuRegister()) { | 
|  | 843 | __ StoreFpuToOffset(store_type, | 
|  | 844 | reg_loc.AsFpuRegister<FpuRegister>(), | 
|  | 845 | SP, | 
|  | 846 | mem_loc.GetStackIndex()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 847 | if (mem_loc.IsStackSlot()) { | 
|  | 848 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); | 
|  | 849 | } else { | 
|  | 850 | DCHECK(mem_loc.IsDoubleStackSlot()); | 
|  | 851 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); | 
|  | 852 | } | 
|  | 853 | } else { | 
|  | 854 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); | 
|  | 855 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); | 
|  | 856 | } | 
|  | 857 | } else if (is_slot1 && is_slot2) { | 
|  | 858 | move_resolver_.Exchange(loc1.GetStackIndex(), | 
|  | 859 | loc2.GetStackIndex(), | 
|  | 860 | loc1.IsDoubleStackSlot()); | 
|  | 861 | } else { | 
|  | 862 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; | 
|  | 863 | } | 
|  | 864 | } | 
|  | 865 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 866 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { | 
|  | 867 | DCHECK(location.IsRegister()); | 
|  | 868 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); | 
|  | 869 | } | 
|  | 870 |  | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 871 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { | 
|  | 872 | if (location.IsRegister()) { | 
|  | 873 | locations->AddTemp(location); | 
|  | 874 | } else { | 
|  | 875 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; | 
|  | 876 | } | 
|  | 877 | } | 
|  | 878 |  | 
| Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 879 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, | 
|  | 880 | GpuRegister value, | 
|  | 881 | bool value_can_be_null) { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 882 | Mips64Label done; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 883 | GpuRegister card = AT; | 
|  | 884 | GpuRegister temp = TMP; | 
| Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 885 | if (value_can_be_null) { | 
|  | 886 | __ Beqzc(value, &done); | 
|  | 887 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 888 | __ LoadFromOffset(kLoadDoubleword, | 
|  | 889 | card, | 
|  | 890 | TR, | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 891 | Thread::CardTableOffset<kMips64DoublewordSize>().Int32Value()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 892 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); | 
|  | 893 | __ Daddu(temp, card, temp); | 
|  | 894 | __ Sb(card, temp, 0); | 
| Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 895 | if (value_can_be_null) { | 
|  | 896 | __ Bind(&done); | 
|  | 897 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 898 | } | 
|  | 899 |  | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 900 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 901 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. | 
|  | 902 | blocked_core_registers_[ZERO] = true; | 
|  | 903 | blocked_core_registers_[K0] = true; | 
|  | 904 | blocked_core_registers_[K1] = true; | 
|  | 905 | blocked_core_registers_[GP] = true; | 
|  | 906 | blocked_core_registers_[SP] = true; | 
|  | 907 | blocked_core_registers_[RA] = true; | 
|  | 908 |  | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 909 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch | 
|  | 910 | // registers (similar to how AT is used by MIPS assemblers). | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 911 | blocked_core_registers_[AT] = true; | 
|  | 912 | blocked_core_registers_[TMP] = true; | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 913 | blocked_core_registers_[TMP2] = true; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 914 | blocked_fpu_registers_[FTMP] = true; | 
|  | 915 |  | 
|  | 916 | // Reserve suspend and thread registers. | 
|  | 917 | blocked_core_registers_[S0] = true; | 
|  | 918 | blocked_core_registers_[TR] = true; | 
|  | 919 |  | 
|  | 920 | // Reserve T9 for function calls | 
|  | 921 | blocked_core_registers_[T9] = true; | 
|  | 922 |  | 
|  | 923 | // TODO: review; anything else? | 
|  | 924 |  | 
| Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 925 | if (GetGraph()->IsDebuggable()) { | 
|  | 926 | // Stubs do not save callee-save floating point registers. If the graph | 
|  | 927 | // is debuggable, we need to deal with these registers differently. For | 
|  | 928 | // now, just block them. | 
|  | 929 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { | 
|  | 930 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; | 
|  | 931 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 932 | } | 
|  | 933 | } | 
|  | 934 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 935 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 936 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 937 | return kMips64DoublewordSize; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 938 | } | 
|  | 939 |  | 
|  | 940 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 941 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 942 | return kMips64DoublewordSize; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 943 | } | 
|  | 944 |  | 
|  | 945 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 946 | __ StoreFpuToOffset(kStoreDoubleword, FpuRegister(reg_id), SP, stack_index); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 947 | return kMips64DoublewordSize; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 948 | } | 
|  | 949 |  | 
|  | 950 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 951 | __ LoadFpuFromOffset(kLoadDoubleword, FpuRegister(reg_id), SP, stack_index); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 952 | return kMips64DoublewordSize; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 953 | } | 
|  | 954 |  | 
|  | 955 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { | 
| David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 956 | stream << GpuRegister(reg); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 957 | } | 
|  | 958 |  | 
|  | 959 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { | 
| David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 960 | stream << FpuRegister(reg); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 961 | } | 
|  | 962 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 963 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, | 
|  | 964 | HInstruction* instruction, | 
|  | 965 | uint32_t dex_pc, | 
|  | 966 | SlowPathCode* slow_path) { | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 967 | InvokeRuntime(GetThreadOffset<kMips64DoublewordSize>(entrypoint).Int32Value(), | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 968 | instruction, | 
|  | 969 | dex_pc, | 
|  | 970 | slow_path); | 
|  | 971 | } | 
|  | 972 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 973 | void CodeGeneratorMIPS64::InvokeRuntime(int32_t entry_point_offset, | 
|  | 974 | HInstruction* instruction, | 
|  | 975 | uint32_t dex_pc, | 
|  | 976 | SlowPathCode* slow_path) { | 
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 977 | ValidateInvokeRuntime(instruction, slow_path); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 978 | // TODO: anything related to T9/GP/GOT/PIC/.so's? | 
|  | 979 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); | 
|  | 980 | __ Jalr(T9); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 981 | __ Nop(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 982 | RecordPcInfo(instruction, dex_pc, slow_path); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 983 | } | 
|  | 984 |  | 
|  | 985 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, | 
|  | 986 | GpuRegister class_reg) { | 
|  | 987 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); | 
|  | 988 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); | 
|  | 989 | __ Bltc(TMP, AT, slow_path->GetEntryLabel()); | 
|  | 990 | // TODO: barrier needed? | 
|  | 991 | __ Bind(slow_path->GetExitLabel()); | 
|  | 992 | } | 
|  | 993 |  | 
|  | 994 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { | 
|  | 995 | __ Sync(0);  // only stype 0 is supported | 
|  | 996 | } | 
|  | 997 |  | 
|  | 998 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, | 
|  | 999 | HBasicBlock* successor) { | 
|  | 1000 | SuspendCheckSlowPathMIPS64* slow_path = | 
|  | 1001 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor); | 
|  | 1002 | codegen_->AddSlowPath(slow_path); | 
|  | 1003 |  | 
|  | 1004 | __ LoadFromOffset(kLoadUnsignedHalfword, | 
|  | 1005 | TMP, | 
|  | 1006 | TR, | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1007 | Thread::ThreadFlagsOffset<kMips64DoublewordSize>().Int32Value()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1008 | if (successor == nullptr) { | 
|  | 1009 | __ Bnezc(TMP, slow_path->GetEntryLabel()); | 
|  | 1010 | __ Bind(slow_path->GetReturnLabel()); | 
|  | 1011 | } else { | 
|  | 1012 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1013 | __ Bc(slow_path->GetEntryLabel()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1014 | // slow_path will return to GetLabelOf(successor). | 
|  | 1015 | } | 
|  | 1016 | } | 
|  | 1017 |  | 
|  | 1018 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, | 
|  | 1019 | CodeGeneratorMIPS64* codegen) | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1020 | : InstructionCodeGenerator(graph, codegen), | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1021 | assembler_(codegen->GetAssembler()), | 
|  | 1022 | codegen_(codegen) {} | 
|  | 1023 |  | 
|  | 1024 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { | 
|  | 1025 | DCHECK_EQ(instruction->InputCount(), 2U); | 
|  | 1026 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 1027 | Primitive::Type type = instruction->GetResultType(); | 
|  | 1028 | switch (type) { | 
|  | 1029 | case Primitive::kPrimInt: | 
|  | 1030 | case Primitive::kPrimLong: { | 
|  | 1031 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1032 | HInstruction* right = instruction->InputAt(1); | 
|  | 1033 | bool can_use_imm = false; | 
|  | 1034 | if (right->IsConstant()) { | 
|  | 1035 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); | 
|  | 1036 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { | 
|  | 1037 | can_use_imm = IsUint<16>(imm); | 
|  | 1038 | } else if (instruction->IsAdd()) { | 
|  | 1039 | can_use_imm = IsInt<16>(imm); | 
|  | 1040 | } else { | 
|  | 1041 | DCHECK(instruction->IsSub()); | 
|  | 1042 | can_use_imm = IsInt<16>(-imm); | 
|  | 1043 | } | 
|  | 1044 | } | 
|  | 1045 | if (can_use_imm) | 
|  | 1046 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); | 
|  | 1047 | else | 
|  | 1048 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 1049 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1050 | } | 
|  | 1051 | break; | 
|  | 1052 |  | 
|  | 1053 | case Primitive::kPrimFloat: | 
|  | 1054 | case Primitive::kPrimDouble: | 
|  | 1055 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 1056 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 1057 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 1058 | break; | 
|  | 1059 |  | 
|  | 1060 | default: | 
|  | 1061 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; | 
|  | 1062 | } | 
|  | 1063 | } | 
|  | 1064 |  | 
|  | 1065 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { | 
|  | 1066 | Primitive::Type type = instruction->GetType(); | 
|  | 1067 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1068 |  | 
|  | 1069 | switch (type) { | 
|  | 1070 | case Primitive::kPrimInt: | 
|  | 1071 | case Primitive::kPrimLong: { | 
|  | 1072 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1073 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1074 | Location rhs_location = locations->InAt(1); | 
|  | 1075 |  | 
|  | 1076 | GpuRegister rhs_reg = ZERO; | 
|  | 1077 | int64_t rhs_imm = 0; | 
|  | 1078 | bool use_imm = rhs_location.IsConstant(); | 
|  | 1079 | if (use_imm) { | 
|  | 1080 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); | 
|  | 1081 | } else { | 
|  | 1082 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); | 
|  | 1083 | } | 
|  | 1084 |  | 
|  | 1085 | if (instruction->IsAnd()) { | 
|  | 1086 | if (use_imm) | 
|  | 1087 | __ Andi(dst, lhs, rhs_imm); | 
|  | 1088 | else | 
|  | 1089 | __ And(dst, lhs, rhs_reg); | 
|  | 1090 | } else if (instruction->IsOr()) { | 
|  | 1091 | if (use_imm) | 
|  | 1092 | __ Ori(dst, lhs, rhs_imm); | 
|  | 1093 | else | 
|  | 1094 | __ Or(dst, lhs, rhs_reg); | 
|  | 1095 | } else if (instruction->IsXor()) { | 
|  | 1096 | if (use_imm) | 
|  | 1097 | __ Xori(dst, lhs, rhs_imm); | 
|  | 1098 | else | 
|  | 1099 | __ Xor(dst, lhs, rhs_reg); | 
|  | 1100 | } else if (instruction->IsAdd()) { | 
|  | 1101 | if (type == Primitive::kPrimInt) { | 
|  | 1102 | if (use_imm) | 
|  | 1103 | __ Addiu(dst, lhs, rhs_imm); | 
|  | 1104 | else | 
|  | 1105 | __ Addu(dst, lhs, rhs_reg); | 
|  | 1106 | } else { | 
|  | 1107 | if (use_imm) | 
|  | 1108 | __ Daddiu(dst, lhs, rhs_imm); | 
|  | 1109 | else | 
|  | 1110 | __ Daddu(dst, lhs, rhs_reg); | 
|  | 1111 | } | 
|  | 1112 | } else { | 
|  | 1113 | DCHECK(instruction->IsSub()); | 
|  | 1114 | if (type == Primitive::kPrimInt) { | 
|  | 1115 | if (use_imm) | 
|  | 1116 | __ Addiu(dst, lhs, -rhs_imm); | 
|  | 1117 | else | 
|  | 1118 | __ Subu(dst, lhs, rhs_reg); | 
|  | 1119 | } else { | 
|  | 1120 | if (use_imm) | 
|  | 1121 | __ Daddiu(dst, lhs, -rhs_imm); | 
|  | 1122 | else | 
|  | 1123 | __ Dsubu(dst, lhs, rhs_reg); | 
|  | 1124 | } | 
|  | 1125 | } | 
|  | 1126 | break; | 
|  | 1127 | } | 
|  | 1128 | case Primitive::kPrimFloat: | 
|  | 1129 | case Primitive::kPrimDouble: { | 
|  | 1130 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); | 
|  | 1131 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); | 
|  | 1132 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); | 
|  | 1133 | if (instruction->IsAdd()) { | 
|  | 1134 | if (type == Primitive::kPrimFloat) | 
|  | 1135 | __ AddS(dst, lhs, rhs); | 
|  | 1136 | else | 
|  | 1137 | __ AddD(dst, lhs, rhs); | 
|  | 1138 | } else if (instruction->IsSub()) { | 
|  | 1139 | if (type == Primitive::kPrimFloat) | 
|  | 1140 | __ SubS(dst, lhs, rhs); | 
|  | 1141 | else | 
|  | 1142 | __ SubD(dst, lhs, rhs); | 
|  | 1143 | } else { | 
|  | 1144 | LOG(FATAL) << "Unexpected floating-point binary operation"; | 
|  | 1145 | } | 
|  | 1146 | break; | 
|  | 1147 | } | 
|  | 1148 | default: | 
|  | 1149 | LOG(FATAL) << "Unexpected binary operation type " << type; | 
|  | 1150 | } | 
|  | 1151 | } | 
|  | 1152 |  | 
|  | 1153 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1154 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1155 |  | 
|  | 1156 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); | 
|  | 1157 | Primitive::Type type = instr->GetResultType(); | 
|  | 1158 | switch (type) { | 
|  | 1159 | case Primitive::kPrimInt: | 
|  | 1160 | case Primitive::kPrimLong: { | 
|  | 1161 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1162 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1163 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1164 | break; | 
|  | 1165 | } | 
|  | 1166 | default: | 
|  | 1167 | LOG(FATAL) << "Unexpected shift type " << type; | 
|  | 1168 | } | 
|  | 1169 | } | 
|  | 1170 |  | 
|  | 1171 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1172 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1173 | LocationSummary* locations = instr->GetLocations(); | 
|  | 1174 | Primitive::Type type = instr->GetType(); | 
|  | 1175 |  | 
|  | 1176 | switch (type) { | 
|  | 1177 | case Primitive::kPrimInt: | 
|  | 1178 | case Primitive::kPrimLong: { | 
|  | 1179 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1180 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1181 | Location rhs_location = locations->InAt(1); | 
|  | 1182 |  | 
|  | 1183 | GpuRegister rhs_reg = ZERO; | 
|  | 1184 | int64_t rhs_imm = 0; | 
|  | 1185 | bool use_imm = rhs_location.IsConstant(); | 
|  | 1186 | if (use_imm) { | 
|  | 1187 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); | 
|  | 1188 | } else { | 
|  | 1189 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); | 
|  | 1190 | } | 
|  | 1191 |  | 
|  | 1192 | if (use_imm) { | 
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1193 | uint32_t shift_value = rhs_imm & | 
|  | 1194 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1195 |  | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1196 | if (shift_value == 0) { | 
|  | 1197 | if (dst != lhs) { | 
|  | 1198 | __ Move(dst, lhs); | 
|  | 1199 | } | 
|  | 1200 | } else if (type == Primitive::kPrimInt) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1201 | if (instr->IsShl()) { | 
|  | 1202 | __ Sll(dst, lhs, shift_value); | 
|  | 1203 | } else if (instr->IsShr()) { | 
|  | 1204 | __ Sra(dst, lhs, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1205 | } else if (instr->IsUShr()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1206 | __ Srl(dst, lhs, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1207 | } else { | 
|  | 1208 | __ Rotr(dst, lhs, shift_value); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1209 | } | 
|  | 1210 | } else { | 
|  | 1211 | if (shift_value < 32) { | 
|  | 1212 | if (instr->IsShl()) { | 
|  | 1213 | __ Dsll(dst, lhs, shift_value); | 
|  | 1214 | } else if (instr->IsShr()) { | 
|  | 1215 | __ Dsra(dst, lhs, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1216 | } else if (instr->IsUShr()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1217 | __ Dsrl(dst, lhs, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1218 | } else { | 
|  | 1219 | __ Drotr(dst, lhs, shift_value); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1220 | } | 
|  | 1221 | } else { | 
|  | 1222 | shift_value -= 32; | 
|  | 1223 | if (instr->IsShl()) { | 
|  | 1224 | __ Dsll32(dst, lhs, shift_value); | 
|  | 1225 | } else if (instr->IsShr()) { | 
|  | 1226 | __ Dsra32(dst, lhs, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1227 | } else if (instr->IsUShr()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1228 | __ Dsrl32(dst, lhs, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1229 | } else { | 
|  | 1230 | __ Drotr32(dst, lhs, shift_value); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1231 | } | 
|  | 1232 | } | 
|  | 1233 | } | 
|  | 1234 | } else { | 
|  | 1235 | if (type == Primitive::kPrimInt) { | 
|  | 1236 | if (instr->IsShl()) { | 
|  | 1237 | __ Sllv(dst, lhs, rhs_reg); | 
|  | 1238 | } else if (instr->IsShr()) { | 
|  | 1239 | __ Srav(dst, lhs, rhs_reg); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1240 | } else if (instr->IsUShr()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1241 | __ Srlv(dst, lhs, rhs_reg); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1242 | } else { | 
|  | 1243 | __ Rotrv(dst, lhs, rhs_reg); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1244 | } | 
|  | 1245 | } else { | 
|  | 1246 | if (instr->IsShl()) { | 
|  | 1247 | __ Dsllv(dst, lhs, rhs_reg); | 
|  | 1248 | } else if (instr->IsShr()) { | 
|  | 1249 | __ Dsrav(dst, lhs, rhs_reg); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1250 | } else if (instr->IsUShr()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1251 | __ Dsrlv(dst, lhs, rhs_reg); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1252 | } else { | 
|  | 1253 | __ Drotrv(dst, lhs, rhs_reg); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1254 | } | 
|  | 1255 | } | 
|  | 1256 | } | 
|  | 1257 | break; | 
|  | 1258 | } | 
|  | 1259 | default: | 
|  | 1260 | LOG(FATAL) << "Unexpected shift operation type " << type; | 
|  | 1261 | } | 
|  | 1262 | } | 
|  | 1263 |  | 
|  | 1264 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { | 
|  | 1265 | HandleBinaryOp(instruction); | 
|  | 1266 | } | 
|  | 1267 |  | 
|  | 1268 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { | 
|  | 1269 | HandleBinaryOp(instruction); | 
|  | 1270 | } | 
|  | 1271 |  | 
|  | 1272 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { | 
|  | 1273 | HandleBinaryOp(instruction); | 
|  | 1274 | } | 
|  | 1275 |  | 
|  | 1276 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { | 
|  | 1277 | HandleBinaryOp(instruction); | 
|  | 1278 | } | 
|  | 1279 |  | 
|  | 1280 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { | 
|  | 1281 | LocationSummary* locations = | 
|  | 1282 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 1283 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1284 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 1285 | if (Primitive::IsFloatingPointType(instruction->GetType())) { | 
|  | 1286 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 1287 | } else { | 
|  | 1288 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1289 | } | 
|  | 1290 | } | 
|  | 1291 |  | 
|  | 1292 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { | 
|  | 1293 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1294 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1295 | Location index = locations->InAt(1); | 
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1296 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1297 |  | 
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1298 | Primitive::Type type = instruction->GetType(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1299 | switch (type) { | 
|  | 1300 | case Primitive::kPrimBoolean: { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1301 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1302 | if (index.IsConstant()) { | 
|  | 1303 | size_t offset = | 
|  | 1304 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; | 
|  | 1305 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); | 
|  | 1306 | } else { | 
|  | 1307 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); | 
|  | 1308 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); | 
|  | 1309 | } | 
|  | 1310 | break; | 
|  | 1311 | } | 
|  | 1312 |  | 
|  | 1313 | case Primitive::kPrimByte: { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1314 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1315 | if (index.IsConstant()) { | 
|  | 1316 | size_t offset = | 
|  | 1317 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; | 
|  | 1318 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); | 
|  | 1319 | } else { | 
|  | 1320 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); | 
|  | 1321 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset); | 
|  | 1322 | } | 
|  | 1323 | break; | 
|  | 1324 | } | 
|  | 1325 |  | 
|  | 1326 | case Primitive::kPrimShort: { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1327 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1328 | if (index.IsConstant()) { | 
|  | 1329 | size_t offset = | 
|  | 1330 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; | 
|  | 1331 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); | 
|  | 1332 | } else { | 
|  | 1333 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2); | 
|  | 1334 | __ Daddu(TMP, obj, TMP); | 
|  | 1335 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset); | 
|  | 1336 | } | 
|  | 1337 | break; | 
|  | 1338 | } | 
|  | 1339 |  | 
|  | 1340 | case Primitive::kPrimChar: { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1341 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1342 | if (index.IsConstant()) { | 
|  | 1343 | size_t offset = | 
|  | 1344 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; | 
|  | 1345 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); | 
|  | 1346 | } else { | 
|  | 1347 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2); | 
|  | 1348 | __ Daddu(TMP, obj, TMP); | 
|  | 1349 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); | 
|  | 1350 | } | 
|  | 1351 | break; | 
|  | 1352 | } | 
|  | 1353 |  | 
|  | 1354 | case Primitive::kPrimInt: | 
|  | 1355 | case Primitive::kPrimNot: { | 
|  | 1356 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1357 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1358 | LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord; | 
|  | 1359 | if (index.IsConstant()) { | 
|  | 1360 | size_t offset = | 
|  | 1361 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
|  | 1362 | __ LoadFromOffset(load_type, out, obj, offset); | 
|  | 1363 | } else { | 
|  | 1364 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); | 
|  | 1365 | __ Daddu(TMP, obj, TMP); | 
|  | 1366 | __ LoadFromOffset(load_type, out, TMP, data_offset); | 
|  | 1367 | } | 
|  | 1368 | break; | 
|  | 1369 | } | 
|  | 1370 |  | 
|  | 1371 | case Primitive::kPrimLong: { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1372 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1373 | if (index.IsConstant()) { | 
|  | 1374 | size_t offset = | 
|  | 1375 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
|  | 1376 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset); | 
|  | 1377 | } else { | 
|  | 1378 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); | 
|  | 1379 | __ Daddu(TMP, obj, TMP); | 
|  | 1380 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset); | 
|  | 1381 | } | 
|  | 1382 | break; | 
|  | 1383 | } | 
|  | 1384 |  | 
|  | 1385 | case Primitive::kPrimFloat: { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1386 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); | 
|  | 1387 | if (index.IsConstant()) { | 
|  | 1388 | size_t offset = | 
|  | 1389 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
|  | 1390 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset); | 
|  | 1391 | } else { | 
|  | 1392 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); | 
|  | 1393 | __ Daddu(TMP, obj, TMP); | 
|  | 1394 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset); | 
|  | 1395 | } | 
|  | 1396 | break; | 
|  | 1397 | } | 
|  | 1398 |  | 
|  | 1399 | case Primitive::kPrimDouble: { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1400 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); | 
|  | 1401 | if (index.IsConstant()) { | 
|  | 1402 | size_t offset = | 
|  | 1403 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
|  | 1404 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset); | 
|  | 1405 | } else { | 
|  | 1406 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); | 
|  | 1407 | __ Daddu(TMP, obj, TMP); | 
|  | 1408 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset); | 
|  | 1409 | } | 
|  | 1410 | break; | 
|  | 1411 | } | 
|  | 1412 |  | 
|  | 1413 | case Primitive::kPrimVoid: | 
|  | 1414 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); | 
|  | 1415 | UNREACHABLE(); | 
|  | 1416 | } | 
|  | 1417 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1418 | } | 
|  | 1419 |  | 
|  | 1420 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { | 
|  | 1421 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 1422 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1423 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1424 | } | 
|  | 1425 |  | 
|  | 1426 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { | 
|  | 1427 | LocationSummary* locations = instruction->GetLocations(); | 
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 1428 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1429 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1430 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1431 | __ LoadFromOffset(kLoadWord, out, obj, offset); | 
|  | 1432 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1433 | } | 
|  | 1434 |  | 
|  | 1435 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { | 
| David Brazdil | bb3d505 | 2015-09-21 18:39:16 +0100 | [diff] [blame] | 1436 | bool needs_runtime_call = instruction->NeedsTypeCheck(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1437 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( | 
|  | 1438 | instruction, | 
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame^] | 1439 | needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); | 
| David Brazdil | bb3d505 | 2015-09-21 18:39:16 +0100 | [diff] [blame] | 1440 | if (needs_runtime_call) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1441 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 1442 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 1443 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
|  | 1444 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); | 
|  | 1445 | } else { | 
|  | 1446 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1447 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 1448 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { | 
|  | 1449 | locations->SetInAt(2, Location::RequiresFpuRegister()); | 
|  | 1450 | } else { | 
|  | 1451 | locations->SetInAt(2, Location::RequiresRegister()); | 
|  | 1452 | } | 
|  | 1453 | } | 
|  | 1454 | } | 
|  | 1455 |  | 
|  | 1456 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { | 
|  | 1457 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1458 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1459 | Location index = locations->InAt(1); | 
|  | 1460 | Primitive::Type value_type = instruction->GetComponentType(); | 
|  | 1461 | bool needs_runtime_call = locations->WillCall(); | 
|  | 1462 | bool needs_write_barrier = | 
|  | 1463 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); | 
|  | 1464 |  | 
|  | 1465 | switch (value_type) { | 
|  | 1466 | case Primitive::kPrimBoolean: | 
|  | 1467 | case Primitive::kPrimByte: { | 
|  | 1468 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); | 
|  | 1469 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); | 
|  | 1470 | if (index.IsConstant()) { | 
|  | 1471 | size_t offset = | 
|  | 1472 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; | 
|  | 1473 | __ StoreToOffset(kStoreByte, value, obj, offset); | 
|  | 1474 | } else { | 
|  | 1475 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); | 
|  | 1476 | __ StoreToOffset(kStoreByte, value, TMP, data_offset); | 
|  | 1477 | } | 
|  | 1478 | break; | 
|  | 1479 | } | 
|  | 1480 |  | 
|  | 1481 | case Primitive::kPrimShort: | 
|  | 1482 | case Primitive::kPrimChar: { | 
|  | 1483 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); | 
|  | 1484 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); | 
|  | 1485 | if (index.IsConstant()) { | 
|  | 1486 | size_t offset = | 
|  | 1487 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; | 
|  | 1488 | __ StoreToOffset(kStoreHalfword, value, obj, offset); | 
|  | 1489 | } else { | 
|  | 1490 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2); | 
|  | 1491 | __ Daddu(TMP, obj, TMP); | 
|  | 1492 | __ StoreToOffset(kStoreHalfword, value, TMP, data_offset); | 
|  | 1493 | } | 
|  | 1494 | break; | 
|  | 1495 | } | 
|  | 1496 |  | 
|  | 1497 | case Primitive::kPrimInt: | 
|  | 1498 | case Primitive::kPrimNot: { | 
|  | 1499 | if (!needs_runtime_call) { | 
|  | 1500 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); | 
|  | 1501 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); | 
|  | 1502 | if (index.IsConstant()) { | 
|  | 1503 | size_t offset = | 
|  | 1504 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
|  | 1505 | __ StoreToOffset(kStoreWord, value, obj, offset); | 
|  | 1506 | } else { | 
|  | 1507 | DCHECK(index.IsRegister()) << index; | 
|  | 1508 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); | 
|  | 1509 | __ Daddu(TMP, obj, TMP); | 
|  | 1510 | __ StoreToOffset(kStoreWord, value, TMP, data_offset); | 
|  | 1511 | } | 
|  | 1512 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1513 | if (needs_write_barrier) { | 
|  | 1514 | DCHECK_EQ(value_type, Primitive::kPrimNot); | 
| Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1515 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1516 | } | 
|  | 1517 | } else { | 
|  | 1518 | DCHECK_EQ(value_type, Primitive::kPrimNot); | 
|  | 1519 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), | 
|  | 1520 | instruction, | 
|  | 1521 | instruction->GetDexPc(), | 
|  | 1522 | nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 1523 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1524 | } | 
|  | 1525 | break; | 
|  | 1526 | } | 
|  | 1527 |  | 
|  | 1528 | case Primitive::kPrimLong: { | 
|  | 1529 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); | 
|  | 1530 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); | 
|  | 1531 | if (index.IsConstant()) { | 
|  | 1532 | size_t offset = | 
|  | 1533 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
|  | 1534 | __ StoreToOffset(kStoreDoubleword, value, obj, offset); | 
|  | 1535 | } else { | 
|  | 1536 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); | 
|  | 1537 | __ Daddu(TMP, obj, TMP); | 
|  | 1538 | __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset); | 
|  | 1539 | } | 
|  | 1540 | break; | 
|  | 1541 | } | 
|  | 1542 |  | 
|  | 1543 | case Primitive::kPrimFloat: { | 
|  | 1544 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); | 
|  | 1545 | FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>(); | 
|  | 1546 | DCHECK(locations->InAt(2).IsFpuRegister()); | 
|  | 1547 | if (index.IsConstant()) { | 
|  | 1548 | size_t offset = | 
|  | 1549 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
|  | 1550 | __ StoreFpuToOffset(kStoreWord, value, obj, offset); | 
|  | 1551 | } else { | 
|  | 1552 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); | 
|  | 1553 | __ Daddu(TMP, obj, TMP); | 
|  | 1554 | __ StoreFpuToOffset(kStoreWord, value, TMP, data_offset); | 
|  | 1555 | } | 
|  | 1556 | break; | 
|  | 1557 | } | 
|  | 1558 |  | 
|  | 1559 | case Primitive::kPrimDouble: { | 
|  | 1560 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); | 
|  | 1561 | FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>(); | 
|  | 1562 | DCHECK(locations->InAt(2).IsFpuRegister()); | 
|  | 1563 | if (index.IsConstant()) { | 
|  | 1564 | size_t offset = | 
|  | 1565 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
|  | 1566 | __ StoreFpuToOffset(kStoreDoubleword, value, obj, offset); | 
|  | 1567 | } else { | 
|  | 1568 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); | 
|  | 1569 | __ Daddu(TMP, obj, TMP); | 
|  | 1570 | __ StoreFpuToOffset(kStoreDoubleword, value, TMP, data_offset); | 
|  | 1571 | } | 
|  | 1572 | break; | 
|  | 1573 | } | 
|  | 1574 |  | 
|  | 1575 | case Primitive::kPrimVoid: | 
|  | 1576 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); | 
|  | 1577 | UNREACHABLE(); | 
|  | 1578 | } | 
|  | 1579 |  | 
|  | 1580 | // Ints and objects are handled in the switch. | 
|  | 1581 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { | 
|  | 1582 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1583 | } | 
|  | 1584 | } | 
|  | 1585 |  | 
|  | 1586 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1587 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
|  | 1588 | ? LocationSummary::kCallOnSlowPath | 
|  | 1589 | : LocationSummary::kNoCall; | 
|  | 1590 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1591 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1592 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 1593 | if (instruction->HasUses()) { | 
|  | 1594 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 1595 | } | 
|  | 1596 | } | 
|  | 1597 |  | 
|  | 1598 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { | 
|  | 1599 | LocationSummary* locations = instruction->GetLocations(); | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1600 | BoundsCheckSlowPathMIPS64* slow_path = | 
|  | 1601 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1602 | codegen_->AddSlowPath(slow_path); | 
|  | 1603 |  | 
|  | 1604 | GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1605 | GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>(); | 
|  | 1606 |  | 
|  | 1607 | // length is limited by the maximum positive signed 32-bit integer. | 
|  | 1608 | // Unsigned comparison of length and index checks for index < 0 | 
|  | 1609 | // and for length <= index simultaneously. | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1610 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1611 | } | 
|  | 1612 |  | 
|  | 1613 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { | 
|  | 1614 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( | 
|  | 1615 | instruction, | 
|  | 1616 | LocationSummary::kCallOnSlowPath); | 
|  | 1617 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1618 | locations->SetInAt(1, Location::RequiresRegister()); | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1619 | // Note that TypeCheckSlowPathMIPS64 uses this register too. | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1620 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 1621 | } | 
|  | 1622 |  | 
|  | 1623 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { | 
|  | 1624 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1625 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1626 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); | 
|  | 1627 | GpuRegister obj_cls = locations->GetTemp(0).AsRegister<GpuRegister>(); | 
|  | 1628 |  | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1629 | SlowPathCodeMIPS64* slow_path = | 
|  | 1630 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1631 | codegen_->AddSlowPath(slow_path); | 
|  | 1632 |  | 
|  | 1633 | // TODO: avoid this check if we know obj is not null. | 
|  | 1634 | __ Beqzc(obj, slow_path->GetExitLabel()); | 
|  | 1635 | // Compare the class of `obj` with `cls`. | 
|  | 1636 | __ LoadFromOffset(kLoadUnsignedWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); | 
|  | 1637 | __ Bnec(obj_cls, cls, slow_path->GetEntryLabel()); | 
|  | 1638 | __ Bind(slow_path->GetExitLabel()); | 
|  | 1639 | } | 
|  | 1640 |  | 
|  | 1641 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { | 
|  | 1642 | LocationSummary* locations = | 
|  | 1643 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); | 
|  | 1644 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1645 | if (check->HasUses()) { | 
|  | 1646 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 1647 | } | 
|  | 1648 | } | 
|  | 1649 |  | 
|  | 1650 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { | 
|  | 1651 | // We assume the class is not null. | 
|  | 1652 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( | 
|  | 1653 | check->GetLoadClass(), | 
|  | 1654 | check, | 
|  | 1655 | check->GetDexPc(), | 
|  | 1656 | true); | 
|  | 1657 | codegen_->AddSlowPath(slow_path); | 
|  | 1658 | GenerateClassInitializationCheck(slow_path, | 
|  | 1659 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); | 
|  | 1660 | } | 
|  | 1661 |  | 
|  | 1662 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { | 
|  | 1663 | Primitive::Type in_type = compare->InputAt(0)->GetType(); | 
|  | 1664 |  | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1665 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1666 |  | 
|  | 1667 | switch (in_type) { | 
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1668 | case Primitive::kPrimBoolean: | 
|  | 1669 | case Primitive::kPrimByte: | 
|  | 1670 | case Primitive::kPrimShort: | 
|  | 1671 | case Primitive::kPrimChar: | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1672 | case Primitive::kPrimInt: | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1673 | case Primitive::kPrimLong: | 
|  | 1674 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1675 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1676 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1677 | break; | 
|  | 1678 |  | 
|  | 1679 | case Primitive::kPrimFloat: | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1680 | case Primitive::kPrimDouble: | 
|  | 1681 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 1682 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 1683 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1684 | break; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1685 |  | 
|  | 1686 | default: | 
|  | 1687 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; | 
|  | 1688 | } | 
|  | 1689 | } | 
|  | 1690 |  | 
|  | 1691 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { | 
|  | 1692 | LocationSummary* locations = instruction->GetLocations(); | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1693 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1694 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); | 
|  | 1695 |  | 
|  | 1696 | //  0 if: left == right | 
|  | 1697 | //  1 if: left  > right | 
|  | 1698 | // -1 if: left  < right | 
|  | 1699 | switch (in_type) { | 
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1700 | case Primitive::kPrimBoolean: | 
|  | 1701 | case Primitive::kPrimByte: | 
|  | 1702 | case Primitive::kPrimShort: | 
|  | 1703 | case Primitive::kPrimChar: | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1704 | case Primitive::kPrimInt: | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1705 | case Primitive::kPrimLong: { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1706 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1707 | Location rhs_location = locations->InAt(1); | 
|  | 1708 | bool use_imm = rhs_location.IsConstant(); | 
|  | 1709 | GpuRegister rhs = ZERO; | 
|  | 1710 | if (use_imm) { | 
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1711 | if (in_type == Primitive::kPrimLong) { | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1712 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); | 
|  | 1713 | if (value != 0) { | 
|  | 1714 | rhs = AT; | 
|  | 1715 | __ LoadConst64(rhs, value); | 
|  | 1716 | } | 
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1717 | } else { | 
|  | 1718 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); | 
|  | 1719 | if (value != 0) { | 
|  | 1720 | rhs = AT; | 
|  | 1721 | __ LoadConst32(rhs, value); | 
|  | 1722 | } | 
| Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1723 | } | 
|  | 1724 | } else { | 
|  | 1725 | rhs = rhs_location.AsRegister<GpuRegister>(); | 
|  | 1726 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1727 | __ Slt(TMP, lhs, rhs); | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1728 | __ Slt(res, rhs, lhs); | 
|  | 1729 | __ Subu(res, res, TMP); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1730 | break; | 
|  | 1731 | } | 
|  | 1732 |  | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1733 | case Primitive::kPrimFloat: { | 
|  | 1734 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); | 
|  | 1735 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); | 
|  | 1736 | Mips64Label done; | 
|  | 1737 | __ CmpEqS(FTMP, lhs, rhs); | 
|  | 1738 | __ LoadConst32(res, 0); | 
|  | 1739 | __ Bc1nez(FTMP, &done); | 
| Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 1740 | if (instruction->IsGtBias()) { | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1741 | __ CmpLtS(FTMP, lhs, rhs); | 
|  | 1742 | __ LoadConst32(res, -1); | 
|  | 1743 | __ Bc1nez(FTMP, &done); | 
|  | 1744 | __ LoadConst32(res, 1); | 
|  | 1745 | } else { | 
|  | 1746 | __ CmpLtS(FTMP, rhs, lhs); | 
|  | 1747 | __ LoadConst32(res, 1); | 
|  | 1748 | __ Bc1nez(FTMP, &done); | 
|  | 1749 | __ LoadConst32(res, -1); | 
|  | 1750 | } | 
|  | 1751 | __ Bind(&done); | 
|  | 1752 | break; | 
|  | 1753 | } | 
|  | 1754 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1755 | case Primitive::kPrimDouble: { | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1756 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); | 
|  | 1757 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); | 
|  | 1758 | Mips64Label done; | 
|  | 1759 | __ CmpEqD(FTMP, lhs, rhs); | 
|  | 1760 | __ LoadConst32(res, 0); | 
|  | 1761 | __ Bc1nez(FTMP, &done); | 
| Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 1762 | if (instruction->IsGtBias()) { | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1763 | __ CmpLtD(FTMP, lhs, rhs); | 
|  | 1764 | __ LoadConst32(res, -1); | 
|  | 1765 | __ Bc1nez(FTMP, &done); | 
|  | 1766 | __ LoadConst32(res, 1); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1767 | } else { | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1768 | __ CmpLtD(FTMP, rhs, lhs); | 
|  | 1769 | __ LoadConst32(res, 1); | 
|  | 1770 | __ Bc1nez(FTMP, &done); | 
|  | 1771 | __ LoadConst32(res, -1); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1772 | } | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1773 | __ Bind(&done); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1774 | break; | 
|  | 1775 | } | 
|  | 1776 |  | 
|  | 1777 | default: | 
|  | 1778 | LOG(FATAL) << "Unimplemented compare type " << in_type; | 
|  | 1779 | } | 
|  | 1780 | } | 
|  | 1781 |  | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1783 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1784 | switch (instruction->InputAt(0)->GetType()) { | 
|  | 1785 | default: | 
|  | 1786 | case Primitive::kPrimLong: | 
|  | 1787 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1788 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 1789 | break; | 
|  | 1790 |  | 
|  | 1791 | case Primitive::kPrimFloat: | 
|  | 1792 | case Primitive::kPrimDouble: | 
|  | 1793 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 1794 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 1795 | break; | 
|  | 1796 | } | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1797 | if (!instruction->IsEmittedAtUseSite()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1798 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1799 | } | 
|  | 1800 | } | 
|  | 1801 |  | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1803 | if (instruction->IsEmittedAtUseSite()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1804 | return; | 
|  | 1805 | } | 
|  | 1806 |  | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1807 | Primitive::Type type = instruction->InputAt(0)->GetType(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1808 | LocationSummary* locations = instruction->GetLocations(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1809 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1810 | Mips64Label true_label; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1811 |  | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1812 | switch (type) { | 
|  | 1813 | default: | 
|  | 1814 | // Integer case. | 
|  | 1815 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); | 
|  | 1816 | return; | 
|  | 1817 | case Primitive::kPrimLong: | 
|  | 1818 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); | 
|  | 1819 | return; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1820 |  | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1821 | case Primitive::kPrimFloat: | 
|  | 1822 | case Primitive::kPrimDouble: | 
|  | 1823 | // TODO: don't use branches. | 
|  | 1824 | GenerateFpCompareAndBranch(instruction->GetCondition(), | 
|  | 1825 | instruction->IsGtBias(), | 
|  | 1826 | type, | 
|  | 1827 | locations, | 
|  | 1828 | &true_label); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1829 | break; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1830 | } | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1831 |  | 
|  | 1832 | // Convert the branches into the result. | 
|  | 1833 | Mips64Label done; | 
|  | 1834 |  | 
|  | 1835 | // False case: result = 0. | 
|  | 1836 | __ LoadConst32(dst, 0); | 
|  | 1837 | __ Bc(&done); | 
|  | 1838 |  | 
|  | 1839 | // True case: result = 1. | 
|  | 1840 | __ Bind(&true_label); | 
|  | 1841 | __ LoadConst32(dst, 1); | 
|  | 1842 | __ Bind(&done); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1843 | } | 
|  | 1844 |  | 
| Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 1845 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { | 
|  | 1846 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 1847 | Primitive::Type type = instruction->GetResultType(); | 
|  | 1848 |  | 
|  | 1849 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1850 | Location second = locations->InAt(1); | 
|  | 1851 | DCHECK(second.IsConstant()); | 
|  | 1852 |  | 
|  | 1853 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1854 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1855 | int64_t imm = Int64FromConstant(second.GetConstant()); | 
|  | 1856 | DCHECK(imm == 1 || imm == -1); | 
|  | 1857 |  | 
|  | 1858 | if (instruction->IsRem()) { | 
|  | 1859 | __ Move(out, ZERO); | 
|  | 1860 | } else { | 
|  | 1861 | if (imm == -1) { | 
|  | 1862 | if (type == Primitive::kPrimInt) { | 
|  | 1863 | __ Subu(out, ZERO, dividend); | 
|  | 1864 | } else { | 
|  | 1865 | DCHECK_EQ(type, Primitive::kPrimLong); | 
|  | 1866 | __ Dsubu(out, ZERO, dividend); | 
|  | 1867 | } | 
|  | 1868 | } else if (out != dividend) { | 
|  | 1869 | __ Move(out, dividend); | 
|  | 1870 | } | 
|  | 1871 | } | 
|  | 1872 | } | 
|  | 1873 |  | 
|  | 1874 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { | 
|  | 1875 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 1876 | Primitive::Type type = instruction->GetResultType(); | 
|  | 1877 |  | 
|  | 1878 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1879 | Location second = locations->InAt(1); | 
|  | 1880 | DCHECK(second.IsConstant()); | 
|  | 1881 |  | 
|  | 1882 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1883 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1884 | int64_t imm = Int64FromConstant(second.GetConstant()); | 
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 1885 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); | 
| Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 1886 | int ctz_imm = CTZ(abs_imm); | 
|  | 1887 |  | 
|  | 1888 | if (instruction->IsDiv()) { | 
|  | 1889 | if (type == Primitive::kPrimInt) { | 
|  | 1890 | if (ctz_imm == 1) { | 
|  | 1891 | // Fast path for division by +/-2, which is very common. | 
|  | 1892 | __ Srl(TMP, dividend, 31); | 
|  | 1893 | } else { | 
|  | 1894 | __ Sra(TMP, dividend, 31); | 
|  | 1895 | __ Srl(TMP, TMP, 32 - ctz_imm); | 
|  | 1896 | } | 
|  | 1897 | __ Addu(out, dividend, TMP); | 
|  | 1898 | __ Sra(out, out, ctz_imm); | 
|  | 1899 | if (imm < 0) { | 
|  | 1900 | __ Subu(out, ZERO, out); | 
|  | 1901 | } | 
|  | 1902 | } else { | 
|  | 1903 | DCHECK_EQ(type, Primitive::kPrimLong); | 
|  | 1904 | if (ctz_imm == 1) { | 
|  | 1905 | // Fast path for division by +/-2, which is very common. | 
|  | 1906 | __ Dsrl32(TMP, dividend, 31); | 
|  | 1907 | } else { | 
|  | 1908 | __ Dsra32(TMP, dividend, 31); | 
|  | 1909 | if (ctz_imm > 32) { | 
|  | 1910 | __ Dsrl(TMP, TMP, 64 - ctz_imm); | 
|  | 1911 | } else { | 
|  | 1912 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); | 
|  | 1913 | } | 
|  | 1914 | } | 
|  | 1915 | __ Daddu(out, dividend, TMP); | 
|  | 1916 | if (ctz_imm < 32) { | 
|  | 1917 | __ Dsra(out, out, ctz_imm); | 
|  | 1918 | } else { | 
|  | 1919 | __ Dsra32(out, out, ctz_imm - 32); | 
|  | 1920 | } | 
|  | 1921 | if (imm < 0) { | 
|  | 1922 | __ Dsubu(out, ZERO, out); | 
|  | 1923 | } | 
|  | 1924 | } | 
|  | 1925 | } else { | 
|  | 1926 | if (type == Primitive::kPrimInt) { | 
|  | 1927 | if (ctz_imm == 1) { | 
|  | 1928 | // Fast path for modulo +/-2, which is very common. | 
|  | 1929 | __ Sra(TMP, dividend, 31); | 
|  | 1930 | __ Subu(out, dividend, TMP); | 
|  | 1931 | __ Andi(out, out, 1); | 
|  | 1932 | __ Addu(out, out, TMP); | 
|  | 1933 | } else { | 
|  | 1934 | __ Sra(TMP, dividend, 31); | 
|  | 1935 | __ Srl(TMP, TMP, 32 - ctz_imm); | 
|  | 1936 | __ Addu(out, dividend, TMP); | 
|  | 1937 | if (IsUint<16>(abs_imm - 1)) { | 
|  | 1938 | __ Andi(out, out, abs_imm - 1); | 
|  | 1939 | } else { | 
|  | 1940 | __ Sll(out, out, 32 - ctz_imm); | 
|  | 1941 | __ Srl(out, out, 32 - ctz_imm); | 
|  | 1942 | } | 
|  | 1943 | __ Subu(out, out, TMP); | 
|  | 1944 | } | 
|  | 1945 | } else { | 
|  | 1946 | DCHECK_EQ(type, Primitive::kPrimLong); | 
|  | 1947 | if (ctz_imm == 1) { | 
|  | 1948 | // Fast path for modulo +/-2, which is very common. | 
|  | 1949 | __ Dsra32(TMP, dividend, 31); | 
|  | 1950 | __ Dsubu(out, dividend, TMP); | 
|  | 1951 | __ Andi(out, out, 1); | 
|  | 1952 | __ Daddu(out, out, TMP); | 
|  | 1953 | } else { | 
|  | 1954 | __ Dsra32(TMP, dividend, 31); | 
|  | 1955 | if (ctz_imm > 32) { | 
|  | 1956 | __ Dsrl(TMP, TMP, 64 - ctz_imm); | 
|  | 1957 | } else { | 
|  | 1958 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); | 
|  | 1959 | } | 
|  | 1960 | __ Daddu(out, dividend, TMP); | 
|  | 1961 | if (IsUint<16>(abs_imm - 1)) { | 
|  | 1962 | __ Andi(out, out, abs_imm - 1); | 
|  | 1963 | } else { | 
|  | 1964 | if (ctz_imm > 32) { | 
|  | 1965 | __ Dsll(out, out, 64 - ctz_imm); | 
|  | 1966 | __ Dsrl(out, out, 64 - ctz_imm); | 
|  | 1967 | } else { | 
|  | 1968 | __ Dsll32(out, out, 32 - ctz_imm); | 
|  | 1969 | __ Dsrl32(out, out, 32 - ctz_imm); | 
|  | 1970 | } | 
|  | 1971 | } | 
|  | 1972 | __ Dsubu(out, out, TMP); | 
|  | 1973 | } | 
|  | 1974 | } | 
|  | 1975 | } | 
|  | 1976 | } | 
|  | 1977 |  | 
|  | 1978 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { | 
|  | 1979 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 1980 |  | 
|  | 1981 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1982 | Location second = locations->InAt(1); | 
|  | 1983 | DCHECK(second.IsConstant()); | 
|  | 1984 |  | 
|  | 1985 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 1986 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 1987 | int64_t imm = Int64FromConstant(second.GetConstant()); | 
|  | 1988 |  | 
|  | 1989 | Primitive::Type type = instruction->GetResultType(); | 
|  | 1990 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; | 
|  | 1991 |  | 
|  | 1992 | int64_t magic; | 
|  | 1993 | int shift; | 
|  | 1994 | CalculateMagicAndShiftForDivRem(imm, | 
|  | 1995 | (type == Primitive::kPrimLong), | 
|  | 1996 | &magic, | 
|  | 1997 | &shift); | 
|  | 1998 |  | 
|  | 1999 | if (type == Primitive::kPrimInt) { | 
|  | 2000 | __ LoadConst32(TMP, magic); | 
|  | 2001 | __ MuhR6(TMP, dividend, TMP); | 
|  | 2002 |  | 
|  | 2003 | if (imm > 0 && magic < 0) { | 
|  | 2004 | __ Addu(TMP, TMP, dividend); | 
|  | 2005 | } else if (imm < 0 && magic > 0) { | 
|  | 2006 | __ Subu(TMP, TMP, dividend); | 
|  | 2007 | } | 
|  | 2008 |  | 
|  | 2009 | if (shift != 0) { | 
|  | 2010 | __ Sra(TMP, TMP, shift); | 
|  | 2011 | } | 
|  | 2012 |  | 
|  | 2013 | if (instruction->IsDiv()) { | 
|  | 2014 | __ Sra(out, TMP, 31); | 
|  | 2015 | __ Subu(out, TMP, out); | 
|  | 2016 | } else { | 
|  | 2017 | __ Sra(AT, TMP, 31); | 
|  | 2018 | __ Subu(AT, TMP, AT); | 
|  | 2019 | __ LoadConst32(TMP, imm); | 
|  | 2020 | __ MulR6(TMP, AT, TMP); | 
|  | 2021 | __ Subu(out, dividend, TMP); | 
|  | 2022 | } | 
|  | 2023 | } else { | 
|  | 2024 | __ LoadConst64(TMP, magic); | 
|  | 2025 | __ Dmuh(TMP, dividend, TMP); | 
|  | 2026 |  | 
|  | 2027 | if (imm > 0 && magic < 0) { | 
|  | 2028 | __ Daddu(TMP, TMP, dividend); | 
|  | 2029 | } else if (imm < 0 && magic > 0) { | 
|  | 2030 | __ Dsubu(TMP, TMP, dividend); | 
|  | 2031 | } | 
|  | 2032 |  | 
|  | 2033 | if (shift >= 32) { | 
|  | 2034 | __ Dsra32(TMP, TMP, shift - 32); | 
|  | 2035 | } else if (shift > 0) { | 
|  | 2036 | __ Dsra(TMP, TMP, shift); | 
|  | 2037 | } | 
|  | 2038 |  | 
|  | 2039 | if (instruction->IsDiv()) { | 
|  | 2040 | __ Dsra32(out, TMP, 31); | 
|  | 2041 | __ Dsubu(out, TMP, out); | 
|  | 2042 | } else { | 
|  | 2043 | __ Dsra32(AT, TMP, 31); | 
|  | 2044 | __ Dsubu(AT, TMP, AT); | 
|  | 2045 | __ LoadConst64(TMP, imm); | 
|  | 2046 | __ Dmul(TMP, AT, TMP); | 
|  | 2047 | __ Dsubu(out, dividend, TMP); | 
|  | 2048 | } | 
|  | 2049 | } | 
|  | 2050 | } | 
|  | 2051 |  | 
|  | 2052 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { | 
|  | 2053 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 2054 | Primitive::Type type = instruction->GetResultType(); | 
|  | 2055 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; | 
|  | 2056 |  | 
|  | 2057 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2058 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 2059 | Location second = locations->InAt(1); | 
|  | 2060 |  | 
|  | 2061 | if (second.IsConstant()) { | 
|  | 2062 | int64_t imm = Int64FromConstant(second.GetConstant()); | 
|  | 2063 | if (imm == 0) { | 
|  | 2064 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. | 
|  | 2065 | } else if (imm == 1 || imm == -1) { | 
|  | 2066 | DivRemOneOrMinusOne(instruction); | 
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2067 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { | 
| Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2068 | DivRemByPowerOfTwo(instruction); | 
|  | 2069 | } else { | 
|  | 2070 | DCHECK(imm <= -2 || imm >= 2); | 
|  | 2071 | GenerateDivRemWithAnyConstant(instruction); | 
|  | 2072 | } | 
|  | 2073 | } else { | 
|  | 2074 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 2075 | GpuRegister divisor = second.AsRegister<GpuRegister>(); | 
|  | 2076 | if (instruction->IsDiv()) { | 
|  | 2077 | if (type == Primitive::kPrimInt) | 
|  | 2078 | __ DivR6(out, dividend, divisor); | 
|  | 2079 | else | 
|  | 2080 | __ Ddiv(out, dividend, divisor); | 
|  | 2081 | } else { | 
|  | 2082 | if (type == Primitive::kPrimInt) | 
|  | 2083 | __ ModR6(out, dividend, divisor); | 
|  | 2084 | else | 
|  | 2085 | __ Dmod(out, dividend, divisor); | 
|  | 2086 | } | 
|  | 2087 | } | 
|  | 2088 | } | 
|  | 2089 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2090 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { | 
|  | 2091 | LocationSummary* locations = | 
|  | 2092 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); | 
|  | 2093 | switch (div->GetResultType()) { | 
|  | 2094 | case Primitive::kPrimInt: | 
|  | 2095 | case Primitive::kPrimLong: | 
|  | 2096 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2097 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2098 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 2099 | break; | 
|  | 2100 |  | 
|  | 2101 | case Primitive::kPrimFloat: | 
|  | 2102 | case Primitive::kPrimDouble: | 
|  | 2103 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2104 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 2105 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 2106 | break; | 
|  | 2107 |  | 
|  | 2108 | default: | 
|  | 2109 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); | 
|  | 2110 | } | 
|  | 2111 | } | 
|  | 2112 |  | 
|  | 2113 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { | 
|  | 2114 | Primitive::Type type = instruction->GetType(); | 
|  | 2115 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2116 |  | 
|  | 2117 | switch (type) { | 
|  | 2118 | case Primitive::kPrimInt: | 
| Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2119 | case Primitive::kPrimLong: | 
|  | 2120 | GenerateDivRemIntegral(instruction); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2121 | break; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2122 | case Primitive::kPrimFloat: | 
|  | 2123 | case Primitive::kPrimDouble: { | 
|  | 2124 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); | 
|  | 2125 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); | 
|  | 2126 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); | 
|  | 2127 | if (type == Primitive::kPrimFloat) | 
|  | 2128 | __ DivS(dst, lhs, rhs); | 
|  | 2129 | else | 
|  | 2130 | __ DivD(dst, lhs, rhs); | 
|  | 2131 | break; | 
|  | 2132 | } | 
|  | 2133 | default: | 
|  | 2134 | LOG(FATAL) << "Unexpected div type " << type; | 
|  | 2135 | } | 
|  | 2136 | } | 
|  | 2137 |  | 
|  | 2138 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2139 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
|  | 2140 | ? LocationSummary::kCallOnSlowPath | 
|  | 2141 | : LocationSummary::kNoCall; | 
|  | 2142 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2143 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); | 
|  | 2144 | if (instruction->HasUses()) { | 
|  | 2145 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2146 | } | 
|  | 2147 | } | 
|  | 2148 |  | 
|  | 2149 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
|  | 2150 | SlowPathCodeMIPS64* slow_path = | 
|  | 2151 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction); | 
|  | 2152 | codegen_->AddSlowPath(slow_path); | 
|  | 2153 | Location value = instruction->GetLocations()->InAt(0); | 
|  | 2154 |  | 
|  | 2155 | Primitive::Type type = instruction->GetType(); | 
|  | 2156 |  | 
| Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2157 | if (!Primitive::IsIntegralType(type)) { | 
|  | 2158 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; | 
| Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 2159 | return; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2160 | } | 
|  | 2161 |  | 
|  | 2162 | if (value.IsConstant()) { | 
|  | 2163 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); | 
|  | 2164 | if (divisor == 0) { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2165 | __ Bc(slow_path->GetEntryLabel()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2166 | } else { | 
|  | 2167 | // A division by a non-null constant is valid. We don't need to perform | 
|  | 2168 | // any check, so simply fall through. | 
|  | 2169 | } | 
|  | 2170 | } else { | 
|  | 2171 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); | 
|  | 2172 | } | 
|  | 2173 | } | 
|  | 2174 |  | 
|  | 2175 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { | 
|  | 2176 | LocationSummary* locations = | 
|  | 2177 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
|  | 2178 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2179 | } | 
|  | 2180 |  | 
|  | 2181 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { | 
|  | 2182 | // Will be generated at use site. | 
|  | 2183 | } | 
|  | 2184 |  | 
|  | 2185 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { | 
|  | 2186 | exit->SetLocations(nullptr); | 
|  | 2187 | } | 
|  | 2188 |  | 
|  | 2189 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { | 
|  | 2190 | } | 
|  | 2191 |  | 
|  | 2192 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { | 
|  | 2193 | LocationSummary* locations = | 
|  | 2194 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
|  | 2195 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2196 | } | 
|  | 2197 |  | 
|  | 2198 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { | 
|  | 2199 | // Will be generated at use site. | 
|  | 2200 | } | 
|  | 2201 |  | 
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2202 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2203 | DCHECK(!successor->IsExitBlock()); | 
|  | 2204 | HBasicBlock* block = got->GetBlock(); | 
|  | 2205 | HInstruction* previous = got->GetPrevious(); | 
|  | 2206 | HLoopInformation* info = block->GetLoopInformation(); | 
|  | 2207 |  | 
|  | 2208 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { | 
|  | 2209 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); | 
|  | 2210 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); | 
|  | 2211 | return; | 
|  | 2212 | } | 
|  | 2213 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { | 
|  | 2214 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); | 
|  | 2215 | } | 
|  | 2216 | if (!codegen_->GoesToNextBlock(block, successor)) { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2217 | __ Bc(codegen_->GetLabelOf(successor)); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2218 | } | 
|  | 2219 | } | 
|  | 2220 |  | 
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2221 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { | 
|  | 2222 | got->SetLocations(nullptr); | 
|  | 2223 | } | 
|  | 2224 |  | 
|  | 2225 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { | 
|  | 2226 | HandleGoto(got, got->GetSuccessor()); | 
|  | 2227 | } | 
|  | 2228 |  | 
|  | 2229 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { | 
|  | 2230 | try_boundary->SetLocations(nullptr); | 
|  | 2231 | } | 
|  | 2232 |  | 
|  | 2233 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { | 
|  | 2234 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); | 
|  | 2235 | if (!successor->IsExitBlock()) { | 
|  | 2236 | HandleGoto(try_boundary, successor); | 
|  | 2237 | } | 
|  | 2238 | } | 
|  | 2239 |  | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2240 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, | 
|  | 2241 | bool is64bit, | 
|  | 2242 | LocationSummary* locations) { | 
|  | 2243 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
|  | 2244 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 2245 | Location rhs_location = locations->InAt(1); | 
|  | 2246 | GpuRegister rhs_reg = ZERO; | 
|  | 2247 | int64_t rhs_imm = 0; | 
|  | 2248 | bool use_imm = rhs_location.IsConstant(); | 
|  | 2249 | if (use_imm) { | 
|  | 2250 | if (is64bit) { | 
|  | 2251 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); | 
|  | 2252 | } else { | 
|  | 2253 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); | 
|  | 2254 | } | 
|  | 2255 | } else { | 
|  | 2256 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); | 
|  | 2257 | } | 
|  | 2258 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); | 
|  | 2259 |  | 
|  | 2260 | switch (cond) { | 
|  | 2261 | case kCondEQ: | 
|  | 2262 | case kCondNE: | 
|  | 2263 | if (use_imm && IsUint<16>(rhs_imm)) { | 
|  | 2264 | __ Xori(dst, lhs, rhs_imm); | 
|  | 2265 | } else { | 
|  | 2266 | if (use_imm) { | 
|  | 2267 | rhs_reg = TMP; | 
|  | 2268 | __ LoadConst64(rhs_reg, rhs_imm); | 
|  | 2269 | } | 
|  | 2270 | __ Xor(dst, lhs, rhs_reg); | 
|  | 2271 | } | 
|  | 2272 | if (cond == kCondEQ) { | 
|  | 2273 | __ Sltiu(dst, dst, 1); | 
|  | 2274 | } else { | 
|  | 2275 | __ Sltu(dst, ZERO, dst); | 
|  | 2276 | } | 
|  | 2277 | break; | 
|  | 2278 |  | 
|  | 2279 | case kCondLT: | 
|  | 2280 | case kCondGE: | 
|  | 2281 | if (use_imm && IsInt<16>(rhs_imm)) { | 
|  | 2282 | __ Slti(dst, lhs, rhs_imm); | 
|  | 2283 | } else { | 
|  | 2284 | if (use_imm) { | 
|  | 2285 | rhs_reg = TMP; | 
|  | 2286 | __ LoadConst64(rhs_reg, rhs_imm); | 
|  | 2287 | } | 
|  | 2288 | __ Slt(dst, lhs, rhs_reg); | 
|  | 2289 | } | 
|  | 2290 | if (cond == kCondGE) { | 
|  | 2291 | // Simulate lhs >= rhs via !(lhs < rhs) since there's | 
|  | 2292 | // only the slt instruction but no sge. | 
|  | 2293 | __ Xori(dst, dst, 1); | 
|  | 2294 | } | 
|  | 2295 | break; | 
|  | 2296 |  | 
|  | 2297 | case kCondLE: | 
|  | 2298 | case kCondGT: | 
|  | 2299 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { | 
|  | 2300 | // Simulate lhs <= rhs via lhs < rhs + 1. | 
|  | 2301 | __ Slti(dst, lhs, rhs_imm_plus_one); | 
|  | 2302 | if (cond == kCondGT) { | 
|  | 2303 | // Simulate lhs > rhs via !(lhs <= rhs) since there's | 
|  | 2304 | // only the slti instruction but no sgti. | 
|  | 2305 | __ Xori(dst, dst, 1); | 
|  | 2306 | } | 
|  | 2307 | } else { | 
|  | 2308 | if (use_imm) { | 
|  | 2309 | rhs_reg = TMP; | 
|  | 2310 | __ LoadConst64(rhs_reg, rhs_imm); | 
|  | 2311 | } | 
|  | 2312 | __ Slt(dst, rhs_reg, lhs); | 
|  | 2313 | if (cond == kCondLE) { | 
|  | 2314 | // Simulate lhs <= rhs via !(rhs < lhs) since there's | 
|  | 2315 | // only the slt instruction but no sle. | 
|  | 2316 | __ Xori(dst, dst, 1); | 
|  | 2317 | } | 
|  | 2318 | } | 
|  | 2319 | break; | 
|  | 2320 |  | 
|  | 2321 | case kCondB: | 
|  | 2322 | case kCondAE: | 
|  | 2323 | if (use_imm && IsInt<16>(rhs_imm)) { | 
|  | 2324 | // Sltiu sign-extends its 16-bit immediate operand before | 
|  | 2325 | // the comparison and thus lets us compare directly with | 
|  | 2326 | // unsigned values in the ranges [0, 0x7fff] and | 
|  | 2327 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. | 
|  | 2328 | __ Sltiu(dst, lhs, rhs_imm); | 
|  | 2329 | } else { | 
|  | 2330 | if (use_imm) { | 
|  | 2331 | rhs_reg = TMP; | 
|  | 2332 | __ LoadConst64(rhs_reg, rhs_imm); | 
|  | 2333 | } | 
|  | 2334 | __ Sltu(dst, lhs, rhs_reg); | 
|  | 2335 | } | 
|  | 2336 | if (cond == kCondAE) { | 
|  | 2337 | // Simulate lhs >= rhs via !(lhs < rhs) since there's | 
|  | 2338 | // only the sltu instruction but no sgeu. | 
|  | 2339 | __ Xori(dst, dst, 1); | 
|  | 2340 | } | 
|  | 2341 | break; | 
|  | 2342 |  | 
|  | 2343 | case kCondBE: | 
|  | 2344 | case kCondA: | 
|  | 2345 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { | 
|  | 2346 | // Simulate lhs <= rhs via lhs < rhs + 1. | 
|  | 2347 | // Note that this only works if rhs + 1 does not overflow | 
|  | 2348 | // to 0, hence the check above. | 
|  | 2349 | // Sltiu sign-extends its 16-bit immediate operand before | 
|  | 2350 | // the comparison and thus lets us compare directly with | 
|  | 2351 | // unsigned values in the ranges [0, 0x7fff] and | 
|  | 2352 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. | 
|  | 2353 | __ Sltiu(dst, lhs, rhs_imm_plus_one); | 
|  | 2354 | if (cond == kCondA) { | 
|  | 2355 | // Simulate lhs > rhs via !(lhs <= rhs) since there's | 
|  | 2356 | // only the sltiu instruction but no sgtiu. | 
|  | 2357 | __ Xori(dst, dst, 1); | 
|  | 2358 | } | 
|  | 2359 | } else { | 
|  | 2360 | if (use_imm) { | 
|  | 2361 | rhs_reg = TMP; | 
|  | 2362 | __ LoadConst64(rhs_reg, rhs_imm); | 
|  | 2363 | } | 
|  | 2364 | __ Sltu(dst, rhs_reg, lhs); | 
|  | 2365 | if (cond == kCondBE) { | 
|  | 2366 | // Simulate lhs <= rhs via !(rhs < lhs) since there's | 
|  | 2367 | // only the sltu instruction but no sleu. | 
|  | 2368 | __ Xori(dst, dst, 1); | 
|  | 2369 | } | 
|  | 2370 | } | 
|  | 2371 | break; | 
|  | 2372 | } | 
|  | 2373 | } | 
|  | 2374 |  | 
|  | 2375 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, | 
|  | 2376 | bool is64bit, | 
|  | 2377 | LocationSummary* locations, | 
|  | 2378 | Mips64Label* label) { | 
|  | 2379 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 2380 | Location rhs_location = locations->InAt(1); | 
|  | 2381 | GpuRegister rhs_reg = ZERO; | 
|  | 2382 | int64_t rhs_imm = 0; | 
|  | 2383 | bool use_imm = rhs_location.IsConstant(); | 
|  | 2384 | if (use_imm) { | 
|  | 2385 | if (is64bit) { | 
|  | 2386 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); | 
|  | 2387 | } else { | 
|  | 2388 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); | 
|  | 2389 | } | 
|  | 2390 | } else { | 
|  | 2391 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); | 
|  | 2392 | } | 
|  | 2393 |  | 
|  | 2394 | if (use_imm && rhs_imm == 0) { | 
|  | 2395 | switch (cond) { | 
|  | 2396 | case kCondEQ: | 
|  | 2397 | case kCondBE:  // <= 0 if zero | 
|  | 2398 | __ Beqzc(lhs, label); | 
|  | 2399 | break; | 
|  | 2400 | case kCondNE: | 
|  | 2401 | case kCondA:  // > 0 if non-zero | 
|  | 2402 | __ Bnezc(lhs, label); | 
|  | 2403 | break; | 
|  | 2404 | case kCondLT: | 
|  | 2405 | __ Bltzc(lhs, label); | 
|  | 2406 | break; | 
|  | 2407 | case kCondGE: | 
|  | 2408 | __ Bgezc(lhs, label); | 
|  | 2409 | break; | 
|  | 2410 | case kCondLE: | 
|  | 2411 | __ Blezc(lhs, label); | 
|  | 2412 | break; | 
|  | 2413 | case kCondGT: | 
|  | 2414 | __ Bgtzc(lhs, label); | 
|  | 2415 | break; | 
|  | 2416 | case kCondB:  // always false | 
|  | 2417 | break; | 
|  | 2418 | case kCondAE:  // always true | 
|  | 2419 | __ Bc(label); | 
|  | 2420 | break; | 
|  | 2421 | } | 
|  | 2422 | } else { | 
|  | 2423 | if (use_imm) { | 
|  | 2424 | rhs_reg = TMP; | 
|  | 2425 | __ LoadConst64(rhs_reg, rhs_imm); | 
|  | 2426 | } | 
|  | 2427 | switch (cond) { | 
|  | 2428 | case kCondEQ: | 
|  | 2429 | __ Beqc(lhs, rhs_reg, label); | 
|  | 2430 | break; | 
|  | 2431 | case kCondNE: | 
|  | 2432 | __ Bnec(lhs, rhs_reg, label); | 
|  | 2433 | break; | 
|  | 2434 | case kCondLT: | 
|  | 2435 | __ Bltc(lhs, rhs_reg, label); | 
|  | 2436 | break; | 
|  | 2437 | case kCondGE: | 
|  | 2438 | __ Bgec(lhs, rhs_reg, label); | 
|  | 2439 | break; | 
|  | 2440 | case kCondLE: | 
|  | 2441 | __ Bgec(rhs_reg, lhs, label); | 
|  | 2442 | break; | 
|  | 2443 | case kCondGT: | 
|  | 2444 | __ Bltc(rhs_reg, lhs, label); | 
|  | 2445 | break; | 
|  | 2446 | case kCondB: | 
|  | 2447 | __ Bltuc(lhs, rhs_reg, label); | 
|  | 2448 | break; | 
|  | 2449 | case kCondAE: | 
|  | 2450 | __ Bgeuc(lhs, rhs_reg, label); | 
|  | 2451 | break; | 
|  | 2452 | case kCondBE: | 
|  | 2453 | __ Bgeuc(rhs_reg, lhs, label); | 
|  | 2454 | break; | 
|  | 2455 | case kCondA: | 
|  | 2456 | __ Bltuc(rhs_reg, lhs, label); | 
|  | 2457 | break; | 
|  | 2458 | } | 
|  | 2459 | } | 
|  | 2460 | } | 
|  | 2461 |  | 
|  | 2462 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, | 
|  | 2463 | bool gt_bias, | 
|  | 2464 | Primitive::Type type, | 
|  | 2465 | LocationSummary* locations, | 
|  | 2466 | Mips64Label* label) { | 
|  | 2467 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); | 
|  | 2468 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); | 
|  | 2469 | if (type == Primitive::kPrimFloat) { | 
|  | 2470 | switch (cond) { | 
|  | 2471 | case kCondEQ: | 
|  | 2472 | __ CmpEqS(FTMP, lhs, rhs); | 
|  | 2473 | __ Bc1nez(FTMP, label); | 
|  | 2474 | break; | 
|  | 2475 | case kCondNE: | 
|  | 2476 | __ CmpEqS(FTMP, lhs, rhs); | 
|  | 2477 | __ Bc1eqz(FTMP, label); | 
|  | 2478 | break; | 
|  | 2479 | case kCondLT: | 
|  | 2480 | if (gt_bias) { | 
|  | 2481 | __ CmpLtS(FTMP, lhs, rhs); | 
|  | 2482 | } else { | 
|  | 2483 | __ CmpUltS(FTMP, lhs, rhs); | 
|  | 2484 | } | 
|  | 2485 | __ Bc1nez(FTMP, label); | 
|  | 2486 | break; | 
|  | 2487 | case kCondLE: | 
|  | 2488 | if (gt_bias) { | 
|  | 2489 | __ CmpLeS(FTMP, lhs, rhs); | 
|  | 2490 | } else { | 
|  | 2491 | __ CmpUleS(FTMP, lhs, rhs); | 
|  | 2492 | } | 
|  | 2493 | __ Bc1nez(FTMP, label); | 
|  | 2494 | break; | 
|  | 2495 | case kCondGT: | 
|  | 2496 | if (gt_bias) { | 
|  | 2497 | __ CmpUltS(FTMP, rhs, lhs); | 
|  | 2498 | } else { | 
|  | 2499 | __ CmpLtS(FTMP, rhs, lhs); | 
|  | 2500 | } | 
|  | 2501 | __ Bc1nez(FTMP, label); | 
|  | 2502 | break; | 
|  | 2503 | case kCondGE: | 
|  | 2504 | if (gt_bias) { | 
|  | 2505 | __ CmpUleS(FTMP, rhs, lhs); | 
|  | 2506 | } else { | 
|  | 2507 | __ CmpLeS(FTMP, rhs, lhs); | 
|  | 2508 | } | 
|  | 2509 | __ Bc1nez(FTMP, label); | 
|  | 2510 | break; | 
|  | 2511 | default: | 
|  | 2512 | LOG(FATAL) << "Unexpected non-floating-point condition"; | 
|  | 2513 | } | 
|  | 2514 | } else { | 
|  | 2515 | DCHECK_EQ(type, Primitive::kPrimDouble); | 
|  | 2516 | switch (cond) { | 
|  | 2517 | case kCondEQ: | 
|  | 2518 | __ CmpEqD(FTMP, lhs, rhs); | 
|  | 2519 | __ Bc1nez(FTMP, label); | 
|  | 2520 | break; | 
|  | 2521 | case kCondNE: | 
|  | 2522 | __ CmpEqD(FTMP, lhs, rhs); | 
|  | 2523 | __ Bc1eqz(FTMP, label); | 
|  | 2524 | break; | 
|  | 2525 | case kCondLT: | 
|  | 2526 | if (gt_bias) { | 
|  | 2527 | __ CmpLtD(FTMP, lhs, rhs); | 
|  | 2528 | } else { | 
|  | 2529 | __ CmpUltD(FTMP, lhs, rhs); | 
|  | 2530 | } | 
|  | 2531 | __ Bc1nez(FTMP, label); | 
|  | 2532 | break; | 
|  | 2533 | case kCondLE: | 
|  | 2534 | if (gt_bias) { | 
|  | 2535 | __ CmpLeD(FTMP, lhs, rhs); | 
|  | 2536 | } else { | 
|  | 2537 | __ CmpUleD(FTMP, lhs, rhs); | 
|  | 2538 | } | 
|  | 2539 | __ Bc1nez(FTMP, label); | 
|  | 2540 | break; | 
|  | 2541 | case kCondGT: | 
|  | 2542 | if (gt_bias) { | 
|  | 2543 | __ CmpUltD(FTMP, rhs, lhs); | 
|  | 2544 | } else { | 
|  | 2545 | __ CmpLtD(FTMP, rhs, lhs); | 
|  | 2546 | } | 
|  | 2547 | __ Bc1nez(FTMP, label); | 
|  | 2548 | break; | 
|  | 2549 | case kCondGE: | 
|  | 2550 | if (gt_bias) { | 
|  | 2551 | __ CmpUleD(FTMP, rhs, lhs); | 
|  | 2552 | } else { | 
|  | 2553 | __ CmpLeD(FTMP, rhs, lhs); | 
|  | 2554 | } | 
|  | 2555 | __ Bc1nez(FTMP, label); | 
|  | 2556 | break; | 
|  | 2557 | default: | 
|  | 2558 | LOG(FATAL) << "Unexpected non-floating-point condition"; | 
|  | 2559 | } | 
|  | 2560 | } | 
|  | 2561 | } | 
|  | 2562 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2563 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2564 | size_t condition_input_index, | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2565 | Mips64Label* true_target, | 
|  | 2566 | Mips64Label* false_target) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2567 | HInstruction* cond = instruction->InputAt(condition_input_index); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2568 |  | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2569 | if (true_target == nullptr && false_target == nullptr) { | 
|  | 2570 | // Nothing to do. The code always falls through. | 
|  | 2571 | return; | 
|  | 2572 | } else if (cond->IsIntConstant()) { | 
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2573 | // Constant condition, statically compared against "true" (integer value 1). | 
|  | 2574 | if (cond->AsIntConstant()->IsTrue()) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2575 | if (true_target != nullptr) { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2576 | __ Bc(true_target); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2577 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2578 | } else { | 
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2579 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2580 | if (false_target != nullptr) { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2581 | __ Bc(false_target); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2582 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2583 | } | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2584 | return; | 
|  | 2585 | } | 
|  | 2586 |  | 
|  | 2587 | // The following code generates these patterns: | 
|  | 2588 | //  (1) true_target == nullptr && false_target != nullptr | 
|  | 2589 | //        - opposite condition true => branch to false_target | 
|  | 2590 | //  (2) true_target != nullptr && false_target == nullptr | 
|  | 2591 | //        - condition true => branch to true_target | 
|  | 2592 | //  (3) true_target != nullptr && false_target != nullptr | 
|  | 2593 | //        - condition true => branch to true_target | 
|  | 2594 | //        - branch to false_target | 
|  | 2595 | if (IsBooleanValueOrMaterializedCondition(cond)) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2596 | // The condition instruction has been materialized, compare the output to 0. | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2597 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2598 | DCHECK(cond_val.IsRegister()); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2599 | if (true_target == nullptr) { | 
|  | 2600 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); | 
|  | 2601 | } else { | 
|  | 2602 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); | 
|  | 2603 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2604 | } else { | 
|  | 2605 | // The condition instruction has not been materialized, use its inputs as | 
|  | 2606 | // the comparison and its condition as the branch condition. | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2607 | HCondition* condition = cond->AsCondition(); | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2608 | Primitive::Type type = condition->InputAt(0)->GetType(); | 
|  | 2609 | LocationSummary* locations = cond->GetLocations(); | 
|  | 2610 | IfCondition if_cond = condition->GetCondition(); | 
|  | 2611 | Mips64Label* branch_target = true_target; | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2612 |  | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2613 | if (true_target == nullptr) { | 
|  | 2614 | if_cond = condition->GetOppositeCondition(); | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2615 | branch_target = false_target; | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2616 | } | 
|  | 2617 |  | 
| Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2618 | switch (type) { | 
|  | 2619 | default: | 
|  | 2620 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); | 
|  | 2621 | break; | 
|  | 2622 | case Primitive::kPrimLong: | 
|  | 2623 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); | 
|  | 2624 | break; | 
|  | 2625 | case Primitive::kPrimFloat: | 
|  | 2626 | case Primitive::kPrimDouble: | 
|  | 2627 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); | 
|  | 2628 | break; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2629 | } | 
|  | 2630 | } | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2631 |  | 
|  | 2632 | // If neither branch falls through (case 3), the conditional branch to `true_target` | 
|  | 2633 | // was already emitted (case 2) and we need to emit a jump to `false_target`. | 
|  | 2634 | if (true_target != nullptr && false_target != nullptr) { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2635 | __ Bc(false_target); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2636 | } | 
|  | 2637 | } | 
|  | 2638 |  | 
|  | 2639 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { | 
|  | 2640 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2641 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2642 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2643 | } | 
|  | 2644 | } | 
|  | 2645 |  | 
|  | 2646 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2647 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); | 
|  | 2648 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2649 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2650 | nullptr : codegen_->GetLabelOf(true_successor); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2651 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2652 | nullptr : codegen_->GetLabelOf(false_successor); | 
|  | 2653 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2654 | } | 
|  | 2655 |  | 
|  | 2656 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { | 
|  | 2657 | LocationSummary* locations = new (GetGraph()->GetArena()) | 
|  | 2658 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2659 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2660 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2661 | } | 
|  | 2662 | } | 
|  | 2663 |  | 
|  | 2664 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2665 | SlowPathCodeMIPS64* slow_path = | 
|  | 2666 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2667 | GenerateTestAndBranch(deoptimize, | 
|  | 2668 | /* condition_input_index */ 0, | 
|  | 2669 | slow_path->GetEntryLabel(), | 
|  | 2670 | /* false_target */ nullptr); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2671 | } | 
|  | 2672 |  | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2673 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { | 
|  | 2674 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); | 
|  | 2675 | if (Primitive::IsFloatingPointType(select->GetType())) { | 
|  | 2676 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2677 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 2678 | } else { | 
|  | 2679 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2680 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 2681 | } | 
|  | 2682 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { | 
|  | 2683 | locations->SetInAt(2, Location::RequiresRegister()); | 
|  | 2684 | } | 
|  | 2685 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2686 | } | 
|  | 2687 |  | 
|  | 2688 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { | 
|  | 2689 | LocationSummary* locations = select->GetLocations(); | 
|  | 2690 | Mips64Label false_target; | 
|  | 2691 | GenerateTestAndBranch(select, | 
|  | 2692 | /* condition_input_index */ 2, | 
|  | 2693 | /* true_target */ nullptr, | 
|  | 2694 | &false_target); | 
|  | 2695 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); | 
|  | 2696 | __ Bind(&false_target); | 
|  | 2697 | } | 
|  | 2698 |  | 
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2699 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { | 
|  | 2700 | new (GetGraph()->GetArena()) LocationSummary(info); | 
|  | 2701 | } | 
|  | 2702 |  | 
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2703 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { | 
|  | 2704 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. | 
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2705 | } | 
|  | 2706 |  | 
|  | 2707 | void CodeGeneratorMIPS64::GenerateNop() { | 
|  | 2708 | __ Nop(); | 
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2709 | } | 
|  | 2710 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2711 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, | 
|  | 2712 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { | 
|  | 2713 | LocationSummary* locations = | 
|  | 2714 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 2715 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2716 | if (Primitive::IsFloatingPointType(instruction->GetType())) { | 
|  | 2717 | locations->SetOut(Location::RequiresFpuRegister()); | 
|  | 2718 | } else { | 
|  | 2719 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 2720 | } | 
|  | 2721 | } | 
|  | 2722 |  | 
|  | 2723 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, | 
|  | 2724 | const FieldInfo& field_info) { | 
|  | 2725 | Primitive::Type type = field_info.GetFieldType(); | 
|  | 2726 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2727 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 2728 | LoadOperandType load_type = kLoadUnsignedByte; | 
|  | 2729 | switch (type) { | 
|  | 2730 | case Primitive::kPrimBoolean: | 
|  | 2731 | load_type = kLoadUnsignedByte; | 
|  | 2732 | break; | 
|  | 2733 | case Primitive::kPrimByte: | 
|  | 2734 | load_type = kLoadSignedByte; | 
|  | 2735 | break; | 
|  | 2736 | case Primitive::kPrimShort: | 
|  | 2737 | load_type = kLoadSignedHalfword; | 
|  | 2738 | break; | 
|  | 2739 | case Primitive::kPrimChar: | 
|  | 2740 | load_type = kLoadUnsignedHalfword; | 
|  | 2741 | break; | 
|  | 2742 | case Primitive::kPrimInt: | 
|  | 2743 | case Primitive::kPrimFloat: | 
|  | 2744 | load_type = kLoadWord; | 
|  | 2745 | break; | 
|  | 2746 | case Primitive::kPrimLong: | 
|  | 2747 | case Primitive::kPrimDouble: | 
|  | 2748 | load_type = kLoadDoubleword; | 
|  | 2749 | break; | 
|  | 2750 | case Primitive::kPrimNot: | 
|  | 2751 | load_type = kLoadUnsignedWord; | 
|  | 2752 | break; | 
|  | 2753 | case Primitive::kPrimVoid: | 
|  | 2754 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 2755 | UNREACHABLE(); | 
|  | 2756 | } | 
|  | 2757 | if (!Primitive::IsFloatingPointType(type)) { | 
|  | 2758 | DCHECK(locations->Out().IsRegister()); | 
|  | 2759 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
|  | 2760 | __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value()); | 
|  | 2761 | } else { | 
|  | 2762 | DCHECK(locations->Out().IsFpuRegister()); | 
|  | 2763 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); | 
|  | 2764 | __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value()); | 
|  | 2765 | } | 
|  | 2766 |  | 
|  | 2767 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 2768 | // TODO: memory barrier? | 
|  | 2769 | } | 
|  | 2770 |  | 
|  | 2771 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, | 
|  | 2772 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { | 
|  | 2773 | LocationSummary* locations = | 
|  | 2774 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 2775 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2776 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { | 
|  | 2777 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 2778 | } else { | 
|  | 2779 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 2780 | } | 
|  | 2781 | } | 
|  | 2782 |  | 
|  | 2783 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, | 
| Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 2784 | const FieldInfo& field_info, | 
|  | 2785 | bool value_can_be_null) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2786 | Primitive::Type type = field_info.GetFieldType(); | 
|  | 2787 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2788 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 2789 | StoreOperandType store_type = kStoreByte; | 
|  | 2790 | switch (type) { | 
|  | 2791 | case Primitive::kPrimBoolean: | 
|  | 2792 | case Primitive::kPrimByte: | 
|  | 2793 | store_type = kStoreByte; | 
|  | 2794 | break; | 
|  | 2795 | case Primitive::kPrimShort: | 
|  | 2796 | case Primitive::kPrimChar: | 
|  | 2797 | store_type = kStoreHalfword; | 
|  | 2798 | break; | 
|  | 2799 | case Primitive::kPrimInt: | 
|  | 2800 | case Primitive::kPrimFloat: | 
|  | 2801 | case Primitive::kPrimNot: | 
|  | 2802 | store_type = kStoreWord; | 
|  | 2803 | break; | 
|  | 2804 | case Primitive::kPrimLong: | 
|  | 2805 | case Primitive::kPrimDouble: | 
|  | 2806 | store_type = kStoreDoubleword; | 
|  | 2807 | break; | 
|  | 2808 | case Primitive::kPrimVoid: | 
|  | 2809 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 2810 | UNREACHABLE(); | 
|  | 2811 | } | 
|  | 2812 | if (!Primitive::IsFloatingPointType(type)) { | 
|  | 2813 | DCHECK(locations->InAt(1).IsRegister()); | 
|  | 2814 | GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>(); | 
|  | 2815 | __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value()); | 
|  | 2816 | } else { | 
|  | 2817 | DCHECK(locations->InAt(1).IsFpuRegister()); | 
|  | 2818 | FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>(); | 
|  | 2819 | __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value()); | 
|  | 2820 | } | 
|  | 2821 |  | 
|  | 2822 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 2823 | // TODO: memory barriers? | 
|  | 2824 | if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) { | 
|  | 2825 | DCHECK(locations->InAt(1).IsRegister()); | 
|  | 2826 | GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>(); | 
| Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 2827 | codegen_->MarkGCCard(obj, src, value_can_be_null); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2828 | } | 
|  | 2829 | } | 
|  | 2830 |  | 
|  | 2831 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
|  | 2832 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
|  | 2833 | } | 
|  | 2834 |  | 
|  | 2835 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
|  | 2836 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
|  | 2837 | } | 
|  | 2838 |  | 
|  | 2839 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
|  | 2840 | HandleFieldSet(instruction, instruction->GetFieldInfo()); | 
|  | 2841 | } | 
|  | 2842 |  | 
|  | 2843 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
| Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 2844 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2845 | } | 
|  | 2846 |  | 
|  | 2847 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { | 
|  | 2848 | LocationSummary::CallKind call_kind = | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2849 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2850 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
|  | 2851 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2852 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 2853 | // The output does overlap inputs. | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2854 | // Note that TypeCheckSlowPathMIPS64 uses this register too. | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2855 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); | 
|  | 2856 | } | 
|  | 2857 |  | 
|  | 2858 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { | 
|  | 2859 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2860 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 2861 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); | 
|  | 2862 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 2863 |  | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2864 | Mips64Label done; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2865 |  | 
|  | 2866 | // Return 0 if `obj` is null. | 
|  | 2867 | // TODO: Avoid this check if we know `obj` is not null. | 
|  | 2868 | __ Move(out, ZERO); | 
|  | 2869 | __ Beqzc(obj, &done); | 
|  | 2870 |  | 
|  | 2871 | // Compare the class of `obj` with `cls`. | 
|  | 2872 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2873 | if (instruction->IsExactCheck()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2874 | // Classes must be equal for the instanceof to succeed. | 
|  | 2875 | __ Xor(out, out, cls); | 
|  | 2876 | __ Sltiu(out, out, 1); | 
|  | 2877 | } else { | 
|  | 2878 | // If the classes are not equal, we go into a slow path. | 
|  | 2879 | DCHECK(locations->OnlyCallsOnSlowPath()); | 
|  | 2880 | SlowPathCodeMIPS64* slow_path = | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2881 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2882 | codegen_->AddSlowPath(slow_path); | 
|  | 2883 | __ Bnec(out, cls, slow_path->GetEntryLabel()); | 
|  | 2884 | __ LoadConst32(out, 1); | 
|  | 2885 | __ Bind(slow_path->GetExitLabel()); | 
|  | 2886 | } | 
|  | 2887 |  | 
|  | 2888 | __ Bind(&done); | 
|  | 2889 | } | 
|  | 2890 |  | 
|  | 2891 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { | 
|  | 2892 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); | 
|  | 2893 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2894 | } | 
|  | 2895 |  | 
|  | 2896 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { | 
|  | 2897 | // Will be generated at use site. | 
|  | 2898 | } | 
|  | 2899 |  | 
|  | 2900 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { | 
|  | 2901 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); | 
|  | 2902 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2903 | } | 
|  | 2904 |  | 
|  | 2905 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { | 
|  | 2906 | // Will be generated at use site. | 
|  | 2907 | } | 
|  | 2908 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2909 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
|  | 2910 | // The trampoline uses the same calling convention as dex calling conventions, | 
|  | 2911 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain | 
|  | 2912 | // the method_idx. | 
|  | 2913 | HandleInvoke(invoke); | 
|  | 2914 | } | 
|  | 2915 |  | 
|  | 2916 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
|  | 2917 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); | 
|  | 2918 | } | 
|  | 2919 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2920 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { | 
|  | 2921 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; | 
|  | 2922 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); | 
|  | 2923 | } | 
|  | 2924 |  | 
|  | 2925 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { | 
|  | 2926 | HandleInvoke(invoke); | 
|  | 2927 | // The register T0 is required to be used for the hidden argument in | 
|  | 2928 | // art_quick_imt_conflict_trampoline, so add the hidden argument. | 
|  | 2929 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); | 
|  | 2930 | } | 
|  | 2931 |  | 
|  | 2932 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { | 
|  | 2933 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. | 
|  | 2934 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); | 
| Nicolas Geoffray | 88f288e | 2016-06-29 08:17:52 +0000 | [diff] [blame] | 2935 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( | 
|  | 2936 | invoke->GetImtIndex() % mirror::Class::kImtSize, kMips64PointerSize).Uint32Value(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2937 | Location receiver = invoke->GetLocations()->InAt(0); | 
|  | 2938 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 2939 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64DoublewordSize); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2940 |  | 
|  | 2941 | // Set the hidden argument. | 
|  | 2942 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), | 
|  | 2943 | invoke->GetDexMethodIndex()); | 
|  | 2944 |  | 
|  | 2945 | // temp = object->GetClass(); | 
|  | 2946 | if (receiver.IsStackSlot()) { | 
|  | 2947 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); | 
|  | 2948 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); | 
|  | 2949 | } else { | 
|  | 2950 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); | 
|  | 2951 | } | 
|  | 2952 | codegen_->MaybeRecordImplicitNullCheck(invoke); | 
|  | 2953 | // temp = temp->GetImtEntryAt(method_offset); | 
|  | 2954 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); | 
|  | 2955 | // T9 = temp->GetEntryPoint(); | 
|  | 2956 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); | 
|  | 2957 | // T9(); | 
|  | 2958 | __ Jalr(T9); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2959 | __ Nop(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2960 | DCHECK(!codegen_->IsLeafMethod()); | 
|  | 2961 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
|  | 2962 | } | 
|  | 2963 |  | 
|  | 2964 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
| Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2965 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); | 
|  | 2966 | if (intrinsic.TryDispatch(invoke)) { | 
|  | 2967 | return; | 
|  | 2968 | } | 
|  | 2969 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2970 | HandleInvoke(invoke); | 
|  | 2971 | } | 
|  | 2972 |  | 
|  | 2973 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2974 | // Explicit clinit checks triggered by static invokes must have been pruned by | 
|  | 2975 | // art::PrepareForRegisterAllocation. | 
|  | 2976 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2977 |  | 
| Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2978 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); | 
|  | 2979 | if (intrinsic.TryDispatch(invoke)) { | 
|  | 2980 | return; | 
|  | 2981 | } | 
|  | 2982 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2983 | HandleInvoke(invoke); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2984 | } | 
|  | 2985 |  | 
| Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2986 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2987 | if (invoke->GetLocations()->Intrinsified()) { | 
| Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2988 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); | 
|  | 2989 | intrinsic.Dispatch(invoke); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2990 | return true; | 
|  | 2991 | } | 
|  | 2992 | return false; | 
|  | 2993 | } | 
|  | 2994 |  | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2995 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( | 
|  | 2996 | HLoadString::LoadKind desired_string_load_kind ATTRIBUTE_UNUSED) { | 
|  | 2997 | // TODO: Implement other kinds. | 
|  | 2998 | return HLoadString::LoadKind::kDexCacheViaMethod; | 
|  | 2999 | } | 
|  | 3000 |  | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3001 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( | 
|  | 3002 | HLoadClass::LoadKind desired_class_load_kind) { | 
|  | 3003 | DCHECK_NE(desired_class_load_kind, HLoadClass::LoadKind::kReferrersClass); | 
|  | 3004 | // TODO: Implement other kinds. | 
|  | 3005 | return HLoadClass::LoadKind::kDexCacheViaMethod; | 
|  | 3006 | } | 
|  | 3007 |  | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3008 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( | 
|  | 3009 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, | 
|  | 3010 | MethodReference target_method ATTRIBUTE_UNUSED) { | 
|  | 3011 | switch (desired_dispatch_info.method_load_kind) { | 
|  | 3012 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: | 
|  | 3013 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: | 
|  | 3014 | // TODO: Implement these types. For the moment, we fall back to kDexCacheViaMethod. | 
|  | 3015 | return HInvokeStaticOrDirect::DispatchInfo { | 
|  | 3016 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, | 
|  | 3017 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, | 
|  | 3018 | 0u, | 
|  | 3019 | 0u | 
|  | 3020 | }; | 
|  | 3021 | default: | 
|  | 3022 | break; | 
|  | 3023 | } | 
|  | 3024 | switch (desired_dispatch_info.code_ptr_location) { | 
|  | 3025 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: | 
|  | 3026 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: | 
|  | 3027 | // TODO: Implement these types. For the moment, we fall back to kCallArtMethod. | 
|  | 3028 | return HInvokeStaticOrDirect::DispatchInfo { | 
|  | 3029 | desired_dispatch_info.method_load_kind, | 
|  | 3030 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, | 
|  | 3031 | desired_dispatch_info.method_load_data, | 
|  | 3032 | 0u | 
|  | 3033 | }; | 
|  | 3034 | default: | 
|  | 3035 | return desired_dispatch_info; | 
|  | 3036 | } | 
|  | 3037 | } | 
|  | 3038 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3039 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { | 
|  | 3040 | // All registers are assumed to be correctly set up per the calling convention. | 
|  | 3041 |  | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3042 | Location callee_method = temp;  // For all kinds except kRecursive, callee will be in temp. | 
|  | 3043 | switch (invoke->GetMethodLoadKind()) { | 
|  | 3044 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: | 
|  | 3045 | // temp = thread->string_init_entrypoint | 
|  | 3046 | __ LoadFromOffset(kLoadDoubleword, | 
|  | 3047 | temp.AsRegister<GpuRegister>(), | 
|  | 3048 | TR, | 
|  | 3049 | invoke->GetStringInitOffset()); | 
|  | 3050 | break; | 
|  | 3051 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3052 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3053 | break; | 
|  | 3054 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: | 
|  | 3055 | __ LoadConst64(temp.AsRegister<GpuRegister>(), invoke->GetMethodAddress()); | 
|  | 3056 | break; | 
|  | 3057 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3058 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3059 | // TODO: Implement these types. | 
|  | 3060 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). | 
|  | 3061 | LOG(FATAL) << "Unsupported"; | 
|  | 3062 | UNREACHABLE(); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3063 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3064 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3065 | GpuRegister reg = temp.AsRegister<GpuRegister>(); | 
|  | 3066 | GpuRegister method_reg; | 
|  | 3067 | if (current_method.IsRegister()) { | 
|  | 3068 | method_reg = current_method.AsRegister<GpuRegister>(); | 
|  | 3069 | } else { | 
|  | 3070 | // TODO: use the appropriate DCHECK() here if possible. | 
|  | 3071 | // DCHECK(invoke->GetLocations()->Intrinsified()); | 
|  | 3072 | DCHECK(!current_method.IsValid()); | 
|  | 3073 | method_reg = reg; | 
|  | 3074 | __ Ld(reg, SP, kCurrentMethodStackOffset); | 
|  | 3075 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3076 |  | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3077 | // temp = temp->dex_cache_resolved_methods_; | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3078 | __ LoadFromOffset(kLoadDoubleword, | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3079 | reg, | 
|  | 3080 | method_reg, | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3081 | ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value()); | 
| Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 3082 | // temp = temp[index_in_cache]; | 
|  | 3083 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. | 
|  | 3084 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3085 | __ LoadFromOffset(kLoadDoubleword, | 
|  | 3086 | reg, | 
|  | 3087 | reg, | 
|  | 3088 | CodeGenerator::GetCachePointerOffset(index_in_cache)); | 
|  | 3089 | break; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3090 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3091 | } | 
|  | 3092 |  | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3093 | switch (invoke->GetCodePtrLocation()) { | 
|  | 3094 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3095 | __ Jialc(&frame_entry_label_, T9); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3096 | break; | 
|  | 3097 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: | 
|  | 3098 | // LR = invoke->GetDirectCodePtr(); | 
|  | 3099 | __ LoadConst64(T9, invoke->GetDirectCodePtr()); | 
|  | 3100 | // LR() | 
|  | 3101 | __ Jalr(T9); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3102 | __ Nop(); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3103 | break; | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3104 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3105 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: | 
|  | 3106 | // TODO: Implement these types. | 
|  | 3107 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). | 
|  | 3108 | LOG(FATAL) << "Unsupported"; | 
|  | 3109 | UNREACHABLE(); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3110 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: | 
|  | 3111 | // T9 = callee_method->entry_point_from_quick_compiled_code_; | 
|  | 3112 | __ LoadFromOffset(kLoadDoubleword, | 
|  | 3113 | T9, | 
|  | 3114 | callee_method.AsRegister<GpuRegister>(), | 
|  | 3115 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 3116 | kMips64DoublewordSize).Int32Value()); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3117 | // T9() | 
|  | 3118 | __ Jalr(T9); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3119 | __ Nop(); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3120 | break; | 
|  | 3121 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3122 | DCHECK(!IsLeafMethod()); | 
|  | 3123 | } | 
|  | 3124 |  | 
|  | 3125 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3126 | // Explicit clinit checks triggered by static invokes must have been pruned by | 
|  | 3127 | // art::PrepareForRegisterAllocation. | 
|  | 3128 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3129 |  | 
|  | 3130 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
|  | 3131 | return; | 
|  | 3132 | } | 
|  | 3133 |  | 
|  | 3134 | LocationSummary* locations = invoke->GetLocations(); | 
|  | 3135 | codegen_->GenerateStaticOrDirectCall(invoke, | 
|  | 3136 | locations->HasTemps() | 
|  | 3137 | ? locations->GetTemp(0) | 
|  | 3138 | : Location::NoLocation()); | 
|  | 3139 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
|  | 3140 | } | 
|  | 3141 |  | 
| Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 3142 | void CodeGeneratorMIPS64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { | 
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3143 | // Use the calling convention instead of the location of the receiver, as | 
|  | 3144 | // intrinsics may have put the receiver in a different register. In the intrinsics | 
|  | 3145 | // slow path, the arguments have been moved to the right place, so here we are | 
|  | 3146 | // guaranteed that the receiver is the first register of the calling convention. | 
|  | 3147 | InvokeDexCallingConvention calling_convention; | 
|  | 3148 | GpuRegister receiver = calling_convention.GetRegisterAt(0); | 
|  | 3149 |  | 
| Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 3150 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3151 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( | 
|  | 3152 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); | 
|  | 3153 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 3154 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64DoublewordSize); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3155 |  | 
|  | 3156 | // temp = object->GetClass(); | 
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3157 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); | 
| Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 3158 | MaybeRecordImplicitNullCheck(invoke); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3159 | // temp = temp->GetMethodAt(method_offset); | 
|  | 3160 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); | 
|  | 3161 | // T9 = temp->GetEntryPoint(); | 
|  | 3162 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); | 
|  | 3163 | // T9(); | 
|  | 3164 | __ Jalr(T9); | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3165 | __ Nop(); | 
| Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 3166 | } | 
|  | 3167 |  | 
|  | 3168 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
|  | 3169 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
|  | 3170 | return; | 
|  | 3171 | } | 
|  | 3172 |  | 
|  | 3173 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3174 | DCHECK(!codegen_->IsLeafMethod()); | 
|  | 3175 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
|  | 3176 | } | 
|  | 3177 |  | 
|  | 3178 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { | 
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3179 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3180 | CodeGenerator::CreateLoadClassLocationSummary( | 
|  | 3181 | cls, | 
|  | 3182 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
| Alexey Frunze | 00580bd | 2015-11-11 13:31:12 -0800 | [diff] [blame] | 3183 | calling_convention.GetReturnLocation(cls->GetType())); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3184 | } | 
|  | 3185 |  | 
|  | 3186 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) { | 
|  | 3187 | LocationSummary* locations = cls->GetLocations(); | 
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3188 | if (cls->NeedsAccessCheck()) { | 
|  | 3189 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); | 
|  | 3190 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), | 
|  | 3191 | cls, | 
|  | 3192 | cls->GetDexPc(), | 
|  | 3193 | nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3194 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); | 
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 3195 | return; | 
|  | 3196 | } | 
|  | 3197 |  | 
|  | 3198 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 3199 | GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 3200 | if (cls->IsReferrersClass()) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3201 | DCHECK(!cls->CanCallRuntime()); | 
|  | 3202 | DCHECK(!cls->MustGenerateClinitCheck()); | 
|  | 3203 | __ LoadFromOffset(kLoadUnsignedWord, out, current_method, | 
|  | 3204 | ArtMethod::DeclaringClassOffset().Int32Value()); | 
|  | 3205 | } else { | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3206 | __ LoadFromOffset(kLoadDoubleword, out, current_method, | 
|  | 3207 | ArtMethod::DexCacheResolvedTypesOffset(kMips64PointerSize).Int32Value()); | 
| Roland Levillain | 698fa97 | 2015-12-16 17:06:47 +0000 | [diff] [blame] | 3208 | __ LoadFromOffset( | 
|  | 3209 | kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3210 | // TODO: We will need a read barrier here. | 
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 3211 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { | 
|  | 3212 | DCHECK(cls->CanCallRuntime()); | 
|  | 3213 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( | 
|  | 3214 | cls, | 
|  | 3215 | cls, | 
|  | 3216 | cls->GetDexPc(), | 
|  | 3217 | cls->MustGenerateClinitCheck()); | 
|  | 3218 | codegen_->AddSlowPath(slow_path); | 
|  | 3219 | if (!cls->IsInDexCache()) { | 
|  | 3220 | __ Beqzc(out, slow_path->GetEntryLabel()); | 
|  | 3221 | } | 
|  | 3222 | if (cls->MustGenerateClinitCheck()) { | 
|  | 3223 | GenerateClassInitializationCheck(slow_path, out); | 
|  | 3224 | } else { | 
|  | 3225 | __ Bind(slow_path->GetExitLabel()); | 
|  | 3226 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3227 | } | 
|  | 3228 | } | 
|  | 3229 | } | 
|  | 3230 |  | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3231 | static int32_t GetExceptionTlsOffset() { | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 3232 | return Thread::ExceptionOffset<kMips64DoublewordSize>().Int32Value(); | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3233 | } | 
|  | 3234 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3235 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { | 
|  | 3236 | LocationSummary* locations = | 
|  | 3237 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); | 
|  | 3238 | locations->SetOut(Location::RequiresRegister()); | 
|  | 3239 | } | 
|  | 3240 |  | 
|  | 3241 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { | 
|  | 3242 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3243 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); | 
|  | 3244 | } | 
|  | 3245 |  | 
|  | 3246 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { | 
|  | 3247 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); | 
|  | 3248 | } | 
|  | 3249 |  | 
|  | 3250 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { | 
|  | 3251 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3252 | } | 
|  | 3253 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3254 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3255 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() | 
|  | 3256 | ? LocationSummary::kCallOnSlowPath | 
|  | 3257 | : LocationSummary::kNoCall; | 
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 3258 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3259 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3260 | locations->SetOut(Location::RequiresRegister()); | 
|  | 3261 | } | 
|  | 3262 |  | 
|  | 3263 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3264 | LocationSummary* locations = load->GetLocations(); | 
|  | 3265 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); | 
|  | 3266 | GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 3267 | __ LoadFromOffset(kLoadUnsignedWord, out, current_method, | 
|  | 3268 | ArtMethod::DeclaringClassOffset().Int32Value()); | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3269 | __ LoadFromOffset(kLoadDoubleword, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); | 
| Roland Levillain | 698fa97 | 2015-12-16 17:06:47 +0000 | [diff] [blame] | 3270 | __ LoadFromOffset( | 
|  | 3271 | kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3272 | // TODO: We will need a read barrier here. | 
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 3273 |  | 
|  | 3274 | if (!load->IsInDexCache()) { | 
|  | 3275 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load); | 
|  | 3276 | codegen_->AddSlowPath(slow_path); | 
|  | 3277 | __ Beqzc(out, slow_path->GetEntryLabel()); | 
|  | 3278 | __ Bind(slow_path->GetExitLabel()); | 
|  | 3279 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3280 | } | 
|  | 3281 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3282 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { | 
|  | 3283 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); | 
|  | 3284 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 3285 | } | 
|  | 3286 |  | 
|  | 3287 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { | 
|  | 3288 | // Will be generated at use site. | 
|  | 3289 | } | 
|  | 3290 |  | 
|  | 3291 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { | 
|  | 3292 | LocationSummary* locations = | 
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame^] | 3293 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3294 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3295 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 3296 | } | 
|  | 3297 |  | 
|  | 3298 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { | 
|  | 3299 | codegen_->InvokeRuntime(instruction->IsEnter() | 
|  | 3300 | ? QUICK_ENTRY_POINT(pLockObject) | 
|  | 3301 | : QUICK_ENTRY_POINT(pUnlockObject), | 
|  | 3302 | instruction, | 
|  | 3303 | instruction->GetDexPc(), | 
|  | 3304 | nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3305 | if (instruction->IsEnter()) { | 
|  | 3306 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); | 
|  | 3307 | } else { | 
|  | 3308 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); | 
|  | 3309 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3310 | } | 
|  | 3311 |  | 
|  | 3312 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { | 
|  | 3313 | LocationSummary* locations = | 
|  | 3314 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); | 
|  | 3315 | switch (mul->GetResultType()) { | 
|  | 3316 | case Primitive::kPrimInt: | 
|  | 3317 | case Primitive::kPrimLong: | 
|  | 3318 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3319 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 3320 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3321 | break; | 
|  | 3322 |  | 
|  | 3323 | case Primitive::kPrimFloat: | 
|  | 3324 | case Primitive::kPrimDouble: | 
|  | 3325 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 3326 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 3327 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 3328 | break; | 
|  | 3329 |  | 
|  | 3330 | default: | 
|  | 3331 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); | 
|  | 3332 | } | 
|  | 3333 | } | 
|  | 3334 |  | 
|  | 3335 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { | 
|  | 3336 | Primitive::Type type = instruction->GetType(); | 
|  | 3337 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3338 |  | 
|  | 3339 | switch (type) { | 
|  | 3340 | case Primitive::kPrimInt: | 
|  | 3341 | case Primitive::kPrimLong: { | 
|  | 3342 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
|  | 3343 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 3344 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); | 
|  | 3345 | if (type == Primitive::kPrimInt) | 
|  | 3346 | __ MulR6(dst, lhs, rhs); | 
|  | 3347 | else | 
|  | 3348 | __ Dmul(dst, lhs, rhs); | 
|  | 3349 | break; | 
|  | 3350 | } | 
|  | 3351 | case Primitive::kPrimFloat: | 
|  | 3352 | case Primitive::kPrimDouble: { | 
|  | 3353 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); | 
|  | 3354 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); | 
|  | 3355 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); | 
|  | 3356 | if (type == Primitive::kPrimFloat) | 
|  | 3357 | __ MulS(dst, lhs, rhs); | 
|  | 3358 | else | 
|  | 3359 | __ MulD(dst, lhs, rhs); | 
|  | 3360 | break; | 
|  | 3361 | } | 
|  | 3362 | default: | 
|  | 3363 | LOG(FATAL) << "Unexpected mul type " << type; | 
|  | 3364 | } | 
|  | 3365 | } | 
|  | 3366 |  | 
|  | 3367 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { | 
|  | 3368 | LocationSummary* locations = | 
|  | 3369 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); | 
|  | 3370 | switch (neg->GetResultType()) { | 
|  | 3371 | case Primitive::kPrimInt: | 
|  | 3372 | case Primitive::kPrimLong: | 
|  | 3373 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3374 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3375 | break; | 
|  | 3376 |  | 
|  | 3377 | case Primitive::kPrimFloat: | 
|  | 3378 | case Primitive::kPrimDouble: | 
|  | 3379 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 3380 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 3381 | break; | 
|  | 3382 |  | 
|  | 3383 | default: | 
|  | 3384 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); | 
|  | 3385 | } | 
|  | 3386 | } | 
|  | 3387 |  | 
|  | 3388 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { | 
|  | 3389 | Primitive::Type type = instruction->GetType(); | 
|  | 3390 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3391 |  | 
|  | 3392 | switch (type) { | 
|  | 3393 | case Primitive::kPrimInt: | 
|  | 3394 | case Primitive::kPrimLong: { | 
|  | 3395 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
|  | 3396 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 3397 | if (type == Primitive::kPrimInt) | 
|  | 3398 | __ Subu(dst, ZERO, src); | 
|  | 3399 | else | 
|  | 3400 | __ Dsubu(dst, ZERO, src); | 
|  | 3401 | break; | 
|  | 3402 | } | 
|  | 3403 | case Primitive::kPrimFloat: | 
|  | 3404 | case Primitive::kPrimDouble: { | 
|  | 3405 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); | 
|  | 3406 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); | 
|  | 3407 | if (type == Primitive::kPrimFloat) | 
|  | 3408 | __ NegS(dst, src); | 
|  | 3409 | else | 
|  | 3410 | __ NegD(dst, src); | 
|  | 3411 | break; | 
|  | 3412 | } | 
|  | 3413 | default: | 
|  | 3414 | LOG(FATAL) << "Unexpected neg type " << type; | 
|  | 3415 | } | 
|  | 3416 | } | 
|  | 3417 |  | 
|  | 3418 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { | 
|  | 3419 | LocationSummary* locations = | 
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame^] | 3420 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3421 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3422 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 3423 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); | 
|  | 3424 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
|  | 3425 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); | 
|  | 3426 | } | 
|  | 3427 |  | 
|  | 3428 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { | 
|  | 3429 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3430 | // Move an uint16_t value to a register. | 
|  | 3431 | __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex()); | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3432 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), | 
|  | 3433 | instruction, | 
|  | 3434 | instruction->GetDexPc(), | 
|  | 3435 | nullptr); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3436 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); | 
|  | 3437 | } | 
|  | 3438 |  | 
|  | 3439 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { | 
|  | 3440 | LocationSummary* locations = | 
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame^] | 3441 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3442 | InvokeRuntimeCallingConvention calling_convention; | 
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3443 | if (instruction->IsStringAlloc()) { | 
|  | 3444 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); | 
|  | 3445 | } else { | 
|  | 3446 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 3447 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
|  | 3448 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3449 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); | 
|  | 3450 | } | 
|  | 3451 |  | 
|  | 3452 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { | 
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3453 | if (instruction->IsStringAlloc()) { | 
|  | 3454 | // String is allocated through StringFactory. Call NewEmptyString entry point. | 
|  | 3455 | GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); | 
| Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 3456 | MemberOffset code_offset = | 
|  | 3457 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64DoublewordSize); | 
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3458 | __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); | 
|  | 3459 | __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value()); | 
|  | 3460 | __ Jalr(T9); | 
|  | 3461 | __ Nop(); | 
|  | 3462 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); | 
|  | 3463 | } else { | 
|  | 3464 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), | 
|  | 3465 | instruction, | 
|  | 3466 | instruction->GetDexPc(), | 
|  | 3467 | nullptr); | 
|  | 3468 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); | 
|  | 3469 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3470 | } | 
|  | 3471 |  | 
|  | 3472 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { | 
|  | 3473 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 3474 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3475 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3476 | } | 
|  | 3477 |  | 
|  | 3478 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { | 
|  | 3479 | Primitive::Type type = instruction->GetType(); | 
|  | 3480 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3481 |  | 
|  | 3482 | switch (type) { | 
|  | 3483 | case Primitive::kPrimInt: | 
|  | 3484 | case Primitive::kPrimLong: { | 
|  | 3485 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
|  | 3486 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 3487 | __ Nor(dst, src, ZERO); | 
|  | 3488 | break; | 
|  | 3489 | } | 
|  | 3490 |  | 
|  | 3491 | default: | 
|  | 3492 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); | 
|  | 3493 | } | 
|  | 3494 | } | 
|  | 3495 |  | 
|  | 3496 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { | 
|  | 3497 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 3498 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3499 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3500 | } | 
|  | 3501 |  | 
|  | 3502 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { | 
|  | 3503 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3504 | __ Xori(locations->Out().AsRegister<GpuRegister>(), | 
|  | 3505 | locations->InAt(0).AsRegister<GpuRegister>(), | 
|  | 3506 | 1); | 
|  | 3507 | } | 
|  | 3508 |  | 
|  | 3509 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3510 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
|  | 3511 | ? LocationSummary::kCallOnSlowPath | 
|  | 3512 | : LocationSummary::kNoCall; | 
|  | 3513 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3514 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3515 | if (instruction->HasUses()) { | 
|  | 3516 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3517 | } | 
|  | 3518 | } | 
|  | 3519 |  | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3520 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { | 
|  | 3521 | if (CanMoveNullCheckToUser(instruction)) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3522 | return; | 
|  | 3523 | } | 
|  | 3524 | Location obj = instruction->GetLocations()->InAt(0); | 
|  | 3525 |  | 
|  | 3526 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3527 | RecordPcInfo(instruction, instruction->GetDexPc()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3528 | } | 
|  | 3529 |  | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3530 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3531 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction); | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3532 | AddSlowPath(slow_path); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3533 |  | 
|  | 3534 | Location obj = instruction->GetLocations()->InAt(0); | 
|  | 3535 |  | 
|  | 3536 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); | 
|  | 3537 | } | 
|  | 3538 |  | 
|  | 3539 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3540 | codegen_->GenerateNullCheck(instruction); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3541 | } | 
|  | 3542 |  | 
|  | 3543 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { | 
|  | 3544 | HandleBinaryOp(instruction); | 
|  | 3545 | } | 
|  | 3546 |  | 
|  | 3547 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { | 
|  | 3548 | HandleBinaryOp(instruction); | 
|  | 3549 | } | 
|  | 3550 |  | 
|  | 3551 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { | 
|  | 3552 | LOG(FATAL) << "Unreachable"; | 
|  | 3553 | } | 
|  | 3554 |  | 
|  | 3555 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { | 
|  | 3556 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); | 
|  | 3557 | } | 
|  | 3558 |  | 
|  | 3559 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { | 
|  | 3560 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 3561 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); | 
|  | 3562 | if (location.IsStackSlot()) { | 
|  | 3563 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
|  | 3564 | } else if (location.IsDoubleStackSlot()) { | 
|  | 3565 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
|  | 3566 | } | 
|  | 3567 | locations->SetOut(location); | 
|  | 3568 | } | 
|  | 3569 |  | 
|  | 3570 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction | 
|  | 3571 | ATTRIBUTE_UNUSED) { | 
|  | 3572 | // Nothing to do, the parameter is already at its location. | 
|  | 3573 | } | 
|  | 3574 |  | 
|  | 3575 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { | 
|  | 3576 | LocationSummary* locations = | 
|  | 3577 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 3578 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); | 
|  | 3579 | } | 
|  | 3580 |  | 
|  | 3581 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction | 
|  | 3582 | ATTRIBUTE_UNUSED) { | 
|  | 3583 | // Nothing to do, the method is already at its location. | 
|  | 3584 | } | 
|  | 3585 |  | 
|  | 3586 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { | 
|  | 3587 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3588 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3589 | locations->SetInAt(i, Location::Any()); | 
|  | 3590 | } | 
|  | 3591 | locations->SetOut(Location::Any()); | 
|  | 3592 | } | 
|  | 3593 |  | 
|  | 3594 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { | 
|  | 3595 | LOG(FATAL) << "Unreachable"; | 
|  | 3596 | } | 
|  | 3597 |  | 
|  | 3598 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { | 
|  | 3599 | Primitive::Type type = rem->GetResultType(); | 
|  | 3600 | LocationSummary::CallKind call_kind = | 
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame^] | 3601 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly | 
|  | 3602 | : LocationSummary::kNoCall; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3603 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); | 
|  | 3604 |  | 
|  | 3605 | switch (type) { | 
|  | 3606 | case Primitive::kPrimInt: | 
|  | 3607 | case Primitive::kPrimLong: | 
|  | 3608 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3609 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3610 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3611 | break; | 
|  | 3612 |  | 
|  | 3613 | case Primitive::kPrimFloat: | 
|  | 3614 | case Primitive::kPrimDouble: { | 
|  | 3615 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3616 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); | 
|  | 3617 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); | 
|  | 3618 | locations->SetOut(calling_convention.GetReturnLocation(type)); | 
|  | 3619 | break; | 
|  | 3620 | } | 
|  | 3621 |  | 
|  | 3622 | default: | 
|  | 3623 | LOG(FATAL) << "Unexpected rem type " << type; | 
|  | 3624 | } | 
|  | 3625 | } | 
|  | 3626 |  | 
|  | 3627 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { | 
|  | 3628 | Primitive::Type type = instruction->GetType(); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3629 |  | 
|  | 3630 | switch (type) { | 
|  | 3631 | case Primitive::kPrimInt: | 
| Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3632 | case Primitive::kPrimLong: | 
|  | 3633 | GenerateDivRemIntegral(instruction); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3634 | break; | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3635 |  | 
|  | 3636 | case Primitive::kPrimFloat: | 
|  | 3637 | case Primitive::kPrimDouble: { | 
|  | 3638 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) | 
|  | 3639 | : QUICK_ENTRY_POINT(pFmod); | 
|  | 3640 | codegen_->InvokeRuntime(entry_offset, instruction, instruction->GetDexPc(), nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3641 | if (type == Primitive::kPrimFloat) { | 
|  | 3642 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); | 
|  | 3643 | } else { | 
|  | 3644 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); | 
|  | 3645 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3646 | break; | 
|  | 3647 | } | 
|  | 3648 | default: | 
|  | 3649 | LOG(FATAL) << "Unexpected rem type " << type; | 
|  | 3650 | } | 
|  | 3651 | } | 
|  | 3652 |  | 
|  | 3653 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
|  | 3654 | memory_barrier->SetLocations(nullptr); | 
|  | 3655 | } | 
|  | 3656 |  | 
|  | 3657 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
|  | 3658 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); | 
|  | 3659 | } | 
|  | 3660 |  | 
|  | 3661 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { | 
|  | 3662 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); | 
|  | 3663 | Primitive::Type return_type = ret->InputAt(0)->GetType(); | 
|  | 3664 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); | 
|  | 3665 | } | 
|  | 3666 |  | 
|  | 3667 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { | 
|  | 3668 | codegen_->GenerateFrameExit(); | 
|  | 3669 | } | 
|  | 3670 |  | 
|  | 3671 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { | 
|  | 3672 | ret->SetLocations(nullptr); | 
|  | 3673 | } | 
|  | 3674 |  | 
|  | 3675 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { | 
|  | 3676 | codegen_->GenerateFrameExit(); | 
|  | 3677 | } | 
|  | 3678 |  | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 3679 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { | 
|  | 3680 | HandleShift(ror); | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3681 | } | 
|  | 3682 |  | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 3683 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { | 
|  | 3684 | HandleShift(ror); | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3685 | } | 
|  | 3686 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3687 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { | 
|  | 3688 | HandleShift(shl); | 
|  | 3689 | } | 
|  | 3690 |  | 
|  | 3691 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { | 
|  | 3692 | HandleShift(shl); | 
|  | 3693 | } | 
|  | 3694 |  | 
|  | 3695 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { | 
|  | 3696 | HandleShift(shr); | 
|  | 3697 | } | 
|  | 3698 |  | 
|  | 3699 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { | 
|  | 3700 | HandleShift(shr); | 
|  | 3701 | } | 
|  | 3702 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3703 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { | 
|  | 3704 | HandleBinaryOp(instruction); | 
|  | 3705 | } | 
|  | 3706 |  | 
|  | 3707 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { | 
|  | 3708 | HandleBinaryOp(instruction); | 
|  | 3709 | } | 
|  | 3710 |  | 
|  | 3711 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
|  | 3712 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
|  | 3713 | } | 
|  | 3714 |  | 
|  | 3715 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
|  | 3716 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
|  | 3717 | } | 
|  | 3718 |  | 
|  | 3719 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
|  | 3720 | HandleFieldSet(instruction, instruction->GetFieldInfo()); | 
|  | 3721 | } | 
|  | 3722 |  | 
|  | 3723 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
| Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 3724 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3725 | } | 
|  | 3726 |  | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 3727 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( | 
|  | 3728 | HUnresolvedInstanceFieldGet* instruction) { | 
|  | 3729 | FieldAccessCallingConventionMIPS64 calling_convention; | 
|  | 3730 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 3731 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 3732 | } | 
|  | 3733 |  | 
|  | 3734 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( | 
|  | 3735 | HUnresolvedInstanceFieldGet* instruction) { | 
|  | 3736 | FieldAccessCallingConventionMIPS64 calling_convention; | 
|  | 3737 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 3738 | instruction->GetFieldType(), | 
|  | 3739 | instruction->GetFieldIndex(), | 
|  | 3740 | instruction->GetDexPc(), | 
|  | 3741 | calling_convention); | 
|  | 3742 | } | 
|  | 3743 |  | 
|  | 3744 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( | 
|  | 3745 | HUnresolvedInstanceFieldSet* instruction) { | 
|  | 3746 | FieldAccessCallingConventionMIPS64 calling_convention; | 
|  | 3747 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 3748 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 3749 | } | 
|  | 3750 |  | 
|  | 3751 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( | 
|  | 3752 | HUnresolvedInstanceFieldSet* instruction) { | 
|  | 3753 | FieldAccessCallingConventionMIPS64 calling_convention; | 
|  | 3754 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 3755 | instruction->GetFieldType(), | 
|  | 3756 | instruction->GetFieldIndex(), | 
|  | 3757 | instruction->GetDexPc(), | 
|  | 3758 | calling_convention); | 
|  | 3759 | } | 
|  | 3760 |  | 
|  | 3761 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( | 
|  | 3762 | HUnresolvedStaticFieldGet* instruction) { | 
|  | 3763 | FieldAccessCallingConventionMIPS64 calling_convention; | 
|  | 3764 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 3765 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 3766 | } | 
|  | 3767 |  | 
|  | 3768 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( | 
|  | 3769 | HUnresolvedStaticFieldGet* instruction) { | 
|  | 3770 | FieldAccessCallingConventionMIPS64 calling_convention; | 
|  | 3771 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 3772 | instruction->GetFieldType(), | 
|  | 3773 | instruction->GetFieldIndex(), | 
|  | 3774 | instruction->GetDexPc(), | 
|  | 3775 | calling_convention); | 
|  | 3776 | } | 
|  | 3777 |  | 
|  | 3778 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( | 
|  | 3779 | HUnresolvedStaticFieldSet* instruction) { | 
|  | 3780 | FieldAccessCallingConventionMIPS64 calling_convention; | 
|  | 3781 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 3782 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 3783 | } | 
|  | 3784 |  | 
|  | 3785 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( | 
|  | 3786 | HUnresolvedStaticFieldSet* instruction) { | 
|  | 3787 | FieldAccessCallingConventionMIPS64 calling_convention; | 
|  | 3788 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 3789 | instruction->GetFieldType(), | 
|  | 3790 | instruction->GetFieldIndex(), | 
|  | 3791 | instruction->GetDexPc(), | 
|  | 3792 | calling_convention); | 
|  | 3793 | } | 
|  | 3794 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3795 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { | 
|  | 3796 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); | 
|  | 3797 | } | 
|  | 3798 |  | 
|  | 3799 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { | 
|  | 3800 | HBasicBlock* block = instruction->GetBlock(); | 
|  | 3801 | if (block->GetLoopInformation() != nullptr) { | 
|  | 3802 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); | 
|  | 3803 | // The back edge will generate the suspend check. | 
|  | 3804 | return; | 
|  | 3805 | } | 
|  | 3806 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { | 
|  | 3807 | // The goto will generate the suspend check. | 
|  | 3808 | return; | 
|  | 3809 | } | 
|  | 3810 | GenerateSuspendCheck(instruction, nullptr); | 
|  | 3811 | } | 
|  | 3812 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3813 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { | 
|  | 3814 | LocationSummary* locations = | 
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame^] | 3815 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3816 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3817 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 3818 | } | 
|  | 3819 |  | 
|  | 3820 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { | 
|  | 3821 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), | 
|  | 3822 | instruction, | 
|  | 3823 | instruction->GetDexPc(), | 
|  | 3824 | nullptr); | 
|  | 3825 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); | 
|  | 3826 | } | 
|  | 3827 |  | 
|  | 3828 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { | 
|  | 3829 | Primitive::Type input_type = conversion->GetInputType(); | 
|  | 3830 | Primitive::Type result_type = conversion->GetResultType(); | 
|  | 3831 | DCHECK_NE(input_type, result_type); | 
|  | 3832 |  | 
|  | 3833 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || | 
|  | 3834 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { | 
|  | 3835 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; | 
|  | 3836 | } | 
|  | 3837 |  | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3838 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion); | 
|  | 3839 |  | 
|  | 3840 | if (Primitive::IsFloatingPointType(input_type)) { | 
|  | 3841 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 3842 | } else { | 
|  | 3843 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3844 | } | 
|  | 3845 |  | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3846 | if (Primitive::IsFloatingPointType(result_type)) { | 
|  | 3847 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3848 | } else { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3849 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3850 | } | 
|  | 3851 | } | 
|  | 3852 |  | 
|  | 3853 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { | 
|  | 3854 | LocationSummary* locations = conversion->GetLocations(); | 
|  | 3855 | Primitive::Type result_type = conversion->GetResultType(); | 
|  | 3856 | Primitive::Type input_type = conversion->GetInputType(); | 
|  | 3857 |  | 
|  | 3858 | DCHECK_NE(input_type, result_type); | 
|  | 3859 |  | 
|  | 3860 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { | 
|  | 3861 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
|  | 3862 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 3863 |  | 
|  | 3864 | switch (result_type) { | 
|  | 3865 | case Primitive::kPrimChar: | 
|  | 3866 | __ Andi(dst, src, 0xFFFF); | 
|  | 3867 | break; | 
|  | 3868 | case Primitive::kPrimByte: | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3869 | if (input_type == Primitive::kPrimLong) { | 
|  | 3870 | // Type conversion from long to types narrower than int is a result of code | 
|  | 3871 | // transformations. To avoid unpredictable results for SEB and SEH, we first | 
|  | 3872 | // need to sign-extend the low 32-bit value into bits 32 through 63. | 
|  | 3873 | __ Sll(dst, src, 0); | 
|  | 3874 | __ Seb(dst, dst); | 
|  | 3875 | } else { | 
|  | 3876 | __ Seb(dst, src); | 
|  | 3877 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3878 | break; | 
|  | 3879 | case Primitive::kPrimShort: | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3880 | if (input_type == Primitive::kPrimLong) { | 
|  | 3881 | // Type conversion from long to types narrower than int is a result of code | 
|  | 3882 | // transformations. To avoid unpredictable results for SEB and SEH, we first | 
|  | 3883 | // need to sign-extend the low 32-bit value into bits 32 through 63. | 
|  | 3884 | __ Sll(dst, src, 0); | 
|  | 3885 | __ Seh(dst, dst); | 
|  | 3886 | } else { | 
|  | 3887 | __ Seh(dst, src); | 
|  | 3888 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3889 | break; | 
|  | 3890 | case Primitive::kPrimInt: | 
|  | 3891 | case Primitive::kPrimLong: | 
|  | 3892 | // Sign-extend 32-bit int into bits 32 through 63 for | 
|  | 3893 | // int-to-long and long-to-int conversions | 
|  | 3894 | __ Sll(dst, src, 0); | 
|  | 3895 | break; | 
|  | 3896 |  | 
|  | 3897 | default: | 
|  | 3898 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 3899 | << " to " << result_type; | 
|  | 3900 | } | 
|  | 3901 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3902 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); | 
|  | 3903 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 3904 | if (input_type == Primitive::kPrimLong) { | 
|  | 3905 | __ Dmtc1(src, FTMP); | 
|  | 3906 | if (result_type == Primitive::kPrimFloat) { | 
|  | 3907 | __ Cvtsl(dst, FTMP); | 
|  | 3908 | } else { | 
|  | 3909 | __ Cvtdl(dst, FTMP); | 
|  | 3910 | } | 
|  | 3911 | } else { | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3912 | __ Mtc1(src, FTMP); | 
|  | 3913 | if (result_type == Primitive::kPrimFloat) { | 
|  | 3914 | __ Cvtsw(dst, FTMP); | 
|  | 3915 | } else { | 
|  | 3916 | __ Cvtdw(dst, FTMP); | 
|  | 3917 | } | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3918 | } | 
|  | 3919 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { | 
|  | 3920 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3921 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); | 
|  | 3922 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); | 
|  | 3923 | Mips64Label truncate; | 
|  | 3924 | Mips64Label done; | 
|  | 3925 |  | 
|  | 3926 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive | 
|  | 3927 | // value when the input is either a NaN or is outside of the range of the output type | 
|  | 3928 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce | 
|  | 3929 | // the same result. | 
|  | 3930 | // | 
|  | 3931 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum | 
|  | 3932 | // value of the output type if the input is outside of the range after the truncation or | 
|  | 3933 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct | 
|  | 3934 | // results. This matches the desired float/double-to-int/long conversion exactly. | 
|  | 3935 | // | 
|  | 3936 | // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction. | 
|  | 3937 | // | 
|  | 3938 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate | 
|  | 3939 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, | 
|  | 3940 | // even though it must be NAN2008=1 on R6. | 
|  | 3941 | // | 
|  | 3942 | // The code takes care of the different behaviors by first comparing the input to the | 
|  | 3943 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). | 
|  | 3944 | // If the input is greater than or equal to the minimum, it procedes to the truncate | 
|  | 3945 | // instruction, which will handle such an input the same way irrespective of NAN2008. | 
|  | 3946 | // Otherwise the input is compared to itself to determine whether it is a NaN or not | 
|  | 3947 | // in order to return either zero or the minimum value. | 
|  | 3948 | // | 
|  | 3949 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the | 
|  | 3950 | // truncate instruction for MIPS64R6. | 
|  | 3951 | if (input_type == Primitive::kPrimFloat) { | 
|  | 3952 | uint32_t min_val = (result_type == Primitive::kPrimLong) | 
|  | 3953 | ? bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min()) | 
|  | 3954 | : bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); | 
|  | 3955 | __ LoadConst32(TMP, min_val); | 
|  | 3956 | __ Mtc1(TMP, FTMP); | 
|  | 3957 | __ CmpLeS(FTMP, FTMP, src); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3958 | } else { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3959 | uint64_t min_val = (result_type == Primitive::kPrimLong) | 
|  | 3960 | ? bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min()) | 
|  | 3961 | : bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); | 
|  | 3962 | __ LoadConst64(TMP, min_val); | 
|  | 3963 | __ Dmtc1(TMP, FTMP); | 
|  | 3964 | __ CmpLeD(FTMP, FTMP, src); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3965 | } | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3966 |  | 
|  | 3967 | __ Bc1nez(FTMP, &truncate); | 
|  | 3968 |  | 
|  | 3969 | if (input_type == Primitive::kPrimFloat) { | 
|  | 3970 | __ CmpEqS(FTMP, src, src); | 
|  | 3971 | } else { | 
|  | 3972 | __ CmpEqD(FTMP, src, src); | 
|  | 3973 | } | 
|  | 3974 | if (result_type == Primitive::kPrimLong) { | 
|  | 3975 | __ LoadConst64(dst, std::numeric_limits<int64_t>::min()); | 
|  | 3976 | } else { | 
|  | 3977 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); | 
|  | 3978 | } | 
|  | 3979 | __ Mfc1(TMP, FTMP); | 
|  | 3980 | __ And(dst, dst, TMP); | 
|  | 3981 |  | 
|  | 3982 | __ Bc(&done); | 
|  | 3983 |  | 
|  | 3984 | __ Bind(&truncate); | 
|  | 3985 |  | 
|  | 3986 | if (result_type == Primitive::kPrimLong) { | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3987 | if (input_type == Primitive::kPrimFloat) { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3988 | __ TruncLS(FTMP, src); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3989 | } else { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3990 | __ TruncLD(FTMP, src); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3991 | } | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3992 | __ Dmfc1(dst, FTMP); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3993 | } else { | 
|  | 3994 | if (input_type == Primitive::kPrimFloat) { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3995 | __ TruncWS(FTMP, src); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3996 | } else { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3997 | __ TruncWD(FTMP, src); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3998 | } | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3999 | __ Mfc1(dst, FTMP); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4000 | } | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 4001 |  | 
|  | 4002 | __ Bind(&done); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4003 | } else if (Primitive::IsFloatingPointType(result_type) && | 
|  | 4004 | Primitive::IsFloatingPointType(input_type)) { | 
|  | 4005 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); | 
|  | 4006 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); | 
|  | 4007 | if (result_type == Primitive::kPrimFloat) { | 
|  | 4008 | __ Cvtsd(dst, src); | 
|  | 4009 | } else { | 
|  | 4010 | __ Cvtds(dst, src); | 
|  | 4011 | } | 
|  | 4012 | } else { | 
|  | 4013 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type | 
|  | 4014 | << " to " << result_type; | 
|  | 4015 | } | 
|  | 4016 | } | 
|  | 4017 |  | 
|  | 4018 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { | 
|  | 4019 | HandleShift(ushr); | 
|  | 4020 | } | 
|  | 4021 |  | 
|  | 4022 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { | 
|  | 4023 | HandleShift(ushr); | 
|  | 4024 | } | 
|  | 4025 |  | 
|  | 4026 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { | 
|  | 4027 | HandleBinaryOp(instruction); | 
|  | 4028 | } | 
|  | 4029 |  | 
|  | 4030 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { | 
|  | 4031 | HandleBinaryOp(instruction); | 
|  | 4032 | } | 
|  | 4033 |  | 
|  | 4034 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { | 
|  | 4035 | // Nothing to do, this should be removed during prepare for register allocator. | 
|  | 4036 | LOG(FATAL) << "Unreachable"; | 
|  | 4037 | } | 
|  | 4038 |  | 
|  | 4039 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { | 
|  | 4040 | // Nothing to do, this should be removed during prepare for register allocator. | 
|  | 4041 | LOG(FATAL) << "Unreachable"; | 
|  | 4042 | } | 
|  | 4043 |  | 
|  | 4044 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4045 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4046 | } | 
|  | 4047 |  | 
|  | 4048 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4049 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4050 | } | 
|  | 4051 |  | 
|  | 4052 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4053 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4054 | } | 
|  | 4055 |  | 
|  | 4056 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4057 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4058 | } | 
|  | 4059 |  | 
|  | 4060 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4061 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4062 | } | 
|  | 4063 |  | 
|  | 4064 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4065 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4066 | } | 
|  | 4067 |  | 
|  | 4068 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4069 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4070 | } | 
|  | 4071 |  | 
|  | 4072 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4073 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4074 | } | 
|  | 4075 |  | 
|  | 4076 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4077 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4078 | } | 
|  | 4079 |  | 
|  | 4080 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4081 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4082 | } | 
|  | 4083 |  | 
|  | 4084 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4085 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4086 | } | 
|  | 4087 |  | 
|  | 4088 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4089 | HandleCondition(comp); | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4090 | } | 
|  | 4091 |  | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4092 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4093 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4094 | } | 
|  | 4095 |  | 
|  | 4096 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4097 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4098 | } | 
|  | 4099 |  | 
|  | 4100 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4101 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4102 | } | 
|  | 4103 |  | 
|  | 4104 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4105 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4106 | } | 
|  | 4107 |  | 
|  | 4108 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4109 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4110 | } | 
|  | 4111 |  | 
|  | 4112 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4113 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4114 | } | 
|  | 4115 |  | 
|  | 4116 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4117 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4118 | } | 
|  | 4119 |  | 
|  | 4120 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4121 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4122 | } | 
|  | 4123 |  | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4124 | // Simple implementation of packed switch - generate cascaded compare/jumps. | 
|  | 4125 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
|  | 4126 | LocationSummary* locations = | 
|  | 4127 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); | 
|  | 4128 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4129 | } | 
|  | 4130 |  | 
|  | 4131 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
|  | 4132 | int32_t lower_bound = switch_instr->GetStartValue(); | 
|  | 4133 | int32_t num_entries = switch_instr->GetNumEntries(); | 
|  | 4134 | LocationSummary* locations = switch_instr->GetLocations(); | 
|  | 4135 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); | 
|  | 4136 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); | 
|  | 4137 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4138 | // Create a set of compare/jumps. | 
|  | 4139 | GpuRegister temp_reg = TMP; | 
|  | 4140 | if (IsInt<16>(-lower_bound)) { | 
|  | 4141 | __ Addiu(temp_reg, value_reg, -lower_bound); | 
|  | 4142 | } else { | 
|  | 4143 | __ LoadConst32(AT, -lower_bound); | 
|  | 4144 | __ Addu(temp_reg, value_reg, AT); | 
|  | 4145 | } | 
|  | 4146 | // Jump to default if index is negative | 
|  | 4147 | // Note: We don't check the case that index is positive while value < lower_bound, because in | 
|  | 4148 | // this case, index >= num_entries must be true. So that we can save one branch instruction. | 
|  | 4149 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); | 
|  | 4150 |  | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4151 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4152 | // Jump to successors[0] if value == lower_bound. | 
|  | 4153 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); | 
|  | 4154 | int32_t last_index = 0; | 
|  | 4155 | for (; num_entries - last_index > 2; last_index += 2) { | 
|  | 4156 | __ Addiu(temp_reg, temp_reg, -2); | 
|  | 4157 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. | 
|  | 4158 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); | 
|  | 4159 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. | 
|  | 4160 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); | 
|  | 4161 | } | 
|  | 4162 | if (num_entries - last_index == 2) { | 
|  | 4163 | // The last missing case_value. | 
|  | 4164 | __ Addiu(temp_reg, temp_reg, -1); | 
|  | 4165 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4166 | } | 
|  | 4167 |  | 
|  | 4168 | // And the default for any other value. | 
|  | 4169 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { | 
| Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4170 | __ Bc(codegen_->GetLabelOf(default_block)); | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4171 | } | 
|  | 4172 | } | 
|  | 4173 |  | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4174 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet*) { | 
|  | 4175 | UNIMPLEMENTED(FATAL) << "ClassTableGet is unimplemented on mips64"; | 
|  | 4176 | } | 
|  | 4177 |  | 
|  | 4178 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet*) { | 
|  | 4179 | UNIMPLEMENTED(FATAL) << "ClassTableGet is unimplemented on mips64"; | 
|  | 4180 | } | 
|  | 4181 |  | 
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4182 | }  // namespace mips64 | 
|  | 4183 | }  // namespace art |