| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2015 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #include "code_generator_mips.h" | 
|  | 18 |  | 
|  | 19 | #include "arch/mips/entrypoints_direct_mips.h" | 
|  | 20 | #include "arch/mips/instruction_set_features_mips.h" | 
|  | 21 | #include "art_method.h" | 
| Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 22 | #include "code_generator_utils.h" | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" | 
|  | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" | 
|  | 25 | #include "gc/accounting/card_table.h" | 
|  | 26 | #include "intrinsics.h" | 
| Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 27 | #include "intrinsics_mips.h" | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 28 | #include "mirror/array-inl.h" | 
|  | 29 | #include "mirror/class-inl.h" | 
|  | 30 | #include "offsets.h" | 
|  | 31 | #include "thread.h" | 
|  | 32 | #include "utils/assembler.h" | 
|  | 33 | #include "utils/mips/assembler_mips.h" | 
|  | 34 | #include "utils/stack_checks.h" | 
|  | 35 |  | 
|  | 36 | namespace art { | 
|  | 37 | namespace mips { | 
|  | 38 |  | 
|  | 39 | static constexpr int kCurrentMethodStackOffset = 0; | 
|  | 40 | static constexpr Register kMethodRegisterArgument = A0; | 
|  | 41 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 42 | Location MipsReturnLocation(Primitive::Type return_type) { | 
|  | 43 | switch (return_type) { | 
|  | 44 | case Primitive::kPrimBoolean: | 
|  | 45 | case Primitive::kPrimByte: | 
|  | 46 | case Primitive::kPrimChar: | 
|  | 47 | case Primitive::kPrimShort: | 
|  | 48 | case Primitive::kPrimInt: | 
|  | 49 | case Primitive::kPrimNot: | 
|  | 50 | return Location::RegisterLocation(V0); | 
|  | 51 |  | 
|  | 52 | case Primitive::kPrimLong: | 
|  | 53 | return Location::RegisterPairLocation(V0, V1); | 
|  | 54 |  | 
|  | 55 | case Primitive::kPrimFloat: | 
|  | 56 | case Primitive::kPrimDouble: | 
|  | 57 | return Location::FpuRegisterLocation(F0); | 
|  | 58 |  | 
|  | 59 | case Primitive::kPrimVoid: | 
|  | 60 | return Location(); | 
|  | 61 | } | 
|  | 62 | UNREACHABLE(); | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(Primitive::Type type) const { | 
|  | 66 | return MipsReturnLocation(type); | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const { | 
|  | 70 | return Location::RegisterLocation(kMethodRegisterArgument); | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(Primitive::Type type) { | 
|  | 74 | Location next_location; | 
|  | 75 |  | 
|  | 76 | switch (type) { | 
|  | 77 | case Primitive::kPrimBoolean: | 
|  | 78 | case Primitive::kPrimByte: | 
|  | 79 | case Primitive::kPrimChar: | 
|  | 80 | case Primitive::kPrimShort: | 
|  | 81 | case Primitive::kPrimInt: | 
|  | 82 | case Primitive::kPrimNot: { | 
|  | 83 | uint32_t gp_index = gp_index_++; | 
|  | 84 | if (gp_index < calling_convention.GetNumberOfRegisters()) { | 
|  | 85 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index)); | 
|  | 86 | } else { | 
|  | 87 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); | 
|  | 88 | next_location = Location::StackSlot(stack_offset); | 
|  | 89 | } | 
|  | 90 | break; | 
|  | 91 | } | 
|  | 92 |  | 
|  | 93 | case Primitive::kPrimLong: { | 
|  | 94 | uint32_t gp_index = gp_index_; | 
|  | 95 | gp_index_ += 2; | 
|  | 96 | if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) { | 
|  | 97 | if (calling_convention.GetRegisterAt(gp_index) == A1) { | 
|  | 98 | gp_index_++;  // Skip A1, and use A2_A3 instead. | 
|  | 99 | gp_index++; | 
|  | 100 | } | 
|  | 101 | Register low_even = calling_convention.GetRegisterAt(gp_index); | 
|  | 102 | Register high_odd = calling_convention.GetRegisterAt(gp_index + 1); | 
|  | 103 | DCHECK_EQ(low_even + 1, high_odd); | 
|  | 104 | next_location = Location::RegisterPairLocation(low_even, high_odd); | 
|  | 105 | } else { | 
|  | 106 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); | 
|  | 107 | next_location = Location::DoubleStackSlot(stack_offset); | 
|  | 108 | } | 
|  | 109 | break; | 
|  | 110 | } | 
|  | 111 |  | 
|  | 112 | // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double | 
|  | 113 | // will take up the even/odd pair, while floats are stored in even regs only. | 
|  | 114 | // On 64 bit FPU, both double and float are stored in even registers only. | 
|  | 115 | case Primitive::kPrimFloat: | 
|  | 116 | case Primitive::kPrimDouble: { | 
|  | 117 | uint32_t float_index = float_index_++; | 
|  | 118 | if (float_index < calling_convention.GetNumberOfFpuRegisters()) { | 
|  | 119 | next_location = Location::FpuRegisterLocation( | 
|  | 120 | calling_convention.GetFpuRegisterAt(float_index)); | 
|  | 121 | } else { | 
|  | 122 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); | 
|  | 123 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) | 
|  | 124 | : Location::StackSlot(stack_offset); | 
|  | 125 | } | 
|  | 126 | break; | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | case Primitive::kPrimVoid: | 
|  | 130 | LOG(FATAL) << "Unexpected parameter type " << type; | 
|  | 131 | break; | 
|  | 132 | } | 
|  | 133 |  | 
|  | 134 | // Space on the stack is reserved for all arguments. | 
|  | 135 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; | 
|  | 136 |  | 
|  | 137 | return next_location; | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) { | 
|  | 141 | return MipsReturnLocation(type); | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | #define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> | 
|  | 145 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, x).Int32Value() | 
|  | 146 |  | 
|  | 147 | class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS { | 
|  | 148 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 149 | explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {} | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 150 |  | 
|  | 151 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 152 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 153 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); | 
|  | 154 | __ Bind(GetEntryLabel()); | 
|  | 155 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 156 | // Live registers will be restored in the catch block if caught. | 
|  | 157 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 158 | } | 
|  | 159 | // We're moving two locations to locations that could overlap, so we need a parallel | 
|  | 160 | // move resolver. | 
|  | 161 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 162 | codegen->EmitParallelMoves(locations->InAt(0), | 
|  | 163 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
|  | 164 | Primitive::kPrimInt, | 
|  | 165 | locations->InAt(1), | 
|  | 166 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
|  | 167 | Primitive::kPrimInt); | 
|  | 168 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), | 
|  | 169 | instruction_, | 
|  | 170 | instruction_->GetDexPc(), | 
|  | 171 | this, | 
|  | 172 | IsDirectEntrypoint(kQuickThrowArrayBounds)); | 
|  | 173 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); | 
|  | 174 | } | 
|  | 175 |  | 
|  | 176 | bool IsFatal() const OVERRIDE { return true; } | 
|  | 177 |  | 
|  | 178 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; } | 
|  | 179 |  | 
|  | 180 | private: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 181 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS); | 
|  | 182 | }; | 
|  | 183 |  | 
|  | 184 | class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS { | 
|  | 185 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 186 | explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {} | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 187 |  | 
|  | 188 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 189 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); | 
|  | 190 | __ Bind(GetEntryLabel()); | 
|  | 191 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 192 | // Live registers will be restored in the catch block if caught. | 
|  | 193 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 194 | } | 
|  | 195 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), | 
|  | 196 | instruction_, | 
|  | 197 | instruction_->GetDexPc(), | 
|  | 198 | this, | 
|  | 199 | IsDirectEntrypoint(kQuickThrowDivZero)); | 
|  | 200 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | bool IsFatal() const OVERRIDE { return true; } | 
|  | 204 |  | 
|  | 205 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; } | 
|  | 206 |  | 
|  | 207 | private: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 208 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS); | 
|  | 209 | }; | 
|  | 210 |  | 
|  | 211 | class LoadClassSlowPathMIPS : public SlowPathCodeMIPS { | 
|  | 212 | public: | 
|  | 213 | LoadClassSlowPathMIPS(HLoadClass* cls, | 
|  | 214 | HInstruction* at, | 
|  | 215 | uint32_t dex_pc, | 
|  | 216 | bool do_clinit) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 217 | : SlowPathCodeMIPS(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 218 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); | 
|  | 219 | } | 
|  | 220 |  | 
|  | 221 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 222 | LocationSummary* locations = at_->GetLocations(); | 
|  | 223 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); | 
|  | 224 |  | 
|  | 225 | __ Bind(GetEntryLabel()); | 
|  | 226 | SaveLiveRegisters(codegen, locations); | 
|  | 227 |  | 
|  | 228 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 229 | __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); | 
|  | 230 |  | 
|  | 231 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) | 
|  | 232 | : QUICK_ENTRY_POINT(pInitializeType); | 
|  | 233 | bool direct = do_clinit_ ? IsDirectEntrypoint(kQuickInitializeStaticStorage) | 
|  | 234 | : IsDirectEntrypoint(kQuickInitializeType); | 
|  | 235 |  | 
|  | 236 | mips_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this, direct); | 
|  | 237 | if (do_clinit_) { | 
|  | 238 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); | 
|  | 239 | } else { | 
|  | 240 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); | 
|  | 241 | } | 
|  | 242 |  | 
|  | 243 | // Move the class to the desired location. | 
|  | 244 | Location out = locations->Out(); | 
|  | 245 | if (out.IsValid()) { | 
|  | 246 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); | 
|  | 247 | Primitive::Type type = at_->GetType(); | 
|  | 248 | mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | RestoreLiveRegisters(codegen, locations); | 
|  | 252 | __ B(GetExitLabel()); | 
|  | 253 | } | 
|  | 254 |  | 
|  | 255 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } | 
|  | 256 |  | 
|  | 257 | private: | 
|  | 258 | // The class this slow path will load. | 
|  | 259 | HLoadClass* const cls_; | 
|  | 260 |  | 
|  | 261 | // The instruction where this slow path is happening. | 
|  | 262 | // (Might be the load class or an initialization check). | 
|  | 263 | HInstruction* const at_; | 
|  | 264 |  | 
|  | 265 | // The dex PC of `at_`. | 
|  | 266 | const uint32_t dex_pc_; | 
|  | 267 |  | 
|  | 268 | // Whether to initialize the class. | 
|  | 269 | const bool do_clinit_; | 
|  | 270 |  | 
|  | 271 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); | 
|  | 272 | }; | 
|  | 273 |  | 
|  | 274 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { | 
|  | 275 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 276 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {} | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 277 |  | 
|  | 278 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 279 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 280 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
|  | 281 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); | 
|  | 282 |  | 
|  | 283 | __ Bind(GetEntryLabel()); | 
|  | 284 | SaveLiveRegisters(codegen, locations); | 
|  | 285 |  | 
|  | 286 | InvokeRuntimeCallingConvention calling_convention; | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 287 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); | 
|  | 288 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 289 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), | 
|  | 290 | instruction_, | 
|  | 291 | instruction_->GetDexPc(), | 
|  | 292 | this, | 
|  | 293 | IsDirectEntrypoint(kQuickResolveString)); | 
|  | 294 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); | 
|  | 295 | Primitive::Type type = instruction_->GetType(); | 
|  | 296 | mips_codegen->MoveLocation(locations->Out(), | 
|  | 297 | calling_convention.GetReturnLocation(type), | 
|  | 298 | type); | 
|  | 299 |  | 
|  | 300 | RestoreLiveRegisters(codegen, locations); | 
|  | 301 | __ B(GetExitLabel()); | 
|  | 302 | } | 
|  | 303 |  | 
|  | 304 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } | 
|  | 305 |  | 
|  | 306 | private: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 307 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); | 
|  | 308 | }; | 
|  | 309 |  | 
|  | 310 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { | 
|  | 311 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 312 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 313 |  | 
|  | 314 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 315 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); | 
|  | 316 | __ Bind(GetEntryLabel()); | 
|  | 317 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 318 | // Live registers will be restored in the catch block if caught. | 
|  | 319 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 320 | } | 
|  | 321 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), | 
|  | 322 | instruction_, | 
|  | 323 | instruction_->GetDexPc(), | 
|  | 324 | this, | 
|  | 325 | IsDirectEntrypoint(kQuickThrowNullPointer)); | 
|  | 326 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); | 
|  | 327 | } | 
|  | 328 |  | 
|  | 329 | bool IsFatal() const OVERRIDE { return true; } | 
|  | 330 |  | 
|  | 331 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } | 
|  | 332 |  | 
|  | 333 | private: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 334 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); | 
|  | 335 | }; | 
|  | 336 |  | 
|  | 337 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { | 
|  | 338 | public: | 
|  | 339 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 340 | : SlowPathCodeMIPS(instruction), successor_(successor) {} | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 341 |  | 
|  | 342 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 343 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); | 
|  | 344 | __ Bind(GetEntryLabel()); | 
|  | 345 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 346 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), | 
|  | 347 | instruction_, | 
|  | 348 | instruction_->GetDexPc(), | 
|  | 349 | this, | 
|  | 350 | IsDirectEntrypoint(kQuickTestSuspend)); | 
|  | 351 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); | 
|  | 352 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 353 | if (successor_ == nullptr) { | 
|  | 354 | __ B(GetReturnLabel()); | 
|  | 355 | } else { | 
|  | 356 | __ B(mips_codegen->GetLabelOf(successor_)); | 
|  | 357 | } | 
|  | 358 | } | 
|  | 359 |  | 
|  | 360 | MipsLabel* GetReturnLabel() { | 
|  | 361 | DCHECK(successor_ == nullptr); | 
|  | 362 | return &return_label_; | 
|  | 363 | } | 
|  | 364 |  | 
|  | 365 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } | 
|  | 366 |  | 
|  | 367 | private: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 368 | // If not null, the block to branch to after the suspend check. | 
|  | 369 | HBasicBlock* const successor_; | 
|  | 370 |  | 
|  | 371 | // If `successor_` is null, the label to branch to after the suspend check. | 
|  | 372 | MipsLabel return_label_; | 
|  | 373 |  | 
|  | 374 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); | 
|  | 375 | }; | 
|  | 376 |  | 
|  | 377 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { | 
|  | 378 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 379 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 380 |  | 
|  | 381 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 382 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 383 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out(); | 
|  | 384 | uint32_t dex_pc = instruction_->GetDexPc(); | 
|  | 385 | DCHECK(instruction_->IsCheckCast() | 
|  | 386 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
|  | 387 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); | 
|  | 388 |  | 
|  | 389 | __ Bind(GetEntryLabel()); | 
|  | 390 | SaveLiveRegisters(codegen, locations); | 
|  | 391 |  | 
|  | 392 | // We're moving two locations to locations that could overlap, so we need a parallel | 
|  | 393 | // move resolver. | 
|  | 394 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 395 | codegen->EmitParallelMoves(locations->InAt(1), | 
|  | 396 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
|  | 397 | Primitive::kPrimNot, | 
|  | 398 | object_class, | 
|  | 399 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
|  | 400 | Primitive::kPrimNot); | 
|  | 401 |  | 
|  | 402 | if (instruction_->IsInstanceOf()) { | 
|  | 403 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), | 
|  | 404 | instruction_, | 
|  | 405 | dex_pc, | 
|  | 406 | this, | 
|  | 407 | IsDirectEntrypoint(kQuickInstanceofNonTrivial)); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 408 | CheckEntrypointTypes< | 
|  | 409 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 410 | Primitive::Type ret_type = instruction_->GetType(); | 
|  | 411 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); | 
|  | 412 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 413 | } else { | 
|  | 414 | DCHECK(instruction_->IsCheckCast()); | 
|  | 415 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), | 
|  | 416 | instruction_, | 
|  | 417 | dex_pc, | 
|  | 418 | this, | 
|  | 419 | IsDirectEntrypoint(kQuickCheckCast)); | 
|  | 420 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); | 
|  | 421 | } | 
|  | 422 |  | 
|  | 423 | RestoreLiveRegisters(codegen, locations); | 
|  | 424 | __ B(GetExitLabel()); | 
|  | 425 | } | 
|  | 426 |  | 
|  | 427 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } | 
|  | 428 |  | 
|  | 429 | private: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 430 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); | 
|  | 431 | }; | 
|  | 432 |  | 
|  | 433 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { | 
|  | 434 | public: | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 435 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 436 | : SlowPathCodeMIPS(instruction) {} | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 437 |  | 
|  | 438 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 439 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 440 | __ Bind(GetEntryLabel()); | 
|  | 441 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 442 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), | 
|  | 443 | instruction_, | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 444 | instruction_->GetDexPc(), | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 445 | this, | 
|  | 446 | IsDirectEntrypoint(kQuickDeoptimize)); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 447 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 448 | } | 
|  | 449 |  | 
|  | 450 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } | 
|  | 451 |  | 
|  | 452 | private: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 453 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); | 
|  | 454 | }; | 
|  | 455 |  | 
|  | 456 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, | 
|  | 457 | const MipsInstructionSetFeatures& isa_features, | 
|  | 458 | const CompilerOptions& compiler_options, | 
|  | 459 | OptimizingCompilerStats* stats) | 
|  | 460 | : CodeGenerator(graph, | 
|  | 461 | kNumberOfCoreRegisters, | 
|  | 462 | kNumberOfFRegisters, | 
|  | 463 | kNumberOfRegisterPairs, | 
|  | 464 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), | 
|  | 465 | arraysize(kCoreCalleeSaves)), | 
|  | 466 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), | 
|  | 467 | arraysize(kFpuCalleeSaves)), | 
|  | 468 | compiler_options, | 
|  | 469 | stats), | 
|  | 470 | block_labels_(nullptr), | 
|  | 471 | location_builder_(graph, this), | 
|  | 472 | instruction_visitor_(graph, this), | 
|  | 473 | move_resolver_(graph->GetArena(), this), | 
|  | 474 | assembler_(&isa_features), | 
|  | 475 | isa_features_(isa_features) { | 
|  | 476 | // Save RA (containing the return address) to mimic Quick. | 
|  | 477 | AddAllocatedRegister(Location::RegisterLocation(RA)); | 
|  | 478 | } | 
|  | 479 |  | 
|  | 480 | #undef __ | 
|  | 481 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> | 
|  | 482 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, x).Int32Value() | 
|  | 483 |  | 
|  | 484 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { | 
|  | 485 | // Ensure that we fix up branches. | 
|  | 486 | __ FinalizeCode(); | 
|  | 487 |  | 
|  | 488 | // Adjust native pc offsets in stack maps. | 
|  | 489 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { | 
|  | 490 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; | 
|  | 491 | uint32_t new_position = __ GetAdjustedPosition(old_position); | 
|  | 492 | DCHECK_GE(new_position, old_position); | 
|  | 493 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); | 
|  | 494 | } | 
|  | 495 |  | 
|  | 496 | // Adjust pc offsets for the disassembly information. | 
|  | 497 | if (disasm_info_ != nullptr) { | 
|  | 498 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); | 
|  | 499 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); | 
|  | 500 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); | 
|  | 501 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { | 
|  | 502 | it.second.start = __ GetAdjustedPosition(it.second.start); | 
|  | 503 | it.second.end = __ GetAdjustedPosition(it.second.end); | 
|  | 504 | } | 
|  | 505 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { | 
|  | 506 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); | 
|  | 507 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); | 
|  | 508 | } | 
|  | 509 | } | 
|  | 510 |  | 
|  | 511 | CodeGenerator::Finalize(allocator); | 
|  | 512 | } | 
|  | 513 |  | 
|  | 514 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { | 
|  | 515 | return codegen_->GetAssembler(); | 
|  | 516 | } | 
|  | 517 |  | 
|  | 518 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { | 
|  | 519 | DCHECK_LT(index, moves_.size()); | 
|  | 520 | MoveOperands* move = moves_[index]; | 
|  | 521 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); | 
|  | 522 | } | 
|  | 523 |  | 
|  | 524 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { | 
|  | 525 | DCHECK_LT(index, moves_.size()); | 
|  | 526 | MoveOperands* move = moves_[index]; | 
|  | 527 | Primitive::Type type = move->GetType(); | 
|  | 528 | Location loc1 = move->GetDestination(); | 
|  | 529 | Location loc2 = move->GetSource(); | 
|  | 530 |  | 
|  | 531 | DCHECK(!loc1.IsConstant()); | 
|  | 532 | DCHECK(!loc2.IsConstant()); | 
|  | 533 |  | 
|  | 534 | if (loc1.Equals(loc2)) { | 
|  | 535 | return; | 
|  | 536 | } | 
|  | 537 |  | 
|  | 538 | if (loc1.IsRegister() && loc2.IsRegister()) { | 
|  | 539 | // Swap 2 GPRs. | 
|  | 540 | Register r1 = loc1.AsRegister<Register>(); | 
|  | 541 | Register r2 = loc2.AsRegister<Register>(); | 
|  | 542 | __ Move(TMP, r2); | 
|  | 543 | __ Move(r2, r1); | 
|  | 544 | __ Move(r1, TMP); | 
|  | 545 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { | 
|  | 546 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); | 
|  | 547 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); | 
|  | 548 | if (type == Primitive::kPrimFloat) { | 
|  | 549 | __ MovS(FTMP, f2); | 
|  | 550 | __ MovS(f2, f1); | 
|  | 551 | __ MovS(f1, FTMP); | 
|  | 552 | } else { | 
|  | 553 | DCHECK_EQ(type, Primitive::kPrimDouble); | 
|  | 554 | __ MovD(FTMP, f2); | 
|  | 555 | __ MovD(f2, f1); | 
|  | 556 | __ MovD(f1, FTMP); | 
|  | 557 | } | 
|  | 558 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || | 
|  | 559 | (loc1.IsFpuRegister() && loc2.IsRegister())) { | 
|  | 560 | // Swap FPR and GPR. | 
|  | 561 | DCHECK_EQ(type, Primitive::kPrimFloat);  // Can only swap a float. | 
|  | 562 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() | 
|  | 563 | : loc2.AsFpuRegister<FRegister>(); | 
|  | 564 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() | 
|  | 565 | : loc2.AsRegister<Register>(); | 
|  | 566 | __ Move(TMP, r2); | 
|  | 567 | __ Mfc1(r2, f1); | 
|  | 568 | __ Mtc1(TMP, f1); | 
|  | 569 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { | 
|  | 570 | // Swap 2 GPR register pairs. | 
|  | 571 | Register r1 = loc1.AsRegisterPairLow<Register>(); | 
|  | 572 | Register r2 = loc2.AsRegisterPairLow<Register>(); | 
|  | 573 | __ Move(TMP, r2); | 
|  | 574 | __ Move(r2, r1); | 
|  | 575 | __ Move(r1, TMP); | 
|  | 576 | r1 = loc1.AsRegisterPairHigh<Register>(); | 
|  | 577 | r2 = loc2.AsRegisterPairHigh<Register>(); | 
|  | 578 | __ Move(TMP, r2); | 
|  | 579 | __ Move(r2, r1); | 
|  | 580 | __ Move(r1, TMP); | 
|  | 581 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || | 
|  | 582 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { | 
|  | 583 | // Swap FPR and GPR register pair. | 
|  | 584 | DCHECK_EQ(type, Primitive::kPrimDouble); | 
|  | 585 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() | 
|  | 586 | : loc2.AsFpuRegister<FRegister>(); | 
|  | 587 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() | 
|  | 588 | : loc2.AsRegisterPairLow<Register>(); | 
|  | 589 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() | 
|  | 590 | : loc2.AsRegisterPairHigh<Register>(); | 
|  | 591 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and | 
|  | 592 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR | 
|  | 593 | // unpredictable and the following mfch1 will fail. | 
|  | 594 | __ Mfc1(TMP, f1); | 
| Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 595 | __ MoveFromFpuHigh(AT, f1); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 596 | __ Mtc1(r2_l, f1); | 
| Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 597 | __ MoveToFpuHigh(r2_h, f1); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 598 | __ Move(r2_l, TMP); | 
|  | 599 | __ Move(r2_h, AT); | 
|  | 600 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { | 
|  | 601 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); | 
|  | 602 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { | 
|  | 603 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); | 
| David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 604 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || | 
|  | 605 | (loc1.IsStackSlot() && loc2.IsRegister())) { | 
|  | 606 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() | 
|  | 607 | : loc2.AsRegister<Register>(); | 
|  | 608 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() | 
|  | 609 | : loc2.GetStackIndex(); | 
|  | 610 | __ Move(TMP, reg); | 
|  | 611 | __ LoadFromOffset(kLoadWord, reg, SP, offset); | 
|  | 612 | __ StoreToOffset(kStoreWord, TMP, SP, offset); | 
|  | 613 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || | 
|  | 614 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { | 
|  | 615 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() | 
|  | 616 | : loc2.AsRegisterPairLow<Register>(); | 
|  | 617 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() | 
|  | 618 | : loc2.AsRegisterPairHigh<Register>(); | 
|  | 619 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() | 
|  | 620 | : loc2.GetStackIndex(); | 
|  | 621 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) | 
|  | 622 | : loc2.GetHighStackIndex(kMipsWordSize); | 
|  | 623 | __ Move(TMP, reg_l); | 
| David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 624 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); | 
| David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 625 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); | 
| David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 626 | __ Move(TMP, reg_h); | 
|  | 627 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); | 
|  | 628 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 629 | } else { | 
|  | 630 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; | 
|  | 631 | } | 
|  | 632 | } | 
|  | 633 |  | 
|  | 634 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { | 
|  | 635 | __ Pop(static_cast<Register>(reg)); | 
|  | 636 | } | 
|  | 637 |  | 
|  | 638 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { | 
|  | 639 | __ Push(static_cast<Register>(reg)); | 
|  | 640 | } | 
|  | 641 |  | 
|  | 642 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { | 
|  | 643 | // Allocate a scratch register other than TMP, if available. | 
|  | 644 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be | 
|  | 645 | // automatically unspilled when the scratch scope object is destroyed). | 
|  | 646 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); | 
|  | 647 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. | 
|  | 648 | int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0; | 
|  | 649 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { | 
|  | 650 | __ LoadFromOffset(kLoadWord, | 
|  | 651 | Register(ensure_scratch.GetRegister()), | 
|  | 652 | SP, | 
|  | 653 | index1 + stack_offset); | 
|  | 654 | __ LoadFromOffset(kLoadWord, | 
|  | 655 | TMP, | 
|  | 656 | SP, | 
|  | 657 | index2 + stack_offset); | 
|  | 658 | __ StoreToOffset(kStoreWord, | 
|  | 659 | Register(ensure_scratch.GetRegister()), | 
|  | 660 | SP, | 
|  | 661 | index2 + stack_offset); | 
|  | 662 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); | 
|  | 663 | } | 
|  | 664 | } | 
|  | 665 |  | 
|  | 666 | static dwarf::Reg DWARFReg(Register reg) { | 
|  | 667 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); | 
|  | 668 | } | 
|  | 669 |  | 
|  | 670 | // TODO: mapping of floating-point registers to DWARF. | 
|  | 671 |  | 
|  | 672 | void CodeGeneratorMIPS::GenerateFrameEntry() { | 
|  | 673 | __ Bind(&frame_entry_label_); | 
|  | 674 |  | 
|  | 675 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod(); | 
|  | 676 |  | 
|  | 677 | if (do_overflow_check) { | 
|  | 678 | __ LoadFromOffset(kLoadWord, | 
|  | 679 | ZERO, | 
|  | 680 | SP, | 
|  | 681 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips))); | 
|  | 682 | RecordPcInfo(nullptr, 0); | 
|  | 683 | } | 
|  | 684 |  | 
|  | 685 | if (HasEmptyFrame()) { | 
|  | 686 | return; | 
|  | 687 | } | 
|  | 688 |  | 
|  | 689 | // Make sure the frame size isn't unreasonably large. | 
|  | 690 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) { | 
|  | 691 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes"; | 
|  | 692 | } | 
|  | 693 |  | 
|  | 694 | // Spill callee-saved registers. | 
|  | 695 | // Note that their cumulative size is small and they can be indexed using | 
|  | 696 | // 16-bit offsets. | 
|  | 697 |  | 
|  | 698 | // TODO: increment/decrement SP in one step instead of two or remove this comment. | 
|  | 699 |  | 
|  | 700 | uint32_t ofs = FrameEntrySpillSize(); | 
|  | 701 | bool unaligned_float = ofs & 0x7; | 
|  | 702 | bool fpu_32bit = isa_features_.Is32BitFloatingPoint(); | 
|  | 703 | __ IncreaseFrameSize(ofs); | 
|  | 704 |  | 
|  | 705 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { | 
|  | 706 | Register reg = kCoreCalleeSaves[i]; | 
|  | 707 | if (allocated_registers_.ContainsCoreRegister(reg)) { | 
|  | 708 | ofs -= kMipsWordSize; | 
|  | 709 | __ Sw(reg, SP, ofs); | 
|  | 710 | __ cfi().RelOffset(DWARFReg(reg), ofs); | 
|  | 711 | } | 
|  | 712 | } | 
|  | 713 |  | 
|  | 714 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { | 
|  | 715 | FRegister reg = kFpuCalleeSaves[i]; | 
|  | 716 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { | 
|  | 717 | ofs -= kMipsDoublewordSize; | 
|  | 718 | // TODO: Change the frame to avoid unaligned accesses for fpu registers. | 
|  | 719 | if (unaligned_float) { | 
|  | 720 | if (fpu_32bit) { | 
|  | 721 | __ Swc1(reg, SP, ofs); | 
|  | 722 | __ Swc1(static_cast<FRegister>(reg + 1), SP, ofs + 4); | 
|  | 723 | } else { | 
|  | 724 | __ Mfhc1(TMP, reg); | 
|  | 725 | __ Swc1(reg, SP, ofs); | 
|  | 726 | __ Sw(TMP, SP, ofs + 4); | 
|  | 727 | } | 
|  | 728 | } else { | 
|  | 729 | __ Sdc1(reg, SP, ofs); | 
|  | 730 | } | 
|  | 731 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); | 
|  | 732 | } | 
|  | 733 | } | 
|  | 734 |  | 
|  | 735 | // Allocate the rest of the frame and store the current method pointer | 
|  | 736 | // at its end. | 
|  | 737 |  | 
|  | 738 | __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); | 
|  | 739 |  | 
|  | 740 | static_assert(IsInt<16>(kCurrentMethodStackOffset), | 
|  | 741 | "kCurrentMethodStackOffset must fit into int16_t"); | 
|  | 742 | __ Sw(kMethodRegisterArgument, SP, kCurrentMethodStackOffset); | 
|  | 743 | } | 
|  | 744 |  | 
|  | 745 | void CodeGeneratorMIPS::GenerateFrameExit() { | 
|  | 746 | __ cfi().RememberState(); | 
|  | 747 |  | 
|  | 748 | if (!HasEmptyFrame()) { | 
|  | 749 | // Deallocate the rest of the frame. | 
|  | 750 |  | 
|  | 751 | __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); | 
|  | 752 |  | 
|  | 753 | // Restore callee-saved registers. | 
|  | 754 | // Note that their cumulative size is small and they can be indexed using | 
|  | 755 | // 16-bit offsets. | 
|  | 756 |  | 
|  | 757 | // TODO: increment/decrement SP in one step instead of two or remove this comment. | 
|  | 758 |  | 
|  | 759 | uint32_t ofs = 0; | 
|  | 760 | bool unaligned_float = FrameEntrySpillSize() & 0x7; | 
|  | 761 | bool fpu_32bit = isa_features_.Is32BitFloatingPoint(); | 
|  | 762 |  | 
|  | 763 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { | 
|  | 764 | FRegister reg = kFpuCalleeSaves[i]; | 
|  | 765 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { | 
|  | 766 | if (unaligned_float) { | 
|  | 767 | if (fpu_32bit) { | 
|  | 768 | __ Lwc1(reg, SP, ofs); | 
|  | 769 | __ Lwc1(static_cast<FRegister>(reg + 1), SP, ofs + 4); | 
|  | 770 | } else { | 
|  | 771 | __ Lwc1(reg, SP, ofs); | 
|  | 772 | __ Lw(TMP, SP, ofs + 4); | 
|  | 773 | __ Mthc1(TMP, reg); | 
|  | 774 | } | 
|  | 775 | } else { | 
|  | 776 | __ Ldc1(reg, SP, ofs); | 
|  | 777 | } | 
|  | 778 | ofs += kMipsDoublewordSize; | 
|  | 779 | // TODO: __ cfi().Restore(DWARFReg(reg)); | 
|  | 780 | } | 
|  | 781 | } | 
|  | 782 |  | 
|  | 783 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { | 
|  | 784 | Register reg = kCoreCalleeSaves[i]; | 
|  | 785 | if (allocated_registers_.ContainsCoreRegister(reg)) { | 
|  | 786 | __ Lw(reg, SP, ofs); | 
|  | 787 | ofs += kMipsWordSize; | 
|  | 788 | __ cfi().Restore(DWARFReg(reg)); | 
|  | 789 | } | 
|  | 790 | } | 
|  | 791 |  | 
|  | 792 | DCHECK_EQ(ofs, FrameEntrySpillSize()); | 
|  | 793 | __ DecreaseFrameSize(ofs); | 
|  | 794 | } | 
|  | 795 |  | 
|  | 796 | __ Jr(RA); | 
|  | 797 | __ Nop(); | 
|  | 798 |  | 
|  | 799 | __ cfi().RestoreState(); | 
|  | 800 | __ cfi().DefCFAOffset(GetFrameSize()); | 
|  | 801 | } | 
|  | 802 |  | 
|  | 803 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { | 
|  | 804 | __ Bind(GetLabelOf(block)); | 
|  | 805 | } | 
|  | 806 |  | 
|  | 807 | void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { | 
|  | 808 | if (src.Equals(dst)) { | 
|  | 809 | return; | 
|  | 810 | } | 
|  | 811 |  | 
|  | 812 | if (src.IsConstant()) { | 
|  | 813 | MoveConstant(dst, src.GetConstant()); | 
|  | 814 | } else { | 
|  | 815 | if (Primitive::Is64BitType(dst_type)) { | 
|  | 816 | Move64(dst, src); | 
|  | 817 | } else { | 
|  | 818 | Move32(dst, src); | 
|  | 819 | } | 
|  | 820 | } | 
|  | 821 | } | 
|  | 822 |  | 
|  | 823 | void CodeGeneratorMIPS::Move32(Location destination, Location source) { | 
|  | 824 | if (source.Equals(destination)) { | 
|  | 825 | return; | 
|  | 826 | } | 
|  | 827 |  | 
|  | 828 | if (destination.IsRegister()) { | 
|  | 829 | if (source.IsRegister()) { | 
|  | 830 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
|  | 831 | } else if (source.IsFpuRegister()) { | 
|  | 832 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); | 
|  | 833 | } else { | 
|  | 834 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; | 
|  | 835 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); | 
|  | 836 | } | 
|  | 837 | } else if (destination.IsFpuRegister()) { | 
|  | 838 | if (source.IsRegister()) { | 
|  | 839 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); | 
|  | 840 | } else if (source.IsFpuRegister()) { | 
|  | 841 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); | 
|  | 842 | } else { | 
|  | 843 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; | 
|  | 844 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); | 
|  | 845 | } | 
|  | 846 | } else { | 
|  | 847 | DCHECK(destination.IsStackSlot()) << destination; | 
|  | 848 | if (source.IsRegister()) { | 
|  | 849 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); | 
|  | 850 | } else if (source.IsFpuRegister()) { | 
|  | 851 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); | 
|  | 852 | } else { | 
|  | 853 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; | 
|  | 854 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); | 
|  | 855 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); | 
|  | 856 | } | 
|  | 857 | } | 
|  | 858 | } | 
|  | 859 |  | 
|  | 860 | void CodeGeneratorMIPS::Move64(Location destination, Location source) { | 
|  | 861 | if (source.Equals(destination)) { | 
|  | 862 | return; | 
|  | 863 | } | 
|  | 864 |  | 
|  | 865 | if (destination.IsRegisterPair()) { | 
|  | 866 | if (source.IsRegisterPair()) { | 
|  | 867 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); | 
|  | 868 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); | 
|  | 869 | } else if (source.IsFpuRegister()) { | 
|  | 870 | Register dst_high = destination.AsRegisterPairHigh<Register>(); | 
|  | 871 | Register dst_low =  destination.AsRegisterPairLow<Register>(); | 
|  | 872 | FRegister src = source.AsFpuRegister<FRegister>(); | 
|  | 873 | __ Mfc1(dst_low, src); | 
| Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 874 | __ MoveFromFpuHigh(dst_high, src); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 875 | } else { | 
|  | 876 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; | 
|  | 877 | int32_t off = source.GetStackIndex(); | 
|  | 878 | Register r = destination.AsRegisterPairLow<Register>(); | 
|  | 879 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); | 
|  | 880 | } | 
|  | 881 | } else if (destination.IsFpuRegister()) { | 
|  | 882 | if (source.IsRegisterPair()) { | 
|  | 883 | FRegister dst = destination.AsFpuRegister<FRegister>(); | 
|  | 884 | Register src_high = source.AsRegisterPairHigh<Register>(); | 
|  | 885 | Register src_low = source.AsRegisterPairLow<Register>(); | 
|  | 886 | __ Mtc1(src_low, dst); | 
| Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 887 | __ MoveToFpuHigh(src_high, dst); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 888 | } else if (source.IsFpuRegister()) { | 
|  | 889 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); | 
|  | 890 | } else { | 
|  | 891 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; | 
|  | 892 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); | 
|  | 893 | } | 
|  | 894 | } else { | 
|  | 895 | DCHECK(destination.IsDoubleStackSlot()) << destination; | 
|  | 896 | int32_t off = destination.GetStackIndex(); | 
|  | 897 | if (source.IsRegisterPair()) { | 
|  | 898 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off); | 
|  | 899 | } else if (source.IsFpuRegister()) { | 
|  | 900 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off); | 
|  | 901 | } else { | 
|  | 902 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; | 
|  | 903 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); | 
|  | 904 | __ StoreToOffset(kStoreWord, TMP, SP, off); | 
|  | 905 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); | 
|  | 906 | __ StoreToOffset(kStoreWord, TMP, SP, off + 4); | 
|  | 907 | } | 
|  | 908 | } | 
|  | 909 | } | 
|  | 910 |  | 
|  | 911 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { | 
|  | 912 | if (c->IsIntConstant() || c->IsNullConstant()) { | 
|  | 913 | // Move 32 bit constant. | 
|  | 914 | int32_t value = GetInt32ValueOf(c); | 
|  | 915 | if (destination.IsRegister()) { | 
|  | 916 | Register dst = destination.AsRegister<Register>(); | 
|  | 917 | __ LoadConst32(dst, value); | 
|  | 918 | } else { | 
|  | 919 | DCHECK(destination.IsStackSlot()) | 
|  | 920 | << "Cannot move " << c->DebugName() << " to " << destination; | 
|  | 921 | __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP); | 
|  | 922 | } | 
|  | 923 | } else if (c->IsLongConstant()) { | 
|  | 924 | // Move 64 bit constant. | 
|  | 925 | int64_t value = GetInt64ValueOf(c); | 
|  | 926 | if (destination.IsRegisterPair()) { | 
|  | 927 | Register r_h = destination.AsRegisterPairHigh<Register>(); | 
|  | 928 | Register r_l = destination.AsRegisterPairLow<Register>(); | 
|  | 929 | __ LoadConst64(r_h, r_l, value); | 
|  | 930 | } else { | 
|  | 931 | DCHECK(destination.IsDoubleStackSlot()) | 
|  | 932 | << "Cannot move " << c->DebugName() << " to " << destination; | 
|  | 933 | __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP); | 
|  | 934 | } | 
|  | 935 | } else if (c->IsFloatConstant()) { | 
|  | 936 | // Move 32 bit float constant. | 
|  | 937 | int32_t value = GetInt32ValueOf(c); | 
|  | 938 | if (destination.IsFpuRegister()) { | 
|  | 939 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); | 
|  | 940 | } else { | 
|  | 941 | DCHECK(destination.IsStackSlot()) | 
|  | 942 | << "Cannot move " << c->DebugName() << " to " << destination; | 
|  | 943 | __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP); | 
|  | 944 | } | 
|  | 945 | } else { | 
|  | 946 | // Move 64 bit double constant. | 
|  | 947 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); | 
|  | 948 | int64_t value = GetInt64ValueOf(c); | 
|  | 949 | if (destination.IsFpuRegister()) { | 
|  | 950 | FRegister fd = destination.AsFpuRegister<FRegister>(); | 
|  | 951 | __ LoadDConst64(fd, value, TMP); | 
|  | 952 | } else { | 
|  | 953 | DCHECK(destination.IsDoubleStackSlot()) | 
|  | 954 | << "Cannot move " << c->DebugName() << " to " << destination; | 
|  | 955 | __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP); | 
|  | 956 | } | 
|  | 957 | } | 
|  | 958 | } | 
|  | 959 |  | 
|  | 960 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { | 
|  | 961 | DCHECK(destination.IsRegister()); | 
|  | 962 | Register dst = destination.AsRegister<Register>(); | 
|  | 963 | __ LoadConst32(dst, value); | 
|  | 964 | } | 
|  | 965 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 966 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { | 
|  | 967 | if (location.IsRegister()) { | 
|  | 968 | locations->AddTemp(location); | 
| Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 969 | } else if (location.IsRegisterPair()) { | 
|  | 970 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); | 
|  | 971 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 972 | } else { | 
|  | 973 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; | 
|  | 974 | } | 
|  | 975 | } | 
|  | 976 |  | 
|  | 977 | Location CodeGeneratorMIPS::GetStackLocation(HLoadLocal* load) const { | 
|  | 978 | Primitive::Type type = load->GetType(); | 
|  | 979 |  | 
|  | 980 | switch (type) { | 
|  | 981 | case Primitive::kPrimNot: | 
|  | 982 | case Primitive::kPrimInt: | 
|  | 983 | case Primitive::kPrimFloat: | 
|  | 984 | return Location::StackSlot(GetStackSlot(load->GetLocal())); | 
|  | 985 |  | 
|  | 986 | case Primitive::kPrimLong: | 
|  | 987 | case Primitive::kPrimDouble: | 
|  | 988 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); | 
|  | 989 |  | 
|  | 990 | case Primitive::kPrimBoolean: | 
|  | 991 | case Primitive::kPrimByte: | 
|  | 992 | case Primitive::kPrimChar: | 
|  | 993 | case Primitive::kPrimShort: | 
|  | 994 | case Primitive::kPrimVoid: | 
|  | 995 | LOG(FATAL) << "Unexpected type " << type; | 
|  | 996 | } | 
|  | 997 |  | 
|  | 998 | LOG(FATAL) << "Unreachable"; | 
|  | 999 | return Location::NoLocation(); | 
|  | 1000 | } | 
|  | 1001 |  | 
|  | 1002 | void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) { | 
|  | 1003 | MipsLabel done; | 
|  | 1004 | Register card = AT; | 
|  | 1005 | Register temp = TMP; | 
|  | 1006 | __ Beqz(value, &done); | 
|  | 1007 | __ LoadFromOffset(kLoadWord, | 
|  | 1008 | card, | 
|  | 1009 | TR, | 
|  | 1010 | Thread::CardTableOffset<kMipsWordSize>().Int32Value()); | 
|  | 1011 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); | 
|  | 1012 | __ Addu(temp, card, temp); | 
|  | 1013 | __ Sb(card, temp, 0); | 
|  | 1014 | __ Bind(&done); | 
|  | 1015 | } | 
|  | 1016 |  | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1017 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1018 | // Don't allocate the dalvik style register pair passing. | 
|  | 1019 | blocked_register_pairs_[A1_A2] = true; | 
|  | 1020 |  | 
|  | 1021 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. | 
|  | 1022 | blocked_core_registers_[ZERO] = true; | 
|  | 1023 | blocked_core_registers_[K0] = true; | 
|  | 1024 | blocked_core_registers_[K1] = true; | 
|  | 1025 | blocked_core_registers_[GP] = true; | 
|  | 1026 | blocked_core_registers_[SP] = true; | 
|  | 1027 | blocked_core_registers_[RA] = true; | 
|  | 1028 |  | 
|  | 1029 | // AT and TMP(T8) are used as temporary/scratch registers | 
|  | 1030 | // (similar to how AT is used by MIPS assemblers). | 
|  | 1031 | blocked_core_registers_[AT] = true; | 
|  | 1032 | blocked_core_registers_[TMP] = true; | 
|  | 1033 | blocked_fpu_registers_[FTMP] = true; | 
|  | 1034 |  | 
|  | 1035 | // Reserve suspend and thread registers. | 
|  | 1036 | blocked_core_registers_[S0] = true; | 
|  | 1037 | blocked_core_registers_[TR] = true; | 
|  | 1038 |  | 
|  | 1039 | // Reserve T9 for function calls | 
|  | 1040 | blocked_core_registers_[T9] = true; | 
|  | 1041 |  | 
|  | 1042 | // Reserve odd-numbered FPU registers. | 
|  | 1043 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { | 
|  | 1044 | blocked_fpu_registers_[i] = true; | 
|  | 1045 | } | 
|  | 1046 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1047 | UpdateBlockedPairRegisters(); | 
|  | 1048 | } | 
|  | 1049 |  | 
|  | 1050 | void CodeGeneratorMIPS::UpdateBlockedPairRegisters() const { | 
|  | 1051 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { | 
|  | 1052 | MipsManagedRegister current = | 
|  | 1053 | MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); | 
|  | 1054 | if (blocked_core_registers_[current.AsRegisterPairLow()] | 
|  | 1055 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { | 
|  | 1056 | blocked_register_pairs_[i] = true; | 
|  | 1057 | } | 
|  | 1058 | } | 
|  | 1059 | } | 
|  | 1060 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1061 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 1062 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); | 
|  | 1063 | return kMipsWordSize; | 
|  | 1064 | } | 
|  | 1065 |  | 
|  | 1066 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 1067 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); | 
|  | 1068 | return kMipsWordSize; | 
|  | 1069 | } | 
|  | 1070 |  | 
|  | 1071 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 1072 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); | 
|  | 1073 | return kMipsDoublewordSize; | 
|  | 1074 | } | 
|  | 1075 |  | 
|  | 1076 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 1077 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); | 
|  | 1078 | return kMipsDoublewordSize; | 
|  | 1079 | } | 
|  | 1080 |  | 
|  | 1081 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { | 
| Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1082 | stream << Register(reg); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1083 | } | 
|  | 1084 |  | 
|  | 1085 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { | 
| Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1086 | stream << FRegister(reg); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1087 | } | 
|  | 1088 |  | 
|  | 1089 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, | 
|  | 1090 | HInstruction* instruction, | 
|  | 1091 | uint32_t dex_pc, | 
|  | 1092 | SlowPathCode* slow_path) { | 
|  | 1093 | InvokeRuntime(GetThreadOffset<kMipsWordSize>(entrypoint).Int32Value(), | 
|  | 1094 | instruction, | 
|  | 1095 | dex_pc, | 
|  | 1096 | slow_path, | 
|  | 1097 | IsDirectEntrypoint(entrypoint)); | 
|  | 1098 | } | 
|  | 1099 |  | 
|  | 1100 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; | 
|  | 1101 |  | 
|  | 1102 | void CodeGeneratorMIPS::InvokeRuntime(int32_t entry_point_offset, | 
|  | 1103 | HInstruction* instruction, | 
|  | 1104 | uint32_t dex_pc, | 
|  | 1105 | SlowPathCode* slow_path, | 
|  | 1106 | bool is_direct_entrypoint) { | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1107 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); | 
|  | 1108 | __ Jalr(T9); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1109 | if (is_direct_entrypoint) { | 
|  | 1110 | // Reserve argument space on stack (for $a0-$a3) for | 
|  | 1111 | // entrypoints that directly reference native implementations. | 
|  | 1112 | // Called function may use this space to store $a0-$a3 regs. | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1113 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);  // Single instruction in delay slot. | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1114 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1115 | } else { | 
|  | 1116 | __ Nop();  // In delay slot. | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1117 | } | 
|  | 1118 | RecordPcInfo(instruction, dex_pc, slow_path); | 
|  | 1119 | } | 
|  | 1120 |  | 
|  | 1121 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, | 
|  | 1122 | Register class_reg) { | 
|  | 1123 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); | 
|  | 1124 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); | 
|  | 1125 | __ Blt(TMP, AT, slow_path->GetEntryLabel()); | 
|  | 1126 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. | 
|  | 1127 | __ Sync(0); | 
|  | 1128 | __ Bind(slow_path->GetExitLabel()); | 
|  | 1129 | } | 
|  | 1130 |  | 
|  | 1131 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { | 
|  | 1132 | __ Sync(0);  // Only stype 0 is supported. | 
|  | 1133 | } | 
|  | 1134 |  | 
|  | 1135 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, | 
|  | 1136 | HBasicBlock* successor) { | 
|  | 1137 | SuspendCheckSlowPathMIPS* slow_path = | 
|  | 1138 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor); | 
|  | 1139 | codegen_->AddSlowPath(slow_path); | 
|  | 1140 |  | 
|  | 1141 | __ LoadFromOffset(kLoadUnsignedHalfword, | 
|  | 1142 | TMP, | 
|  | 1143 | TR, | 
|  | 1144 | Thread::ThreadFlagsOffset<kMipsWordSize>().Int32Value()); | 
|  | 1145 | if (successor == nullptr) { | 
|  | 1146 | __ Bnez(TMP, slow_path->GetEntryLabel()); | 
|  | 1147 | __ Bind(slow_path->GetReturnLabel()); | 
|  | 1148 | } else { | 
|  | 1149 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); | 
|  | 1150 | __ B(slow_path->GetEntryLabel()); | 
|  | 1151 | // slow_path will return to GetLabelOf(successor). | 
|  | 1152 | } | 
|  | 1153 | } | 
|  | 1154 |  | 
|  | 1155 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, | 
|  | 1156 | CodeGeneratorMIPS* codegen) | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1157 | : InstructionCodeGenerator(graph, codegen), | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1158 | assembler_(codegen->GetAssembler()), | 
|  | 1159 | codegen_(codegen) {} | 
|  | 1160 |  | 
|  | 1161 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { | 
|  | 1162 | DCHECK_EQ(instruction->InputCount(), 2U); | 
|  | 1163 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 1164 | Primitive::Type type = instruction->GetResultType(); | 
|  | 1165 | switch (type) { | 
|  | 1166 | case Primitive::kPrimInt: { | 
|  | 1167 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1168 | HInstruction* right = instruction->InputAt(1); | 
|  | 1169 | bool can_use_imm = false; | 
|  | 1170 | if (right->IsConstant()) { | 
|  | 1171 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); | 
|  | 1172 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { | 
|  | 1173 | can_use_imm = IsUint<16>(imm); | 
|  | 1174 | } else if (instruction->IsAdd()) { | 
|  | 1175 | can_use_imm = IsInt<16>(imm); | 
|  | 1176 | } else { | 
|  | 1177 | DCHECK(instruction->IsSub()); | 
|  | 1178 | can_use_imm = IsInt<16>(-imm); | 
|  | 1179 | } | 
|  | 1180 | } | 
|  | 1181 | if (can_use_imm) | 
|  | 1182 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); | 
|  | 1183 | else | 
|  | 1184 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 1185 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1186 | break; | 
|  | 1187 | } | 
|  | 1188 |  | 
|  | 1189 | case Primitive::kPrimLong: { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1190 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1191 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 1192 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1193 | break; | 
|  | 1194 | } | 
|  | 1195 |  | 
|  | 1196 | case Primitive::kPrimFloat: | 
|  | 1197 | case Primitive::kPrimDouble: | 
|  | 1198 | DCHECK(instruction->IsAdd() || instruction->IsSub()); | 
|  | 1199 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 1200 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 1201 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 1202 | break; | 
|  | 1203 |  | 
|  | 1204 | default: | 
|  | 1205 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; | 
|  | 1206 | } | 
|  | 1207 | } | 
|  | 1208 |  | 
|  | 1209 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { | 
|  | 1210 | Primitive::Type type = instruction->GetType(); | 
|  | 1211 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1212 |  | 
|  | 1213 | switch (type) { | 
|  | 1214 | case Primitive::kPrimInt: { | 
|  | 1215 | Register dst = locations->Out().AsRegister<Register>(); | 
|  | 1216 | Register lhs = locations->InAt(0).AsRegister<Register>(); | 
|  | 1217 | Location rhs_location = locations->InAt(1); | 
|  | 1218 |  | 
|  | 1219 | Register rhs_reg = ZERO; | 
|  | 1220 | int32_t rhs_imm = 0; | 
|  | 1221 | bool use_imm = rhs_location.IsConstant(); | 
|  | 1222 | if (use_imm) { | 
|  | 1223 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); | 
|  | 1224 | } else { | 
|  | 1225 | rhs_reg = rhs_location.AsRegister<Register>(); | 
|  | 1226 | } | 
|  | 1227 |  | 
|  | 1228 | if (instruction->IsAnd()) { | 
|  | 1229 | if (use_imm) | 
|  | 1230 | __ Andi(dst, lhs, rhs_imm); | 
|  | 1231 | else | 
|  | 1232 | __ And(dst, lhs, rhs_reg); | 
|  | 1233 | } else if (instruction->IsOr()) { | 
|  | 1234 | if (use_imm) | 
|  | 1235 | __ Ori(dst, lhs, rhs_imm); | 
|  | 1236 | else | 
|  | 1237 | __ Or(dst, lhs, rhs_reg); | 
|  | 1238 | } else if (instruction->IsXor()) { | 
|  | 1239 | if (use_imm) | 
|  | 1240 | __ Xori(dst, lhs, rhs_imm); | 
|  | 1241 | else | 
|  | 1242 | __ Xor(dst, lhs, rhs_reg); | 
|  | 1243 | } else if (instruction->IsAdd()) { | 
|  | 1244 | if (use_imm) | 
|  | 1245 | __ Addiu(dst, lhs, rhs_imm); | 
|  | 1246 | else | 
|  | 1247 | __ Addu(dst, lhs, rhs_reg); | 
|  | 1248 | } else { | 
|  | 1249 | DCHECK(instruction->IsSub()); | 
|  | 1250 | if (use_imm) | 
|  | 1251 | __ Addiu(dst, lhs, -rhs_imm); | 
|  | 1252 | else | 
|  | 1253 | __ Subu(dst, lhs, rhs_reg); | 
|  | 1254 | } | 
|  | 1255 | break; | 
|  | 1256 | } | 
|  | 1257 |  | 
|  | 1258 | case Primitive::kPrimLong: { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1259 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); | 
|  | 1260 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); | 
|  | 1261 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); | 
|  | 1262 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1263 | Location rhs_location = locations->InAt(1); | 
|  | 1264 | bool use_imm = rhs_location.IsConstant(); | 
|  | 1265 | if (!use_imm) { | 
|  | 1266 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); | 
|  | 1267 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); | 
|  | 1268 | if (instruction->IsAnd()) { | 
|  | 1269 | __ And(dst_low, lhs_low, rhs_low); | 
|  | 1270 | __ And(dst_high, lhs_high, rhs_high); | 
|  | 1271 | } else if (instruction->IsOr()) { | 
|  | 1272 | __ Or(dst_low, lhs_low, rhs_low); | 
|  | 1273 | __ Or(dst_high, lhs_high, rhs_high); | 
|  | 1274 | } else if (instruction->IsXor()) { | 
|  | 1275 | __ Xor(dst_low, lhs_low, rhs_low); | 
|  | 1276 | __ Xor(dst_high, lhs_high, rhs_high); | 
|  | 1277 | } else if (instruction->IsAdd()) { | 
|  | 1278 | if (lhs_low == rhs_low) { | 
|  | 1279 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. | 
|  | 1280 | __ Slt(TMP, lhs_low, ZERO); | 
|  | 1281 | __ Addu(dst_low, lhs_low, rhs_low); | 
|  | 1282 | } else { | 
|  | 1283 | __ Addu(dst_low, lhs_low, rhs_low); | 
|  | 1284 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. | 
|  | 1285 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); | 
|  | 1286 | } | 
|  | 1287 | __ Addu(dst_high, lhs_high, rhs_high); | 
|  | 1288 | __ Addu(dst_high, dst_high, TMP); | 
|  | 1289 | } else { | 
|  | 1290 | DCHECK(instruction->IsSub()); | 
|  | 1291 | __ Sltu(TMP, lhs_low, rhs_low); | 
|  | 1292 | __ Subu(dst_low, lhs_low, rhs_low); | 
|  | 1293 | __ Subu(dst_high, lhs_high, rhs_high); | 
|  | 1294 | __ Subu(dst_high, dst_high, TMP); | 
|  | 1295 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1296 | } else { | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1297 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); | 
|  | 1298 | if (instruction->IsOr()) { | 
|  | 1299 | uint32_t low = Low32Bits(value); | 
|  | 1300 | uint32_t high = High32Bits(value); | 
|  | 1301 | if (IsUint<16>(low)) { | 
|  | 1302 | if (dst_low != lhs_low || low != 0) { | 
|  | 1303 | __ Ori(dst_low, lhs_low, low); | 
|  | 1304 | } | 
|  | 1305 | } else { | 
|  | 1306 | __ LoadConst32(TMP, low); | 
|  | 1307 | __ Or(dst_low, lhs_low, TMP); | 
|  | 1308 | } | 
|  | 1309 | if (IsUint<16>(high)) { | 
|  | 1310 | if (dst_high != lhs_high || high != 0) { | 
|  | 1311 | __ Ori(dst_high, lhs_high, high); | 
|  | 1312 | } | 
|  | 1313 | } else { | 
|  | 1314 | if (high != low) { | 
|  | 1315 | __ LoadConst32(TMP, high); | 
|  | 1316 | } | 
|  | 1317 | __ Or(dst_high, lhs_high, TMP); | 
|  | 1318 | } | 
|  | 1319 | } else if (instruction->IsXor()) { | 
|  | 1320 | uint32_t low = Low32Bits(value); | 
|  | 1321 | uint32_t high = High32Bits(value); | 
|  | 1322 | if (IsUint<16>(low)) { | 
|  | 1323 | if (dst_low != lhs_low || low != 0) { | 
|  | 1324 | __ Xori(dst_low, lhs_low, low); | 
|  | 1325 | } | 
|  | 1326 | } else { | 
|  | 1327 | __ LoadConst32(TMP, low); | 
|  | 1328 | __ Xor(dst_low, lhs_low, TMP); | 
|  | 1329 | } | 
|  | 1330 | if (IsUint<16>(high)) { | 
|  | 1331 | if (dst_high != lhs_high || high != 0) { | 
|  | 1332 | __ Xori(dst_high, lhs_high, high); | 
|  | 1333 | } | 
|  | 1334 | } else { | 
|  | 1335 | if (high != low) { | 
|  | 1336 | __ LoadConst32(TMP, high); | 
|  | 1337 | } | 
|  | 1338 | __ Xor(dst_high, lhs_high, TMP); | 
|  | 1339 | } | 
|  | 1340 | } else if (instruction->IsAnd()) { | 
|  | 1341 | uint32_t low = Low32Bits(value); | 
|  | 1342 | uint32_t high = High32Bits(value); | 
|  | 1343 | if (IsUint<16>(low)) { | 
|  | 1344 | __ Andi(dst_low, lhs_low, low); | 
|  | 1345 | } else if (low != 0xFFFFFFFF) { | 
|  | 1346 | __ LoadConst32(TMP, low); | 
|  | 1347 | __ And(dst_low, lhs_low, TMP); | 
|  | 1348 | } else if (dst_low != lhs_low) { | 
|  | 1349 | __ Move(dst_low, lhs_low); | 
|  | 1350 | } | 
|  | 1351 | if (IsUint<16>(high)) { | 
|  | 1352 | __ Andi(dst_high, lhs_high, high); | 
|  | 1353 | } else if (high != 0xFFFFFFFF) { | 
|  | 1354 | if (high != low) { | 
|  | 1355 | __ LoadConst32(TMP, high); | 
|  | 1356 | } | 
|  | 1357 | __ And(dst_high, lhs_high, TMP); | 
|  | 1358 | } else if (dst_high != lhs_high) { | 
|  | 1359 | __ Move(dst_high, lhs_high); | 
|  | 1360 | } | 
|  | 1361 | } else { | 
|  | 1362 | if (instruction->IsSub()) { | 
|  | 1363 | value = -value; | 
|  | 1364 | } else { | 
|  | 1365 | DCHECK(instruction->IsAdd()); | 
|  | 1366 | } | 
|  | 1367 | int32_t low = Low32Bits(value); | 
|  | 1368 | int32_t high = High32Bits(value); | 
|  | 1369 | if (IsInt<16>(low)) { | 
|  | 1370 | if (dst_low != lhs_low || low != 0) { | 
|  | 1371 | __ Addiu(dst_low, lhs_low, low); | 
|  | 1372 | } | 
|  | 1373 | if (low != 0) { | 
|  | 1374 | __ Sltiu(AT, dst_low, low); | 
|  | 1375 | } | 
|  | 1376 | } else { | 
|  | 1377 | __ LoadConst32(TMP, low); | 
|  | 1378 | __ Addu(dst_low, lhs_low, TMP); | 
|  | 1379 | __ Sltu(AT, dst_low, TMP); | 
|  | 1380 | } | 
|  | 1381 | if (IsInt<16>(high)) { | 
|  | 1382 | if (dst_high != lhs_high || high != 0) { | 
|  | 1383 | __ Addiu(dst_high, lhs_high, high); | 
|  | 1384 | } | 
|  | 1385 | } else { | 
|  | 1386 | if (high != low) { | 
|  | 1387 | __ LoadConst32(TMP, high); | 
|  | 1388 | } | 
|  | 1389 | __ Addu(dst_high, lhs_high, TMP); | 
|  | 1390 | } | 
|  | 1391 | if (low != 0) { | 
|  | 1392 | __ Addu(dst_high, dst_high, AT); | 
|  | 1393 | } | 
|  | 1394 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1395 | } | 
|  | 1396 | break; | 
|  | 1397 | } | 
|  | 1398 |  | 
|  | 1399 | case Primitive::kPrimFloat: | 
|  | 1400 | case Primitive::kPrimDouble: { | 
|  | 1401 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 1402 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 1403 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); | 
|  | 1404 | if (instruction->IsAdd()) { | 
|  | 1405 | if (type == Primitive::kPrimFloat) { | 
|  | 1406 | __ AddS(dst, lhs, rhs); | 
|  | 1407 | } else { | 
|  | 1408 | __ AddD(dst, lhs, rhs); | 
|  | 1409 | } | 
|  | 1410 | } else { | 
|  | 1411 | DCHECK(instruction->IsSub()); | 
|  | 1412 | if (type == Primitive::kPrimFloat) { | 
|  | 1413 | __ SubS(dst, lhs, rhs); | 
|  | 1414 | } else { | 
|  | 1415 | __ SubD(dst, lhs, rhs); | 
|  | 1416 | } | 
|  | 1417 | } | 
|  | 1418 | break; | 
|  | 1419 | } | 
|  | 1420 |  | 
|  | 1421 | default: | 
|  | 1422 | LOG(FATAL) << "Unexpected binary operation type " << type; | 
|  | 1423 | } | 
|  | 1424 | } | 
|  | 1425 |  | 
|  | 1426 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1427 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1428 |  | 
|  | 1429 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); | 
|  | 1430 | Primitive::Type type = instr->GetResultType(); | 
|  | 1431 | switch (type) { | 
|  | 1432 | case Primitive::kPrimInt: | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1433 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1434 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); | 
|  | 1435 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1436 | break; | 
|  | 1437 | case Primitive::kPrimLong: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1438 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1439 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); | 
|  | 1440 | locations->SetOut(Location::RequiresRegister()); | 
|  | 1441 | break; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1442 | default: | 
|  | 1443 | LOG(FATAL) << "Unexpected shift type " << type; | 
|  | 1444 | } | 
|  | 1445 | } | 
|  | 1446 |  | 
|  | 1447 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; | 
|  | 1448 |  | 
|  | 1449 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1450 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1451 | LocationSummary* locations = instr->GetLocations(); | 
|  | 1452 | Primitive::Type type = instr->GetType(); | 
|  | 1453 |  | 
|  | 1454 | Location rhs_location = locations->InAt(1); | 
|  | 1455 | bool use_imm = rhs_location.IsConstant(); | 
|  | 1456 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); | 
|  | 1457 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1458 | const uint32_t shift_mask = (type == Primitive::kPrimInt) | 
|  | 1459 | ? kMaxIntShiftValue | 
|  | 1460 | : kMaxLongShiftValue; | 
|  | 1461 | const uint32_t shift_value = rhs_imm & shift_mask; | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1462 | // Are the INS (Insert Bit Field) and ROTR instructions supported? | 
|  | 1463 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1464 |  | 
|  | 1465 | switch (type) { | 
|  | 1466 | case Primitive::kPrimInt: { | 
|  | 1467 | Register dst = locations->Out().AsRegister<Register>(); | 
|  | 1468 | Register lhs = locations->InAt(0).AsRegister<Register>(); | 
|  | 1469 | if (use_imm) { | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1470 | if (shift_value == 0) { | 
|  | 1471 | if (dst != lhs) { | 
|  | 1472 | __ Move(dst, lhs); | 
|  | 1473 | } | 
|  | 1474 | } else if (instr->IsShl()) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1475 | __ Sll(dst, lhs, shift_value); | 
|  | 1476 | } else if (instr->IsShr()) { | 
|  | 1477 | __ Sra(dst, lhs, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1478 | } else if (instr->IsUShr()) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1479 | __ Srl(dst, lhs, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1480 | } else { | 
|  | 1481 | if (has_ins_rotr) { | 
|  | 1482 | __ Rotr(dst, lhs, shift_value); | 
|  | 1483 | } else { | 
|  | 1484 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); | 
|  | 1485 | __ Srl(dst, lhs, shift_value); | 
|  | 1486 | __ Or(dst, dst, TMP); | 
|  | 1487 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1488 | } | 
|  | 1489 | } else { | 
|  | 1490 | if (instr->IsShl()) { | 
|  | 1491 | __ Sllv(dst, lhs, rhs_reg); | 
|  | 1492 | } else if (instr->IsShr()) { | 
|  | 1493 | __ Srav(dst, lhs, rhs_reg); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1494 | } else if (instr->IsUShr()) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1495 | __ Srlv(dst, lhs, rhs_reg); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1496 | } else { | 
|  | 1497 | if (has_ins_rotr) { | 
|  | 1498 | __ Rotrv(dst, lhs, rhs_reg); | 
|  | 1499 | } else { | 
|  | 1500 | __ Subu(TMP, ZERO, rhs_reg); | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1501 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so | 
|  | 1502 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case | 
|  | 1503 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out | 
|  | 1504 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, | 
|  | 1505 | // IOW, the OR'd values are equal. | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1506 | __ Sllv(TMP, lhs, TMP); | 
|  | 1507 | __ Srlv(dst, lhs, rhs_reg); | 
|  | 1508 | __ Or(dst, dst, TMP); | 
|  | 1509 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1510 | } | 
|  | 1511 | } | 
|  | 1512 | break; | 
|  | 1513 | } | 
|  | 1514 |  | 
|  | 1515 | case Primitive::kPrimLong: { | 
|  | 1516 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); | 
|  | 1517 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); | 
|  | 1518 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); | 
|  | 1519 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); | 
|  | 1520 | if (use_imm) { | 
|  | 1521 | if (shift_value == 0) { | 
|  | 1522 | codegen_->Move64(locations->Out(), locations->InAt(0)); | 
|  | 1523 | } else if (shift_value < kMipsBitsPerWord) { | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1524 | if (has_ins_rotr) { | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1525 | if (instr->IsShl()) { | 
|  | 1526 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); | 
|  | 1527 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); | 
|  | 1528 | __ Sll(dst_low, lhs_low, shift_value); | 
|  | 1529 | } else if (instr->IsShr()) { | 
|  | 1530 | __ Srl(dst_low, lhs_low, shift_value); | 
|  | 1531 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); | 
|  | 1532 | __ Sra(dst_high, lhs_high, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1533 | } else if (instr->IsUShr()) { | 
|  | 1534 | __ Srl(dst_low, lhs_low, shift_value); | 
|  | 1535 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); | 
|  | 1536 | __ Srl(dst_high, lhs_high, shift_value); | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1537 | } else { | 
|  | 1538 | __ Srl(dst_low, lhs_low, shift_value); | 
|  | 1539 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); | 
|  | 1540 | __ Srl(dst_high, lhs_high, shift_value); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1541 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1542 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1543 | } else { | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1544 | if (instr->IsShl()) { | 
|  | 1545 | __ Sll(dst_low, lhs_low, shift_value); | 
|  | 1546 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); | 
|  | 1547 | __ Sll(dst_high, lhs_high, shift_value); | 
|  | 1548 | __ Or(dst_high, dst_high, TMP); | 
|  | 1549 | } else if (instr->IsShr()) { | 
|  | 1550 | __ Sra(dst_high, lhs_high, shift_value); | 
|  | 1551 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); | 
|  | 1552 | __ Srl(dst_low, lhs_low, shift_value); | 
|  | 1553 | __ Or(dst_low, dst_low, TMP); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1554 | } else if (instr->IsUShr()) { | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1555 | __ Srl(dst_high, lhs_high, shift_value); | 
|  | 1556 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); | 
|  | 1557 | __ Srl(dst_low, lhs_low, shift_value); | 
|  | 1558 | __ Or(dst_low, dst_low, TMP); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1559 | } else { | 
|  | 1560 | __ Srl(TMP, lhs_low, shift_value); | 
|  | 1561 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); | 
|  | 1562 | __ Or(dst_low, dst_low, TMP); | 
|  | 1563 | __ Srl(TMP, lhs_high, shift_value); | 
|  | 1564 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); | 
|  | 1565 | __ Or(dst_high, dst_high, TMP); | 
| Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1566 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1567 | } | 
|  | 1568 | } else { | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1569 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1570 | if (instr->IsShl()) { | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1571 | __ Sll(dst_high, lhs_low, shift_value_high); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1572 | __ Move(dst_low, ZERO); | 
|  | 1573 | } else if (instr->IsShr()) { | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1574 | __ Sra(dst_low, lhs_high, shift_value_high); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1575 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1576 | } else if (instr->IsUShr()) { | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1577 | __ Srl(dst_low, lhs_high, shift_value_high); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1578 | __ Move(dst_high, ZERO); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1579 | } else { | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1580 | if (shift_value == kMipsBitsPerWord) { | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1581 | // 64-bit rotation by 32 is just a swap. | 
|  | 1582 | __ Move(dst_low, lhs_high); | 
|  | 1583 | __ Move(dst_high, lhs_low); | 
|  | 1584 | } else { | 
|  | 1585 | if (has_ins_rotr) { | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1586 | __ Srl(dst_low, lhs_high, shift_value_high); | 
|  | 1587 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); | 
|  | 1588 | __ Srl(dst_high, lhs_low, shift_value_high); | 
|  | 1589 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1590 | } else { | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1591 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); | 
|  | 1592 | __ Srl(dst_low, lhs_high, shift_value_high); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1593 | __ Or(dst_low, dst_low, TMP); | 
| Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1594 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); | 
|  | 1595 | __ Srl(dst_high, lhs_low, shift_value_high); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1596 | __ Or(dst_high, dst_high, TMP); | 
|  | 1597 | } | 
|  | 1598 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1599 | } | 
|  | 1600 | } | 
|  | 1601 | } else { | 
|  | 1602 | MipsLabel done; | 
|  | 1603 | if (instr->IsShl()) { | 
|  | 1604 | __ Sllv(dst_low, lhs_low, rhs_reg); | 
|  | 1605 | __ Nor(AT, ZERO, rhs_reg); | 
|  | 1606 | __ Srl(TMP, lhs_low, 1); | 
|  | 1607 | __ Srlv(TMP, TMP, AT); | 
|  | 1608 | __ Sllv(dst_high, lhs_high, rhs_reg); | 
|  | 1609 | __ Or(dst_high, dst_high, TMP); | 
|  | 1610 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); | 
|  | 1611 | __ Beqz(TMP, &done); | 
|  | 1612 | __ Move(dst_high, dst_low); | 
|  | 1613 | __ Move(dst_low, ZERO); | 
|  | 1614 | } else if (instr->IsShr()) { | 
|  | 1615 | __ Srav(dst_high, lhs_high, rhs_reg); | 
|  | 1616 | __ Nor(AT, ZERO, rhs_reg); | 
|  | 1617 | __ Sll(TMP, lhs_high, 1); | 
|  | 1618 | __ Sllv(TMP, TMP, AT); | 
|  | 1619 | __ Srlv(dst_low, lhs_low, rhs_reg); | 
|  | 1620 | __ Or(dst_low, dst_low, TMP); | 
|  | 1621 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); | 
|  | 1622 | __ Beqz(TMP, &done); | 
|  | 1623 | __ Move(dst_low, dst_high); | 
|  | 1624 | __ Sra(dst_high, dst_high, 31); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1625 | } else if (instr->IsUShr()) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1626 | __ Srlv(dst_high, lhs_high, rhs_reg); | 
|  | 1627 | __ Nor(AT, ZERO, rhs_reg); | 
|  | 1628 | __ Sll(TMP, lhs_high, 1); | 
|  | 1629 | __ Sllv(TMP, TMP, AT); | 
|  | 1630 | __ Srlv(dst_low, lhs_low, rhs_reg); | 
|  | 1631 | __ Or(dst_low, dst_low, TMP); | 
|  | 1632 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); | 
|  | 1633 | __ Beqz(TMP, &done); | 
|  | 1634 | __ Move(dst_low, dst_high); | 
|  | 1635 | __ Move(dst_high, ZERO); | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1636 | } else { | 
|  | 1637 | __ Nor(AT, ZERO, rhs_reg); | 
|  | 1638 | __ Srlv(TMP, lhs_low, rhs_reg); | 
|  | 1639 | __ Sll(dst_low, lhs_high, 1); | 
|  | 1640 | __ Sllv(dst_low, dst_low, AT); | 
|  | 1641 | __ Or(dst_low, dst_low, TMP); | 
|  | 1642 | __ Srlv(TMP, lhs_high, rhs_reg); | 
|  | 1643 | __ Sll(dst_high, lhs_low, 1); | 
|  | 1644 | __ Sllv(dst_high, dst_high, AT); | 
|  | 1645 | __ Or(dst_high, dst_high, TMP); | 
|  | 1646 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); | 
|  | 1647 | __ Beqz(TMP, &done); | 
|  | 1648 | __ Move(TMP, dst_high); | 
|  | 1649 | __ Move(dst_high, dst_low); | 
|  | 1650 | __ Move(dst_low, TMP); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1651 | } | 
|  | 1652 | __ Bind(&done); | 
|  | 1653 | } | 
|  | 1654 | break; | 
|  | 1655 | } | 
|  | 1656 |  | 
|  | 1657 | default: | 
|  | 1658 | LOG(FATAL) << "Unexpected shift operation type " << type; | 
|  | 1659 | } | 
|  | 1660 | } | 
|  | 1661 |  | 
|  | 1662 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { | 
|  | 1663 | HandleBinaryOp(instruction); | 
|  | 1664 | } | 
|  | 1665 |  | 
|  | 1666 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { | 
|  | 1667 | HandleBinaryOp(instruction); | 
|  | 1668 | } | 
|  | 1669 |  | 
|  | 1670 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { | 
|  | 1671 | HandleBinaryOp(instruction); | 
|  | 1672 | } | 
|  | 1673 |  | 
|  | 1674 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { | 
|  | 1675 | HandleBinaryOp(instruction); | 
|  | 1676 | } | 
|  | 1677 |  | 
|  | 1678 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { | 
|  | 1679 | LocationSummary* locations = | 
|  | 1680 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 1681 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1682 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 1683 | if (Primitive::IsFloatingPointType(instruction->GetType())) { | 
|  | 1684 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 1685 | } else { | 
|  | 1686 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1687 | } | 
|  | 1688 | } | 
|  | 1689 |  | 
|  | 1690 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { | 
|  | 1691 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1692 | Register obj = locations->InAt(0).AsRegister<Register>(); | 
|  | 1693 | Location index = locations->InAt(1); | 
|  | 1694 | Primitive::Type type = instruction->GetType(); | 
|  | 1695 |  | 
|  | 1696 | switch (type) { | 
|  | 1697 | case Primitive::kPrimBoolean: { | 
|  | 1698 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); | 
|  | 1699 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 1700 | if (index.IsConstant()) { | 
|  | 1701 | size_t offset = | 
|  | 1702 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; | 
|  | 1703 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); | 
|  | 1704 | } else { | 
|  | 1705 | __ Addu(TMP, obj, index.AsRegister<Register>()); | 
|  | 1706 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); | 
|  | 1707 | } | 
|  | 1708 | break; | 
|  | 1709 | } | 
|  | 1710 |  | 
|  | 1711 | case Primitive::kPrimByte: { | 
|  | 1712 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); | 
|  | 1713 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 1714 | if (index.IsConstant()) { | 
|  | 1715 | size_t offset = | 
|  | 1716 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; | 
|  | 1717 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); | 
|  | 1718 | } else { | 
|  | 1719 | __ Addu(TMP, obj, index.AsRegister<Register>()); | 
|  | 1720 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset); | 
|  | 1721 | } | 
|  | 1722 | break; | 
|  | 1723 | } | 
|  | 1724 |  | 
|  | 1725 | case Primitive::kPrimShort: { | 
|  | 1726 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); | 
|  | 1727 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 1728 | if (index.IsConstant()) { | 
|  | 1729 | size_t offset = | 
|  | 1730 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; | 
|  | 1731 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); | 
|  | 1732 | } else { | 
|  | 1733 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); | 
|  | 1734 | __ Addu(TMP, obj, TMP); | 
|  | 1735 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset); | 
|  | 1736 | } | 
|  | 1737 | break; | 
|  | 1738 | } | 
|  | 1739 |  | 
|  | 1740 | case Primitive::kPrimChar: { | 
|  | 1741 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); | 
|  | 1742 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 1743 | if (index.IsConstant()) { | 
|  | 1744 | size_t offset = | 
|  | 1745 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; | 
|  | 1746 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); | 
|  | 1747 | } else { | 
|  | 1748 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); | 
|  | 1749 | __ Addu(TMP, obj, TMP); | 
|  | 1750 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); | 
|  | 1751 | } | 
|  | 1752 | break; | 
|  | 1753 | } | 
|  | 1754 |  | 
|  | 1755 | case Primitive::kPrimInt: | 
|  | 1756 | case Primitive::kPrimNot: { | 
|  | 1757 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); | 
|  | 1758 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); | 
|  | 1759 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 1760 | if (index.IsConstant()) { | 
|  | 1761 | size_t offset = | 
|  | 1762 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
|  | 1763 | __ LoadFromOffset(kLoadWord, out, obj, offset); | 
|  | 1764 | } else { | 
|  | 1765 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); | 
|  | 1766 | __ Addu(TMP, obj, TMP); | 
|  | 1767 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset); | 
|  | 1768 | } | 
|  | 1769 | break; | 
|  | 1770 | } | 
|  | 1771 |  | 
|  | 1772 | case Primitive::kPrimLong: { | 
|  | 1773 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); | 
|  | 1774 | Register out = locations->Out().AsRegisterPairLow<Register>(); | 
|  | 1775 | if (index.IsConstant()) { | 
|  | 1776 | size_t offset = | 
|  | 1777 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
|  | 1778 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset); | 
|  | 1779 | } else { | 
|  | 1780 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); | 
|  | 1781 | __ Addu(TMP, obj, TMP); | 
|  | 1782 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset); | 
|  | 1783 | } | 
|  | 1784 | break; | 
|  | 1785 | } | 
|  | 1786 |  | 
|  | 1787 | case Primitive::kPrimFloat: { | 
|  | 1788 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); | 
|  | 1789 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 1790 | if (index.IsConstant()) { | 
|  | 1791 | size_t offset = | 
|  | 1792 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
|  | 1793 | __ LoadSFromOffset(out, obj, offset); | 
|  | 1794 | } else { | 
|  | 1795 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); | 
|  | 1796 | __ Addu(TMP, obj, TMP); | 
|  | 1797 | __ LoadSFromOffset(out, TMP, data_offset); | 
|  | 1798 | } | 
|  | 1799 | break; | 
|  | 1800 | } | 
|  | 1801 |  | 
|  | 1802 | case Primitive::kPrimDouble: { | 
|  | 1803 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); | 
|  | 1804 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 1805 | if (index.IsConstant()) { | 
|  | 1806 | size_t offset = | 
|  | 1807 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
|  | 1808 | __ LoadDFromOffset(out, obj, offset); | 
|  | 1809 | } else { | 
|  | 1810 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); | 
|  | 1811 | __ Addu(TMP, obj, TMP); | 
|  | 1812 | __ LoadDFromOffset(out, TMP, data_offset); | 
|  | 1813 | } | 
|  | 1814 | break; | 
|  | 1815 | } | 
|  | 1816 |  | 
|  | 1817 | case Primitive::kPrimVoid: | 
|  | 1818 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); | 
|  | 1819 | UNREACHABLE(); | 
|  | 1820 | } | 
|  | 1821 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1822 | } | 
|  | 1823 |  | 
|  | 1824 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { | 
|  | 1825 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 1826 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1827 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1828 | } | 
|  | 1829 |  | 
|  | 1830 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { | 
|  | 1831 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1832 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); | 
|  | 1833 | Register obj = locations->InAt(0).AsRegister<Register>(); | 
|  | 1834 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 1835 | __ LoadFromOffset(kLoadWord, out, obj, offset); | 
|  | 1836 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1837 | } | 
|  | 1838 |  | 
|  | 1839 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { | 
| Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 1840 | bool needs_runtime_call = instruction->NeedsTypeCheck(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1841 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( | 
|  | 1842 | instruction, | 
| Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 1843 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); | 
|  | 1844 | if (needs_runtime_call) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1845 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 1846 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 1847 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
|  | 1848 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); | 
|  | 1849 | } else { | 
|  | 1850 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1851 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 1852 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { | 
|  | 1853 | locations->SetInAt(2, Location::RequiresFpuRegister()); | 
|  | 1854 | } else { | 
|  | 1855 | locations->SetInAt(2, Location::RequiresRegister()); | 
|  | 1856 | } | 
|  | 1857 | } | 
|  | 1858 | } | 
|  | 1859 |  | 
|  | 1860 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { | 
|  | 1861 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1862 | Register obj = locations->InAt(0).AsRegister<Register>(); | 
|  | 1863 | Location index = locations->InAt(1); | 
|  | 1864 | Primitive::Type value_type = instruction->GetComponentType(); | 
|  | 1865 | bool needs_runtime_call = locations->WillCall(); | 
|  | 1866 | bool needs_write_barrier = | 
|  | 1867 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); | 
|  | 1868 |  | 
|  | 1869 | switch (value_type) { | 
|  | 1870 | case Primitive::kPrimBoolean: | 
|  | 1871 | case Primitive::kPrimByte: { | 
|  | 1872 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); | 
|  | 1873 | Register value = locations->InAt(2).AsRegister<Register>(); | 
|  | 1874 | if (index.IsConstant()) { | 
|  | 1875 | size_t offset = | 
|  | 1876 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; | 
|  | 1877 | __ StoreToOffset(kStoreByte, value, obj, offset); | 
|  | 1878 | } else { | 
|  | 1879 | __ Addu(TMP, obj, index.AsRegister<Register>()); | 
|  | 1880 | __ StoreToOffset(kStoreByte, value, TMP, data_offset); | 
|  | 1881 | } | 
|  | 1882 | break; | 
|  | 1883 | } | 
|  | 1884 |  | 
|  | 1885 | case Primitive::kPrimShort: | 
|  | 1886 | case Primitive::kPrimChar: { | 
|  | 1887 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); | 
|  | 1888 | Register value = locations->InAt(2).AsRegister<Register>(); | 
|  | 1889 | if (index.IsConstant()) { | 
|  | 1890 | size_t offset = | 
|  | 1891 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; | 
|  | 1892 | __ StoreToOffset(kStoreHalfword, value, obj, offset); | 
|  | 1893 | } else { | 
|  | 1894 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); | 
|  | 1895 | __ Addu(TMP, obj, TMP); | 
|  | 1896 | __ StoreToOffset(kStoreHalfword, value, TMP, data_offset); | 
|  | 1897 | } | 
|  | 1898 | break; | 
|  | 1899 | } | 
|  | 1900 |  | 
|  | 1901 | case Primitive::kPrimInt: | 
|  | 1902 | case Primitive::kPrimNot: { | 
|  | 1903 | if (!needs_runtime_call) { | 
|  | 1904 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); | 
|  | 1905 | Register value = locations->InAt(2).AsRegister<Register>(); | 
|  | 1906 | if (index.IsConstant()) { | 
|  | 1907 | size_t offset = | 
|  | 1908 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
|  | 1909 | __ StoreToOffset(kStoreWord, value, obj, offset); | 
|  | 1910 | } else { | 
|  | 1911 | DCHECK(index.IsRegister()) << index; | 
|  | 1912 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); | 
|  | 1913 | __ Addu(TMP, obj, TMP); | 
|  | 1914 | __ StoreToOffset(kStoreWord, value, TMP, data_offset); | 
|  | 1915 | } | 
|  | 1916 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1917 | if (needs_write_barrier) { | 
|  | 1918 | DCHECK_EQ(value_type, Primitive::kPrimNot); | 
|  | 1919 | codegen_->MarkGCCard(obj, value); | 
|  | 1920 | } | 
|  | 1921 | } else { | 
|  | 1922 | DCHECK_EQ(value_type, Primitive::kPrimNot); | 
|  | 1923 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), | 
|  | 1924 | instruction, | 
|  | 1925 | instruction->GetDexPc(), | 
|  | 1926 | nullptr, | 
|  | 1927 | IsDirectEntrypoint(kQuickAputObject)); | 
|  | 1928 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); | 
|  | 1929 | } | 
|  | 1930 | break; | 
|  | 1931 | } | 
|  | 1932 |  | 
|  | 1933 | case Primitive::kPrimLong: { | 
|  | 1934 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); | 
|  | 1935 | Register value = locations->InAt(2).AsRegisterPairLow<Register>(); | 
|  | 1936 | if (index.IsConstant()) { | 
|  | 1937 | size_t offset = | 
|  | 1938 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
|  | 1939 | __ StoreToOffset(kStoreDoubleword, value, obj, offset); | 
|  | 1940 | } else { | 
|  | 1941 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); | 
|  | 1942 | __ Addu(TMP, obj, TMP); | 
|  | 1943 | __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset); | 
|  | 1944 | } | 
|  | 1945 | break; | 
|  | 1946 | } | 
|  | 1947 |  | 
|  | 1948 | case Primitive::kPrimFloat: { | 
|  | 1949 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); | 
|  | 1950 | FRegister value = locations->InAt(2).AsFpuRegister<FRegister>(); | 
|  | 1951 | DCHECK(locations->InAt(2).IsFpuRegister()); | 
|  | 1952 | if (index.IsConstant()) { | 
|  | 1953 | size_t offset = | 
|  | 1954 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
|  | 1955 | __ StoreSToOffset(value, obj, offset); | 
|  | 1956 | } else { | 
|  | 1957 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); | 
|  | 1958 | __ Addu(TMP, obj, TMP); | 
|  | 1959 | __ StoreSToOffset(value, TMP, data_offset); | 
|  | 1960 | } | 
|  | 1961 | break; | 
|  | 1962 | } | 
|  | 1963 |  | 
|  | 1964 | case Primitive::kPrimDouble: { | 
|  | 1965 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); | 
|  | 1966 | FRegister value = locations->InAt(2).AsFpuRegister<FRegister>(); | 
|  | 1967 | DCHECK(locations->InAt(2).IsFpuRegister()); | 
|  | 1968 | if (index.IsConstant()) { | 
|  | 1969 | size_t offset = | 
|  | 1970 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
|  | 1971 | __ StoreDToOffset(value, obj, offset); | 
|  | 1972 | } else { | 
|  | 1973 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); | 
|  | 1974 | __ Addu(TMP, obj, TMP); | 
|  | 1975 | __ StoreDToOffset(value, TMP, data_offset); | 
|  | 1976 | } | 
|  | 1977 | break; | 
|  | 1978 | } | 
|  | 1979 |  | 
|  | 1980 | case Primitive::kPrimVoid: | 
|  | 1981 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); | 
|  | 1982 | UNREACHABLE(); | 
|  | 1983 | } | 
|  | 1984 |  | 
|  | 1985 | // Ints and objects are handled in the switch. | 
|  | 1986 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { | 
|  | 1987 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1988 | } | 
|  | 1989 | } | 
|  | 1990 |  | 
|  | 1991 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { | 
|  | 1992 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
|  | 1993 | ? LocationSummary::kCallOnSlowPath | 
|  | 1994 | : LocationSummary::kNoCall; | 
|  | 1995 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
|  | 1996 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1997 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 1998 | if (instruction->HasUses()) { | 
|  | 1999 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2000 | } | 
|  | 2001 | } | 
|  | 2002 |  | 
|  | 2003 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { | 
|  | 2004 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2005 | BoundsCheckSlowPathMIPS* slow_path = | 
|  | 2006 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction); | 
|  | 2007 | codegen_->AddSlowPath(slow_path); | 
|  | 2008 |  | 
|  | 2009 | Register index = locations->InAt(0).AsRegister<Register>(); | 
|  | 2010 | Register length = locations->InAt(1).AsRegister<Register>(); | 
|  | 2011 |  | 
|  | 2012 | // length is limited by the maximum positive signed 32-bit integer. | 
|  | 2013 | // Unsigned comparison of length and index checks for index < 0 | 
|  | 2014 | // and for length <= index simultaneously. | 
|  | 2015 | __ Bgeu(index, length, slow_path->GetEntryLabel()); | 
|  | 2016 | } | 
|  | 2017 |  | 
|  | 2018 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { | 
|  | 2019 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( | 
|  | 2020 | instruction, | 
|  | 2021 | LocationSummary::kCallOnSlowPath); | 
|  | 2022 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2023 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 2024 | // Note that TypeCheckSlowPathMIPS uses this register too. | 
|  | 2025 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 2026 | } | 
|  | 2027 |  | 
|  | 2028 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { | 
|  | 2029 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2030 | Register obj = locations->InAt(0).AsRegister<Register>(); | 
|  | 2031 | Register cls = locations->InAt(1).AsRegister<Register>(); | 
|  | 2032 | Register obj_cls = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 2033 |  | 
|  | 2034 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); | 
|  | 2035 | codegen_->AddSlowPath(slow_path); | 
|  | 2036 |  | 
|  | 2037 | // TODO: avoid this check if we know obj is not null. | 
|  | 2038 | __ Beqz(obj, slow_path->GetExitLabel()); | 
|  | 2039 | // Compare the class of `obj` with `cls`. | 
|  | 2040 | __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); | 
|  | 2041 | __ Bne(obj_cls, cls, slow_path->GetEntryLabel()); | 
|  | 2042 | __ Bind(slow_path->GetExitLabel()); | 
|  | 2043 | } | 
|  | 2044 |  | 
|  | 2045 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { | 
|  | 2046 | LocationSummary* locations = | 
|  | 2047 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); | 
|  | 2048 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2049 | if (check->HasUses()) { | 
|  | 2050 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2051 | } | 
|  | 2052 | } | 
|  | 2053 |  | 
|  | 2054 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { | 
|  | 2055 | // We assume the class is not null. | 
|  | 2056 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( | 
|  | 2057 | check->GetLoadClass(), | 
|  | 2058 | check, | 
|  | 2059 | check->GetDexPc(), | 
|  | 2060 | true); | 
|  | 2061 | codegen_->AddSlowPath(slow_path); | 
|  | 2062 | GenerateClassInitializationCheck(slow_path, | 
|  | 2063 | check->GetLocations()->InAt(0).AsRegister<Register>()); | 
|  | 2064 | } | 
|  | 2065 |  | 
|  | 2066 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { | 
|  | 2067 | Primitive::Type in_type = compare->InputAt(0)->GetType(); | 
|  | 2068 |  | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2069 | LocationSummary* locations = | 
|  | 2070 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2071 |  | 
|  | 2072 | switch (in_type) { | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2073 | case Primitive::kPrimInt: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2074 | case Primitive::kPrimLong: | 
|  | 2075 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2076 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 2077 | // Output overlaps because it is written before doing the low comparison. | 
|  | 2078 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); | 
|  | 2079 | break; | 
|  | 2080 |  | 
|  | 2081 | case Primitive::kPrimFloat: | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2082 | case Primitive::kPrimDouble: | 
|  | 2083 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2084 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 2085 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2086 | break; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2087 |  | 
|  | 2088 | default: | 
|  | 2089 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; | 
|  | 2090 | } | 
|  | 2091 | } | 
|  | 2092 |  | 
|  | 2093 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { | 
|  | 2094 | LocationSummary* locations = instruction->GetLocations(); | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2095 | Register res = locations->Out().AsRegister<Register>(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2096 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2097 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2098 |  | 
|  | 2099 | //  0 if: left == right | 
|  | 2100 | //  1 if: left  > right | 
|  | 2101 | // -1 if: left  < right | 
|  | 2102 | switch (in_type) { | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2103 | case Primitive::kPrimInt: { | 
|  | 2104 | Register lhs = locations->InAt(0).AsRegister<Register>(); | 
|  | 2105 | Register rhs = locations->InAt(1).AsRegister<Register>(); | 
|  | 2106 | __ Slt(TMP, lhs, rhs); | 
|  | 2107 | __ Slt(res, rhs, lhs); | 
|  | 2108 | __ Subu(res, res, TMP); | 
|  | 2109 | break; | 
|  | 2110 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2111 | case Primitive::kPrimLong: { | 
|  | 2112 | MipsLabel done; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2113 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); | 
|  | 2114 | Register lhs_low  = locations->InAt(0).AsRegisterPairLow<Register>(); | 
|  | 2115 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); | 
|  | 2116 | Register rhs_low  = locations->InAt(1).AsRegisterPairLow<Register>(); | 
|  | 2117 | // TODO: more efficient (direct) comparison with a constant. | 
|  | 2118 | __ Slt(TMP, lhs_high, rhs_high); | 
|  | 2119 | __ Slt(AT, rhs_high, lhs_high);  // Inverted: is actually gt. | 
|  | 2120 | __ Subu(res, AT, TMP);           // Result -1:1:0 for [ <, >, == ]. | 
|  | 2121 | __ Bnez(res, &done);             // If we compared ==, check if lower bits are also equal. | 
|  | 2122 | __ Sltu(TMP, lhs_low, rhs_low); | 
|  | 2123 | __ Sltu(AT, rhs_low, lhs_low);   // Inverted: is actually gt. | 
|  | 2124 | __ Subu(res, AT, TMP);           // Result -1:1:0 for [ <, >, == ]. | 
|  | 2125 | __ Bind(&done); | 
|  | 2126 | break; | 
|  | 2127 | } | 
|  | 2128 |  | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2129 | case Primitive::kPrimFloat: { | 
| Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2130 | bool gt_bias = instruction->IsGtBias(); | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2131 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 2132 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); | 
|  | 2133 | MipsLabel done; | 
|  | 2134 | if (isR6) { | 
|  | 2135 | __ CmpEqS(FTMP, lhs, rhs); | 
|  | 2136 | __ LoadConst32(res, 0); | 
|  | 2137 | __ Bc1nez(FTMP, &done); | 
|  | 2138 | if (gt_bias) { | 
|  | 2139 | __ CmpLtS(FTMP, lhs, rhs); | 
|  | 2140 | __ LoadConst32(res, -1); | 
|  | 2141 | __ Bc1nez(FTMP, &done); | 
|  | 2142 | __ LoadConst32(res, 1); | 
|  | 2143 | } else { | 
|  | 2144 | __ CmpLtS(FTMP, rhs, lhs); | 
|  | 2145 | __ LoadConst32(res, 1); | 
|  | 2146 | __ Bc1nez(FTMP, &done); | 
|  | 2147 | __ LoadConst32(res, -1); | 
|  | 2148 | } | 
|  | 2149 | } else { | 
|  | 2150 | if (gt_bias) { | 
|  | 2151 | __ ColtS(0, lhs, rhs); | 
|  | 2152 | __ LoadConst32(res, -1); | 
|  | 2153 | __ Bc1t(0, &done); | 
|  | 2154 | __ CeqS(0, lhs, rhs); | 
|  | 2155 | __ LoadConst32(res, 1); | 
|  | 2156 | __ Movt(res, ZERO, 0); | 
|  | 2157 | } else { | 
|  | 2158 | __ ColtS(0, rhs, lhs); | 
|  | 2159 | __ LoadConst32(res, 1); | 
|  | 2160 | __ Bc1t(0, &done); | 
|  | 2161 | __ CeqS(0, lhs, rhs); | 
|  | 2162 | __ LoadConst32(res, -1); | 
|  | 2163 | __ Movt(res, ZERO, 0); | 
|  | 2164 | } | 
|  | 2165 | } | 
|  | 2166 | __ Bind(&done); | 
|  | 2167 | break; | 
|  | 2168 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2169 | case Primitive::kPrimDouble: { | 
| Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2170 | bool gt_bias = instruction->IsGtBias(); | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2171 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 2172 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); | 
|  | 2173 | MipsLabel done; | 
|  | 2174 | if (isR6) { | 
|  | 2175 | __ CmpEqD(FTMP, lhs, rhs); | 
|  | 2176 | __ LoadConst32(res, 0); | 
|  | 2177 | __ Bc1nez(FTMP, &done); | 
|  | 2178 | if (gt_bias) { | 
|  | 2179 | __ CmpLtD(FTMP, lhs, rhs); | 
|  | 2180 | __ LoadConst32(res, -1); | 
|  | 2181 | __ Bc1nez(FTMP, &done); | 
|  | 2182 | __ LoadConst32(res, 1); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2183 | } else { | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2184 | __ CmpLtD(FTMP, rhs, lhs); | 
|  | 2185 | __ LoadConst32(res, 1); | 
|  | 2186 | __ Bc1nez(FTMP, &done); | 
|  | 2187 | __ LoadConst32(res, -1); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2188 | } | 
|  | 2189 | } else { | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2190 | if (gt_bias) { | 
|  | 2191 | __ ColtD(0, lhs, rhs); | 
|  | 2192 | __ LoadConst32(res, -1); | 
|  | 2193 | __ Bc1t(0, &done); | 
|  | 2194 | __ CeqD(0, lhs, rhs); | 
|  | 2195 | __ LoadConst32(res, 1); | 
|  | 2196 | __ Movt(res, ZERO, 0); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2197 | } else { | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2198 | __ ColtD(0, rhs, lhs); | 
|  | 2199 | __ LoadConst32(res, 1); | 
|  | 2200 | __ Bc1t(0, &done); | 
|  | 2201 | __ CeqD(0, lhs, rhs); | 
|  | 2202 | __ LoadConst32(res, -1); | 
|  | 2203 | __ Movt(res, ZERO, 0); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2204 | } | 
|  | 2205 | } | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2206 | __ Bind(&done); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2207 | break; | 
|  | 2208 | } | 
|  | 2209 |  | 
|  | 2210 | default: | 
|  | 2211 | LOG(FATAL) << "Unimplemented compare type " << in_type; | 
|  | 2212 | } | 
|  | 2213 | } | 
|  | 2214 |  | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2215 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2216 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2217 | switch (instruction->InputAt(0)->GetType()) { | 
|  | 2218 | default: | 
|  | 2219 | case Primitive::kPrimLong: | 
|  | 2220 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2221 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 2222 | break; | 
|  | 2223 |  | 
|  | 2224 | case Primitive::kPrimFloat: | 
|  | 2225 | case Primitive::kPrimDouble: | 
|  | 2226 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2227 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 2228 | break; | 
|  | 2229 | } | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2230 | if (!instruction->IsEmittedAtUseSite()) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2231 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 2232 | } | 
|  | 2233 | } | 
|  | 2234 |  | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2235 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2236 | if (instruction->IsEmittedAtUseSite()) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2237 | return; | 
|  | 2238 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2239 |  | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2240 | Primitive::Type type = instruction->InputAt(0)->GetType(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2241 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2242 | Register dst = locations->Out().AsRegister<Register>(); | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2243 | MipsLabel true_label; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2244 |  | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2245 | switch (type) { | 
|  | 2246 | default: | 
|  | 2247 | // Integer case. | 
|  | 2248 | GenerateIntCompare(instruction->GetCondition(), locations); | 
|  | 2249 | return; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2250 |  | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2251 | case Primitive::kPrimLong: | 
|  | 2252 | // TODO: don't use branches. | 
|  | 2253 | GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2254 | break; | 
|  | 2255 |  | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2256 | case Primitive::kPrimFloat: | 
|  | 2257 | case Primitive::kPrimDouble: | 
|  | 2258 | // TODO: don't use branches. | 
|  | 2259 | GenerateFpCompareAndBranch(instruction->GetCondition(), | 
|  | 2260 | instruction->IsGtBias(), | 
|  | 2261 | type, | 
|  | 2262 | locations, | 
|  | 2263 | &true_label); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2264 | break; | 
|  | 2265 | } | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2266 |  | 
|  | 2267 | // Convert the branches into the result. | 
|  | 2268 | MipsLabel done; | 
|  | 2269 |  | 
|  | 2270 | // False case: result = 0. | 
|  | 2271 | __ LoadConst32(dst, 0); | 
|  | 2272 | __ B(&done); | 
|  | 2273 |  | 
|  | 2274 | // True case: result = 1. | 
|  | 2275 | __ Bind(&true_label); | 
|  | 2276 | __ LoadConst32(dst, 1); | 
|  | 2277 | __ Bind(&done); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2278 | } | 
|  | 2279 |  | 
| Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2280 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { | 
|  | 2281 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 2282 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); | 
|  | 2283 |  | 
|  | 2284 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2285 | Location second = locations->InAt(1); | 
|  | 2286 | DCHECK(second.IsConstant()); | 
|  | 2287 |  | 
|  | 2288 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 2289 | Register dividend = locations->InAt(0).AsRegister<Register>(); | 
|  | 2290 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); | 
|  | 2291 | DCHECK(imm == 1 || imm == -1); | 
|  | 2292 |  | 
|  | 2293 | if (instruction->IsRem()) { | 
|  | 2294 | __ Move(out, ZERO); | 
|  | 2295 | } else { | 
|  | 2296 | if (imm == -1) { | 
|  | 2297 | __ Subu(out, ZERO, dividend); | 
|  | 2298 | } else if (out != dividend) { | 
|  | 2299 | __ Move(out, dividend); | 
|  | 2300 | } | 
|  | 2301 | } | 
|  | 2302 | } | 
|  | 2303 |  | 
|  | 2304 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { | 
|  | 2305 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 2306 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); | 
|  | 2307 |  | 
|  | 2308 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2309 | Location second = locations->InAt(1); | 
|  | 2310 | DCHECK(second.IsConstant()); | 
|  | 2311 |  | 
|  | 2312 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 2313 | Register dividend = locations->InAt(0).AsRegister<Register>(); | 
|  | 2314 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); | 
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2315 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); | 
| Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2316 | int ctz_imm = CTZ(abs_imm); | 
|  | 2317 |  | 
|  | 2318 | if (instruction->IsDiv()) { | 
|  | 2319 | if (ctz_imm == 1) { | 
|  | 2320 | // Fast path for division by +/-2, which is very common. | 
|  | 2321 | __ Srl(TMP, dividend, 31); | 
|  | 2322 | } else { | 
|  | 2323 | __ Sra(TMP, dividend, 31); | 
|  | 2324 | __ Srl(TMP, TMP, 32 - ctz_imm); | 
|  | 2325 | } | 
|  | 2326 | __ Addu(out, dividend, TMP); | 
|  | 2327 | __ Sra(out, out, ctz_imm); | 
|  | 2328 | if (imm < 0) { | 
|  | 2329 | __ Subu(out, ZERO, out); | 
|  | 2330 | } | 
|  | 2331 | } else { | 
|  | 2332 | if (ctz_imm == 1) { | 
|  | 2333 | // Fast path for modulo +/-2, which is very common. | 
|  | 2334 | __ Sra(TMP, dividend, 31); | 
|  | 2335 | __ Subu(out, dividend, TMP); | 
|  | 2336 | __ Andi(out, out, 1); | 
|  | 2337 | __ Addu(out, out, TMP); | 
|  | 2338 | } else { | 
|  | 2339 | __ Sra(TMP, dividend, 31); | 
|  | 2340 | __ Srl(TMP, TMP, 32 - ctz_imm); | 
|  | 2341 | __ Addu(out, dividend, TMP); | 
|  | 2342 | if (IsUint<16>(abs_imm - 1)) { | 
|  | 2343 | __ Andi(out, out, abs_imm - 1); | 
|  | 2344 | } else { | 
|  | 2345 | __ Sll(out, out, 32 - ctz_imm); | 
|  | 2346 | __ Srl(out, out, 32 - ctz_imm); | 
|  | 2347 | } | 
|  | 2348 | __ Subu(out, out, TMP); | 
|  | 2349 | } | 
|  | 2350 | } | 
|  | 2351 | } | 
|  | 2352 |  | 
|  | 2353 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { | 
|  | 2354 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 2355 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); | 
|  | 2356 |  | 
|  | 2357 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2358 | Location second = locations->InAt(1); | 
|  | 2359 | DCHECK(second.IsConstant()); | 
|  | 2360 |  | 
|  | 2361 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 2362 | Register dividend = locations->InAt(0).AsRegister<Register>(); | 
|  | 2363 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); | 
|  | 2364 |  | 
|  | 2365 | int64_t magic; | 
|  | 2366 | int shift; | 
|  | 2367 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); | 
|  | 2368 |  | 
|  | 2369 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); | 
|  | 2370 |  | 
|  | 2371 | __ LoadConst32(TMP, magic); | 
|  | 2372 | if (isR6) { | 
|  | 2373 | __ MuhR6(TMP, dividend, TMP); | 
|  | 2374 | } else { | 
|  | 2375 | __ MultR2(dividend, TMP); | 
|  | 2376 | __ Mfhi(TMP); | 
|  | 2377 | } | 
|  | 2378 | if (imm > 0 && magic < 0) { | 
|  | 2379 | __ Addu(TMP, TMP, dividend); | 
|  | 2380 | } else if (imm < 0 && magic > 0) { | 
|  | 2381 | __ Subu(TMP, TMP, dividend); | 
|  | 2382 | } | 
|  | 2383 |  | 
|  | 2384 | if (shift != 0) { | 
|  | 2385 | __ Sra(TMP, TMP, shift); | 
|  | 2386 | } | 
|  | 2387 |  | 
|  | 2388 | if (instruction->IsDiv()) { | 
|  | 2389 | __ Sra(out, TMP, 31); | 
|  | 2390 | __ Subu(out, TMP, out); | 
|  | 2391 | } else { | 
|  | 2392 | __ Sra(AT, TMP, 31); | 
|  | 2393 | __ Subu(AT, TMP, AT); | 
|  | 2394 | __ LoadConst32(TMP, imm); | 
|  | 2395 | if (isR6) { | 
|  | 2396 | __ MulR6(TMP, AT, TMP); | 
|  | 2397 | } else { | 
|  | 2398 | __ MulR2(TMP, AT, TMP); | 
|  | 2399 | } | 
|  | 2400 | __ Subu(out, dividend, TMP); | 
|  | 2401 | } | 
|  | 2402 | } | 
|  | 2403 |  | 
|  | 2404 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { | 
|  | 2405 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 2406 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); | 
|  | 2407 |  | 
|  | 2408 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2409 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 2410 | Location second = locations->InAt(1); | 
|  | 2411 |  | 
|  | 2412 | if (second.IsConstant()) { | 
|  | 2413 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); | 
|  | 2414 | if (imm == 0) { | 
|  | 2415 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. | 
|  | 2416 | } else if (imm == 1 || imm == -1) { | 
|  | 2417 | DivRemOneOrMinusOne(instruction); | 
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2418 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { | 
| Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2419 | DivRemByPowerOfTwo(instruction); | 
|  | 2420 | } else { | 
|  | 2421 | DCHECK(imm <= -2 || imm >= 2); | 
|  | 2422 | GenerateDivRemWithAnyConstant(instruction); | 
|  | 2423 | } | 
|  | 2424 | } else { | 
|  | 2425 | Register dividend = locations->InAt(0).AsRegister<Register>(); | 
|  | 2426 | Register divisor = second.AsRegister<Register>(); | 
|  | 2427 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); | 
|  | 2428 | if (instruction->IsDiv()) { | 
|  | 2429 | if (isR6) { | 
|  | 2430 | __ DivR6(out, dividend, divisor); | 
|  | 2431 | } else { | 
|  | 2432 | __ DivR2(out, dividend, divisor); | 
|  | 2433 | } | 
|  | 2434 | } else { | 
|  | 2435 | if (isR6) { | 
|  | 2436 | __ ModR6(out, dividend, divisor); | 
|  | 2437 | } else { | 
|  | 2438 | __ ModR2(out, dividend, divisor); | 
|  | 2439 | } | 
|  | 2440 | } | 
|  | 2441 | } | 
|  | 2442 | } | 
|  | 2443 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2444 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { | 
|  | 2445 | Primitive::Type type = div->GetResultType(); | 
|  | 2446 | LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong) | 
|  | 2447 | ? LocationSummary::kCall | 
|  | 2448 | : LocationSummary::kNoCall; | 
|  | 2449 |  | 
|  | 2450 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); | 
|  | 2451 |  | 
|  | 2452 | switch (type) { | 
|  | 2453 | case Primitive::kPrimInt: | 
|  | 2454 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2455 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2456 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 2457 | break; | 
|  | 2458 |  | 
|  | 2459 | case Primitive::kPrimLong: { | 
|  | 2460 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 2461 | locations->SetInAt(0, Location::RegisterPairLocation( | 
|  | 2462 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); | 
|  | 2463 | locations->SetInAt(1, Location::RegisterPairLocation( | 
|  | 2464 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); | 
|  | 2465 | locations->SetOut(calling_convention.GetReturnLocation(type)); | 
|  | 2466 | break; | 
|  | 2467 | } | 
|  | 2468 |  | 
|  | 2469 | case Primitive::kPrimFloat: | 
|  | 2470 | case Primitive::kPrimDouble: | 
|  | 2471 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2472 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 2473 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 2474 | break; | 
|  | 2475 |  | 
|  | 2476 | default: | 
|  | 2477 | LOG(FATAL) << "Unexpected div type " << type; | 
|  | 2478 | } | 
|  | 2479 | } | 
|  | 2480 |  | 
|  | 2481 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { | 
|  | 2482 | Primitive::Type type = instruction->GetType(); | 
|  | 2483 | LocationSummary* locations = instruction->GetLocations(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2484 |  | 
|  | 2485 | switch (type) { | 
| Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2486 | case Primitive::kPrimInt: | 
|  | 2487 | GenerateDivRemIntegral(instruction); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2488 | break; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2489 | case Primitive::kPrimLong: { | 
|  | 2490 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), | 
|  | 2491 | instruction, | 
|  | 2492 | instruction->GetDexPc(), | 
|  | 2493 | nullptr, | 
|  | 2494 | IsDirectEntrypoint(kQuickLdiv)); | 
|  | 2495 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); | 
|  | 2496 | break; | 
|  | 2497 | } | 
|  | 2498 | case Primitive::kPrimFloat: | 
|  | 2499 | case Primitive::kPrimDouble: { | 
|  | 2500 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 2501 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 2502 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); | 
|  | 2503 | if (type == Primitive::kPrimFloat) { | 
|  | 2504 | __ DivS(dst, lhs, rhs); | 
|  | 2505 | } else { | 
|  | 2506 | __ DivD(dst, lhs, rhs); | 
|  | 2507 | } | 
|  | 2508 | break; | 
|  | 2509 | } | 
|  | 2510 | default: | 
|  | 2511 | LOG(FATAL) << "Unexpected div type " << type; | 
|  | 2512 | } | 
|  | 2513 | } | 
|  | 2514 |  | 
|  | 2515 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
|  | 2516 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
|  | 2517 | ? LocationSummary::kCallOnSlowPath | 
|  | 2518 | : LocationSummary::kNoCall; | 
|  | 2519 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
|  | 2520 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); | 
|  | 2521 | if (instruction->HasUses()) { | 
|  | 2522 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2523 | } | 
|  | 2524 | } | 
|  | 2525 |  | 
|  | 2526 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
|  | 2527 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction); | 
|  | 2528 | codegen_->AddSlowPath(slow_path); | 
|  | 2529 | Location value = instruction->GetLocations()->InAt(0); | 
|  | 2530 | Primitive::Type type = instruction->GetType(); | 
|  | 2531 |  | 
|  | 2532 | switch (type) { | 
|  | 2533 | case Primitive::kPrimByte: | 
|  | 2534 | case Primitive::kPrimChar: | 
|  | 2535 | case Primitive::kPrimShort: | 
|  | 2536 | case Primitive::kPrimInt: { | 
|  | 2537 | if (value.IsConstant()) { | 
|  | 2538 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { | 
|  | 2539 | __ B(slow_path->GetEntryLabel()); | 
|  | 2540 | } else { | 
|  | 2541 | // A division by a non-null constant is valid. We don't need to perform | 
|  | 2542 | // any check, so simply fall through. | 
|  | 2543 | } | 
|  | 2544 | } else { | 
|  | 2545 | DCHECK(value.IsRegister()) << value; | 
|  | 2546 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); | 
|  | 2547 | } | 
|  | 2548 | break; | 
|  | 2549 | } | 
|  | 2550 | case Primitive::kPrimLong: { | 
|  | 2551 | if (value.IsConstant()) { | 
|  | 2552 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { | 
|  | 2553 | __ B(slow_path->GetEntryLabel()); | 
|  | 2554 | } else { | 
|  | 2555 | // A division by a non-null constant is valid. We don't need to perform | 
|  | 2556 | // any check, so simply fall through. | 
|  | 2557 | } | 
|  | 2558 | } else { | 
|  | 2559 | DCHECK(value.IsRegisterPair()) << value; | 
|  | 2560 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); | 
|  | 2561 | __ Beqz(TMP, slow_path->GetEntryLabel()); | 
|  | 2562 | } | 
|  | 2563 | break; | 
|  | 2564 | } | 
|  | 2565 | default: | 
|  | 2566 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; | 
|  | 2567 | } | 
|  | 2568 | } | 
|  | 2569 |  | 
|  | 2570 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { | 
|  | 2571 | LocationSummary* locations = | 
|  | 2572 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
|  | 2573 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2574 | } | 
|  | 2575 |  | 
|  | 2576 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { | 
|  | 2577 | // Will be generated at use site. | 
|  | 2578 | } | 
|  | 2579 |  | 
|  | 2580 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { | 
|  | 2581 | exit->SetLocations(nullptr); | 
|  | 2582 | } | 
|  | 2583 |  | 
|  | 2584 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { | 
|  | 2585 | } | 
|  | 2586 |  | 
|  | 2587 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { | 
|  | 2588 | LocationSummary* locations = | 
|  | 2589 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
|  | 2590 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2591 | } | 
|  | 2592 |  | 
|  | 2593 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { | 
|  | 2594 | // Will be generated at use site. | 
|  | 2595 | } | 
|  | 2596 |  | 
|  | 2597 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { | 
|  | 2598 | got->SetLocations(nullptr); | 
|  | 2599 | } | 
|  | 2600 |  | 
|  | 2601 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { | 
|  | 2602 | DCHECK(!successor->IsExitBlock()); | 
|  | 2603 | HBasicBlock* block = got->GetBlock(); | 
|  | 2604 | HInstruction* previous = got->GetPrevious(); | 
|  | 2605 | HLoopInformation* info = block->GetLoopInformation(); | 
|  | 2606 |  | 
|  | 2607 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { | 
|  | 2608 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); | 
|  | 2609 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); | 
|  | 2610 | return; | 
|  | 2611 | } | 
|  | 2612 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { | 
|  | 2613 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); | 
|  | 2614 | } | 
|  | 2615 | if (!codegen_->GoesToNextBlock(block, successor)) { | 
|  | 2616 | __ B(codegen_->GetLabelOf(successor)); | 
|  | 2617 | } | 
|  | 2618 | } | 
|  | 2619 |  | 
|  | 2620 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { | 
|  | 2621 | HandleGoto(got, got->GetSuccessor()); | 
|  | 2622 | } | 
|  | 2623 |  | 
|  | 2624 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { | 
|  | 2625 | try_boundary->SetLocations(nullptr); | 
|  | 2626 | } | 
|  | 2627 |  | 
|  | 2628 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { | 
|  | 2629 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); | 
|  | 2630 | if (!successor->IsExitBlock()) { | 
|  | 2631 | HandleGoto(try_boundary, successor); | 
|  | 2632 | } | 
|  | 2633 | } | 
|  | 2634 |  | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2635 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, | 
|  | 2636 | LocationSummary* locations) { | 
|  | 2637 | Register dst = locations->Out().AsRegister<Register>(); | 
|  | 2638 | Register lhs = locations->InAt(0).AsRegister<Register>(); | 
|  | 2639 | Location rhs_location = locations->InAt(1); | 
|  | 2640 | Register rhs_reg = ZERO; | 
|  | 2641 | int64_t rhs_imm = 0; | 
|  | 2642 | bool use_imm = rhs_location.IsConstant(); | 
|  | 2643 | if (use_imm) { | 
|  | 2644 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); | 
|  | 2645 | } else { | 
|  | 2646 | rhs_reg = rhs_location.AsRegister<Register>(); | 
|  | 2647 | } | 
|  | 2648 |  | 
|  | 2649 | switch (cond) { | 
|  | 2650 | case kCondEQ: | 
|  | 2651 | case kCondNE: | 
|  | 2652 | if (use_imm && IsUint<16>(rhs_imm)) { | 
|  | 2653 | __ Xori(dst, lhs, rhs_imm); | 
|  | 2654 | } else { | 
|  | 2655 | if (use_imm) { | 
|  | 2656 | rhs_reg = TMP; | 
|  | 2657 | __ LoadConst32(rhs_reg, rhs_imm); | 
|  | 2658 | } | 
|  | 2659 | __ Xor(dst, lhs, rhs_reg); | 
|  | 2660 | } | 
|  | 2661 | if (cond == kCondEQ) { | 
|  | 2662 | __ Sltiu(dst, dst, 1); | 
|  | 2663 | } else { | 
|  | 2664 | __ Sltu(dst, ZERO, dst); | 
|  | 2665 | } | 
|  | 2666 | break; | 
|  | 2667 |  | 
|  | 2668 | case kCondLT: | 
|  | 2669 | case kCondGE: | 
|  | 2670 | if (use_imm && IsInt<16>(rhs_imm)) { | 
|  | 2671 | __ Slti(dst, lhs, rhs_imm); | 
|  | 2672 | } else { | 
|  | 2673 | if (use_imm) { | 
|  | 2674 | rhs_reg = TMP; | 
|  | 2675 | __ LoadConst32(rhs_reg, rhs_imm); | 
|  | 2676 | } | 
|  | 2677 | __ Slt(dst, lhs, rhs_reg); | 
|  | 2678 | } | 
|  | 2679 | if (cond == kCondGE) { | 
|  | 2680 | // Simulate lhs >= rhs via !(lhs < rhs) since there's | 
|  | 2681 | // only the slt instruction but no sge. | 
|  | 2682 | __ Xori(dst, dst, 1); | 
|  | 2683 | } | 
|  | 2684 | break; | 
|  | 2685 |  | 
|  | 2686 | case kCondLE: | 
|  | 2687 | case kCondGT: | 
|  | 2688 | if (use_imm && IsInt<16>(rhs_imm + 1)) { | 
|  | 2689 | // Simulate lhs <= rhs via lhs < rhs + 1. | 
|  | 2690 | __ Slti(dst, lhs, rhs_imm + 1); | 
|  | 2691 | if (cond == kCondGT) { | 
|  | 2692 | // Simulate lhs > rhs via !(lhs <= rhs) since there's | 
|  | 2693 | // only the slti instruction but no sgti. | 
|  | 2694 | __ Xori(dst, dst, 1); | 
|  | 2695 | } | 
|  | 2696 | } else { | 
|  | 2697 | if (use_imm) { | 
|  | 2698 | rhs_reg = TMP; | 
|  | 2699 | __ LoadConst32(rhs_reg, rhs_imm); | 
|  | 2700 | } | 
|  | 2701 | __ Slt(dst, rhs_reg, lhs); | 
|  | 2702 | if (cond == kCondLE) { | 
|  | 2703 | // Simulate lhs <= rhs via !(rhs < lhs) since there's | 
|  | 2704 | // only the slt instruction but no sle. | 
|  | 2705 | __ Xori(dst, dst, 1); | 
|  | 2706 | } | 
|  | 2707 | } | 
|  | 2708 | break; | 
|  | 2709 |  | 
|  | 2710 | case kCondB: | 
|  | 2711 | case kCondAE: | 
|  | 2712 | if (use_imm && IsInt<16>(rhs_imm)) { | 
|  | 2713 | // Sltiu sign-extends its 16-bit immediate operand before | 
|  | 2714 | // the comparison and thus lets us compare directly with | 
|  | 2715 | // unsigned values in the ranges [0, 0x7fff] and | 
|  | 2716 | // [0xffff8000, 0xffffffff]. | 
|  | 2717 | __ Sltiu(dst, lhs, rhs_imm); | 
|  | 2718 | } else { | 
|  | 2719 | if (use_imm) { | 
|  | 2720 | rhs_reg = TMP; | 
|  | 2721 | __ LoadConst32(rhs_reg, rhs_imm); | 
|  | 2722 | } | 
|  | 2723 | __ Sltu(dst, lhs, rhs_reg); | 
|  | 2724 | } | 
|  | 2725 | if (cond == kCondAE) { | 
|  | 2726 | // Simulate lhs >= rhs via !(lhs < rhs) since there's | 
|  | 2727 | // only the sltu instruction but no sgeu. | 
|  | 2728 | __ Xori(dst, dst, 1); | 
|  | 2729 | } | 
|  | 2730 | break; | 
|  | 2731 |  | 
|  | 2732 | case kCondBE: | 
|  | 2733 | case kCondA: | 
|  | 2734 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { | 
|  | 2735 | // Simulate lhs <= rhs via lhs < rhs + 1. | 
|  | 2736 | // Note that this only works if rhs + 1 does not overflow | 
|  | 2737 | // to 0, hence the check above. | 
|  | 2738 | // Sltiu sign-extends its 16-bit immediate operand before | 
|  | 2739 | // the comparison and thus lets us compare directly with | 
|  | 2740 | // unsigned values in the ranges [0, 0x7fff] and | 
|  | 2741 | // [0xffff8000, 0xffffffff]. | 
|  | 2742 | __ Sltiu(dst, lhs, rhs_imm + 1); | 
|  | 2743 | if (cond == kCondA) { | 
|  | 2744 | // Simulate lhs > rhs via !(lhs <= rhs) since there's | 
|  | 2745 | // only the sltiu instruction but no sgtiu. | 
|  | 2746 | __ Xori(dst, dst, 1); | 
|  | 2747 | } | 
|  | 2748 | } else { | 
|  | 2749 | if (use_imm) { | 
|  | 2750 | rhs_reg = TMP; | 
|  | 2751 | __ LoadConst32(rhs_reg, rhs_imm); | 
|  | 2752 | } | 
|  | 2753 | __ Sltu(dst, rhs_reg, lhs); | 
|  | 2754 | if (cond == kCondBE) { | 
|  | 2755 | // Simulate lhs <= rhs via !(rhs < lhs) since there's | 
|  | 2756 | // only the sltu instruction but no sleu. | 
|  | 2757 | __ Xori(dst, dst, 1); | 
|  | 2758 | } | 
|  | 2759 | } | 
|  | 2760 | break; | 
|  | 2761 | } | 
|  | 2762 | } | 
|  | 2763 |  | 
|  | 2764 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, | 
|  | 2765 | LocationSummary* locations, | 
|  | 2766 | MipsLabel* label) { | 
|  | 2767 | Register lhs = locations->InAt(0).AsRegister<Register>(); | 
|  | 2768 | Location rhs_location = locations->InAt(1); | 
|  | 2769 | Register rhs_reg = ZERO; | 
|  | 2770 | int32_t rhs_imm = 0; | 
|  | 2771 | bool use_imm = rhs_location.IsConstant(); | 
|  | 2772 | if (use_imm) { | 
|  | 2773 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); | 
|  | 2774 | } else { | 
|  | 2775 | rhs_reg = rhs_location.AsRegister<Register>(); | 
|  | 2776 | } | 
|  | 2777 |  | 
|  | 2778 | if (use_imm && rhs_imm == 0) { | 
|  | 2779 | switch (cond) { | 
|  | 2780 | case kCondEQ: | 
|  | 2781 | case kCondBE:  // <= 0 if zero | 
|  | 2782 | __ Beqz(lhs, label); | 
|  | 2783 | break; | 
|  | 2784 | case kCondNE: | 
|  | 2785 | case kCondA:  // > 0 if non-zero | 
|  | 2786 | __ Bnez(lhs, label); | 
|  | 2787 | break; | 
|  | 2788 | case kCondLT: | 
|  | 2789 | __ Bltz(lhs, label); | 
|  | 2790 | break; | 
|  | 2791 | case kCondGE: | 
|  | 2792 | __ Bgez(lhs, label); | 
|  | 2793 | break; | 
|  | 2794 | case kCondLE: | 
|  | 2795 | __ Blez(lhs, label); | 
|  | 2796 | break; | 
|  | 2797 | case kCondGT: | 
|  | 2798 | __ Bgtz(lhs, label); | 
|  | 2799 | break; | 
|  | 2800 | case kCondB:  // always false | 
|  | 2801 | break; | 
|  | 2802 | case kCondAE:  // always true | 
|  | 2803 | __ B(label); | 
|  | 2804 | break; | 
|  | 2805 | } | 
|  | 2806 | } else { | 
|  | 2807 | if (use_imm) { | 
|  | 2808 | // TODO: more efficient comparison with 16-bit constants without loading them into TMP. | 
|  | 2809 | rhs_reg = TMP; | 
|  | 2810 | __ LoadConst32(rhs_reg, rhs_imm); | 
|  | 2811 | } | 
|  | 2812 | switch (cond) { | 
|  | 2813 | case kCondEQ: | 
|  | 2814 | __ Beq(lhs, rhs_reg, label); | 
|  | 2815 | break; | 
|  | 2816 | case kCondNE: | 
|  | 2817 | __ Bne(lhs, rhs_reg, label); | 
|  | 2818 | break; | 
|  | 2819 | case kCondLT: | 
|  | 2820 | __ Blt(lhs, rhs_reg, label); | 
|  | 2821 | break; | 
|  | 2822 | case kCondGE: | 
|  | 2823 | __ Bge(lhs, rhs_reg, label); | 
|  | 2824 | break; | 
|  | 2825 | case kCondLE: | 
|  | 2826 | __ Bge(rhs_reg, lhs, label); | 
|  | 2827 | break; | 
|  | 2828 | case kCondGT: | 
|  | 2829 | __ Blt(rhs_reg, lhs, label); | 
|  | 2830 | break; | 
|  | 2831 | case kCondB: | 
|  | 2832 | __ Bltu(lhs, rhs_reg, label); | 
|  | 2833 | break; | 
|  | 2834 | case kCondAE: | 
|  | 2835 | __ Bgeu(lhs, rhs_reg, label); | 
|  | 2836 | break; | 
|  | 2837 | case kCondBE: | 
|  | 2838 | __ Bgeu(rhs_reg, lhs, label); | 
|  | 2839 | break; | 
|  | 2840 | case kCondA: | 
|  | 2841 | __ Bltu(rhs_reg, lhs, label); | 
|  | 2842 | break; | 
|  | 2843 | } | 
|  | 2844 | } | 
|  | 2845 | } | 
|  | 2846 |  | 
|  | 2847 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, | 
|  | 2848 | LocationSummary* locations, | 
|  | 2849 | MipsLabel* label) { | 
|  | 2850 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); | 
|  | 2851 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); | 
|  | 2852 | Location rhs_location = locations->InAt(1); | 
|  | 2853 | Register rhs_high = ZERO; | 
|  | 2854 | Register rhs_low = ZERO; | 
|  | 2855 | int64_t imm = 0; | 
|  | 2856 | uint32_t imm_high = 0; | 
|  | 2857 | uint32_t imm_low = 0; | 
|  | 2858 | bool use_imm = rhs_location.IsConstant(); | 
|  | 2859 | if (use_imm) { | 
|  | 2860 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 2861 | imm_high = High32Bits(imm); | 
|  | 2862 | imm_low = Low32Bits(imm); | 
|  | 2863 | } else { | 
|  | 2864 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); | 
|  | 2865 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); | 
|  | 2866 | } | 
|  | 2867 |  | 
|  | 2868 | if (use_imm && imm == 0) { | 
|  | 2869 | switch (cond) { | 
|  | 2870 | case kCondEQ: | 
|  | 2871 | case kCondBE:  // <= 0 if zero | 
|  | 2872 | __ Or(TMP, lhs_high, lhs_low); | 
|  | 2873 | __ Beqz(TMP, label); | 
|  | 2874 | break; | 
|  | 2875 | case kCondNE: | 
|  | 2876 | case kCondA:  // > 0 if non-zero | 
|  | 2877 | __ Or(TMP, lhs_high, lhs_low); | 
|  | 2878 | __ Bnez(TMP, label); | 
|  | 2879 | break; | 
|  | 2880 | case kCondLT: | 
|  | 2881 | __ Bltz(lhs_high, label); | 
|  | 2882 | break; | 
|  | 2883 | case kCondGE: | 
|  | 2884 | __ Bgez(lhs_high, label); | 
|  | 2885 | break; | 
|  | 2886 | case kCondLE: | 
|  | 2887 | __ Or(TMP, lhs_high, lhs_low); | 
|  | 2888 | __ Sra(AT, lhs_high, 31); | 
|  | 2889 | __ Bgeu(AT, TMP, label); | 
|  | 2890 | break; | 
|  | 2891 | case kCondGT: | 
|  | 2892 | __ Or(TMP, lhs_high, lhs_low); | 
|  | 2893 | __ Sra(AT, lhs_high, 31); | 
|  | 2894 | __ Bltu(AT, TMP, label); | 
|  | 2895 | break; | 
|  | 2896 | case kCondB:  // always false | 
|  | 2897 | break; | 
|  | 2898 | case kCondAE:  // always true | 
|  | 2899 | __ B(label); | 
|  | 2900 | break; | 
|  | 2901 | } | 
|  | 2902 | } else if (use_imm) { | 
|  | 2903 | // TODO: more efficient comparison with constants without loading them into TMP/AT. | 
|  | 2904 | switch (cond) { | 
|  | 2905 | case kCondEQ: | 
|  | 2906 | __ LoadConst32(TMP, imm_high); | 
|  | 2907 | __ Xor(TMP, TMP, lhs_high); | 
|  | 2908 | __ LoadConst32(AT, imm_low); | 
|  | 2909 | __ Xor(AT, AT, lhs_low); | 
|  | 2910 | __ Or(TMP, TMP, AT); | 
|  | 2911 | __ Beqz(TMP, label); | 
|  | 2912 | break; | 
|  | 2913 | case kCondNE: | 
|  | 2914 | __ LoadConst32(TMP, imm_high); | 
|  | 2915 | __ Xor(TMP, TMP, lhs_high); | 
|  | 2916 | __ LoadConst32(AT, imm_low); | 
|  | 2917 | __ Xor(AT, AT, lhs_low); | 
|  | 2918 | __ Or(TMP, TMP, AT); | 
|  | 2919 | __ Bnez(TMP, label); | 
|  | 2920 | break; | 
|  | 2921 | case kCondLT: | 
|  | 2922 | __ LoadConst32(TMP, imm_high); | 
|  | 2923 | __ Blt(lhs_high, TMP, label); | 
|  | 2924 | __ Slt(TMP, TMP, lhs_high); | 
|  | 2925 | __ LoadConst32(AT, imm_low); | 
|  | 2926 | __ Sltu(AT, lhs_low, AT); | 
|  | 2927 | __ Blt(TMP, AT, label); | 
|  | 2928 | break; | 
|  | 2929 | case kCondGE: | 
|  | 2930 | __ LoadConst32(TMP, imm_high); | 
|  | 2931 | __ Blt(TMP, lhs_high, label); | 
|  | 2932 | __ Slt(TMP, lhs_high, TMP); | 
|  | 2933 | __ LoadConst32(AT, imm_low); | 
|  | 2934 | __ Sltu(AT, lhs_low, AT); | 
|  | 2935 | __ Or(TMP, TMP, AT); | 
|  | 2936 | __ Beqz(TMP, label); | 
|  | 2937 | break; | 
|  | 2938 | case kCondLE: | 
|  | 2939 | __ LoadConst32(TMP, imm_high); | 
|  | 2940 | __ Blt(lhs_high, TMP, label); | 
|  | 2941 | __ Slt(TMP, TMP, lhs_high); | 
|  | 2942 | __ LoadConst32(AT, imm_low); | 
|  | 2943 | __ Sltu(AT, AT, lhs_low); | 
|  | 2944 | __ Or(TMP, TMP, AT); | 
|  | 2945 | __ Beqz(TMP, label); | 
|  | 2946 | break; | 
|  | 2947 | case kCondGT: | 
|  | 2948 | __ LoadConst32(TMP, imm_high); | 
|  | 2949 | __ Blt(TMP, lhs_high, label); | 
|  | 2950 | __ Slt(TMP, lhs_high, TMP); | 
|  | 2951 | __ LoadConst32(AT, imm_low); | 
|  | 2952 | __ Sltu(AT, AT, lhs_low); | 
|  | 2953 | __ Blt(TMP, AT, label); | 
|  | 2954 | break; | 
|  | 2955 | case kCondB: | 
|  | 2956 | __ LoadConst32(TMP, imm_high); | 
|  | 2957 | __ Bltu(lhs_high, TMP, label); | 
|  | 2958 | __ Sltu(TMP, TMP, lhs_high); | 
|  | 2959 | __ LoadConst32(AT, imm_low); | 
|  | 2960 | __ Sltu(AT, lhs_low, AT); | 
|  | 2961 | __ Blt(TMP, AT, label); | 
|  | 2962 | break; | 
|  | 2963 | case kCondAE: | 
|  | 2964 | __ LoadConst32(TMP, imm_high); | 
|  | 2965 | __ Bltu(TMP, lhs_high, label); | 
|  | 2966 | __ Sltu(TMP, lhs_high, TMP); | 
|  | 2967 | __ LoadConst32(AT, imm_low); | 
|  | 2968 | __ Sltu(AT, lhs_low, AT); | 
|  | 2969 | __ Or(TMP, TMP, AT); | 
|  | 2970 | __ Beqz(TMP, label); | 
|  | 2971 | break; | 
|  | 2972 | case kCondBE: | 
|  | 2973 | __ LoadConst32(TMP, imm_high); | 
|  | 2974 | __ Bltu(lhs_high, TMP, label); | 
|  | 2975 | __ Sltu(TMP, TMP, lhs_high); | 
|  | 2976 | __ LoadConst32(AT, imm_low); | 
|  | 2977 | __ Sltu(AT, AT, lhs_low); | 
|  | 2978 | __ Or(TMP, TMP, AT); | 
|  | 2979 | __ Beqz(TMP, label); | 
|  | 2980 | break; | 
|  | 2981 | case kCondA: | 
|  | 2982 | __ LoadConst32(TMP, imm_high); | 
|  | 2983 | __ Bltu(TMP, lhs_high, label); | 
|  | 2984 | __ Sltu(TMP, lhs_high, TMP); | 
|  | 2985 | __ LoadConst32(AT, imm_low); | 
|  | 2986 | __ Sltu(AT, AT, lhs_low); | 
|  | 2987 | __ Blt(TMP, AT, label); | 
|  | 2988 | break; | 
|  | 2989 | } | 
|  | 2990 | } else { | 
|  | 2991 | switch (cond) { | 
|  | 2992 | case kCondEQ: | 
|  | 2993 | __ Xor(TMP, lhs_high, rhs_high); | 
|  | 2994 | __ Xor(AT, lhs_low, rhs_low); | 
|  | 2995 | __ Or(TMP, TMP, AT); | 
|  | 2996 | __ Beqz(TMP, label); | 
|  | 2997 | break; | 
|  | 2998 | case kCondNE: | 
|  | 2999 | __ Xor(TMP, lhs_high, rhs_high); | 
|  | 3000 | __ Xor(AT, lhs_low, rhs_low); | 
|  | 3001 | __ Or(TMP, TMP, AT); | 
|  | 3002 | __ Bnez(TMP, label); | 
|  | 3003 | break; | 
|  | 3004 | case kCondLT: | 
|  | 3005 | __ Blt(lhs_high, rhs_high, label); | 
|  | 3006 | __ Slt(TMP, rhs_high, lhs_high); | 
|  | 3007 | __ Sltu(AT, lhs_low, rhs_low); | 
|  | 3008 | __ Blt(TMP, AT, label); | 
|  | 3009 | break; | 
|  | 3010 | case kCondGE: | 
|  | 3011 | __ Blt(rhs_high, lhs_high, label); | 
|  | 3012 | __ Slt(TMP, lhs_high, rhs_high); | 
|  | 3013 | __ Sltu(AT, lhs_low, rhs_low); | 
|  | 3014 | __ Or(TMP, TMP, AT); | 
|  | 3015 | __ Beqz(TMP, label); | 
|  | 3016 | break; | 
|  | 3017 | case kCondLE: | 
|  | 3018 | __ Blt(lhs_high, rhs_high, label); | 
|  | 3019 | __ Slt(TMP, rhs_high, lhs_high); | 
|  | 3020 | __ Sltu(AT, rhs_low, lhs_low); | 
|  | 3021 | __ Or(TMP, TMP, AT); | 
|  | 3022 | __ Beqz(TMP, label); | 
|  | 3023 | break; | 
|  | 3024 | case kCondGT: | 
|  | 3025 | __ Blt(rhs_high, lhs_high, label); | 
|  | 3026 | __ Slt(TMP, lhs_high, rhs_high); | 
|  | 3027 | __ Sltu(AT, rhs_low, lhs_low); | 
|  | 3028 | __ Blt(TMP, AT, label); | 
|  | 3029 | break; | 
|  | 3030 | case kCondB: | 
|  | 3031 | __ Bltu(lhs_high, rhs_high, label); | 
|  | 3032 | __ Sltu(TMP, rhs_high, lhs_high); | 
|  | 3033 | __ Sltu(AT, lhs_low, rhs_low); | 
|  | 3034 | __ Blt(TMP, AT, label); | 
|  | 3035 | break; | 
|  | 3036 | case kCondAE: | 
|  | 3037 | __ Bltu(rhs_high, lhs_high, label); | 
|  | 3038 | __ Sltu(TMP, lhs_high, rhs_high); | 
|  | 3039 | __ Sltu(AT, lhs_low, rhs_low); | 
|  | 3040 | __ Or(TMP, TMP, AT); | 
|  | 3041 | __ Beqz(TMP, label); | 
|  | 3042 | break; | 
|  | 3043 | case kCondBE: | 
|  | 3044 | __ Bltu(lhs_high, rhs_high, label); | 
|  | 3045 | __ Sltu(TMP, rhs_high, lhs_high); | 
|  | 3046 | __ Sltu(AT, rhs_low, lhs_low); | 
|  | 3047 | __ Or(TMP, TMP, AT); | 
|  | 3048 | __ Beqz(TMP, label); | 
|  | 3049 | break; | 
|  | 3050 | case kCondA: | 
|  | 3051 | __ Bltu(rhs_high, lhs_high, label); | 
|  | 3052 | __ Sltu(TMP, lhs_high, rhs_high); | 
|  | 3053 | __ Sltu(AT, rhs_low, lhs_low); | 
|  | 3054 | __ Blt(TMP, AT, label); | 
|  | 3055 | break; | 
|  | 3056 | } | 
|  | 3057 | } | 
|  | 3058 | } | 
|  | 3059 |  | 
|  | 3060 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, | 
|  | 3061 | bool gt_bias, | 
|  | 3062 | Primitive::Type type, | 
|  | 3063 | LocationSummary* locations, | 
|  | 3064 | MipsLabel* label) { | 
|  | 3065 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 3066 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); | 
|  | 3067 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); | 
|  | 3068 | if (type == Primitive::kPrimFloat) { | 
|  | 3069 | if (isR6) { | 
|  | 3070 | switch (cond) { | 
|  | 3071 | case kCondEQ: | 
|  | 3072 | __ CmpEqS(FTMP, lhs, rhs); | 
|  | 3073 | __ Bc1nez(FTMP, label); | 
|  | 3074 | break; | 
|  | 3075 | case kCondNE: | 
|  | 3076 | __ CmpEqS(FTMP, lhs, rhs); | 
|  | 3077 | __ Bc1eqz(FTMP, label); | 
|  | 3078 | break; | 
|  | 3079 | case kCondLT: | 
|  | 3080 | if (gt_bias) { | 
|  | 3081 | __ CmpLtS(FTMP, lhs, rhs); | 
|  | 3082 | } else { | 
|  | 3083 | __ CmpUltS(FTMP, lhs, rhs); | 
|  | 3084 | } | 
|  | 3085 | __ Bc1nez(FTMP, label); | 
|  | 3086 | break; | 
|  | 3087 | case kCondLE: | 
|  | 3088 | if (gt_bias) { | 
|  | 3089 | __ CmpLeS(FTMP, lhs, rhs); | 
|  | 3090 | } else { | 
|  | 3091 | __ CmpUleS(FTMP, lhs, rhs); | 
|  | 3092 | } | 
|  | 3093 | __ Bc1nez(FTMP, label); | 
|  | 3094 | break; | 
|  | 3095 | case kCondGT: | 
|  | 3096 | if (gt_bias) { | 
|  | 3097 | __ CmpUltS(FTMP, rhs, lhs); | 
|  | 3098 | } else { | 
|  | 3099 | __ CmpLtS(FTMP, rhs, lhs); | 
|  | 3100 | } | 
|  | 3101 | __ Bc1nez(FTMP, label); | 
|  | 3102 | break; | 
|  | 3103 | case kCondGE: | 
|  | 3104 | if (gt_bias) { | 
|  | 3105 | __ CmpUleS(FTMP, rhs, lhs); | 
|  | 3106 | } else { | 
|  | 3107 | __ CmpLeS(FTMP, rhs, lhs); | 
|  | 3108 | } | 
|  | 3109 | __ Bc1nez(FTMP, label); | 
|  | 3110 | break; | 
|  | 3111 | default: | 
|  | 3112 | LOG(FATAL) << "Unexpected non-floating-point condition"; | 
|  | 3113 | } | 
|  | 3114 | } else { | 
|  | 3115 | switch (cond) { | 
|  | 3116 | case kCondEQ: | 
|  | 3117 | __ CeqS(0, lhs, rhs); | 
|  | 3118 | __ Bc1t(0, label); | 
|  | 3119 | break; | 
|  | 3120 | case kCondNE: | 
|  | 3121 | __ CeqS(0, lhs, rhs); | 
|  | 3122 | __ Bc1f(0, label); | 
|  | 3123 | break; | 
|  | 3124 | case kCondLT: | 
|  | 3125 | if (gt_bias) { | 
|  | 3126 | __ ColtS(0, lhs, rhs); | 
|  | 3127 | } else { | 
|  | 3128 | __ CultS(0, lhs, rhs); | 
|  | 3129 | } | 
|  | 3130 | __ Bc1t(0, label); | 
|  | 3131 | break; | 
|  | 3132 | case kCondLE: | 
|  | 3133 | if (gt_bias) { | 
|  | 3134 | __ ColeS(0, lhs, rhs); | 
|  | 3135 | } else { | 
|  | 3136 | __ CuleS(0, lhs, rhs); | 
|  | 3137 | } | 
|  | 3138 | __ Bc1t(0, label); | 
|  | 3139 | break; | 
|  | 3140 | case kCondGT: | 
|  | 3141 | if (gt_bias) { | 
|  | 3142 | __ CultS(0, rhs, lhs); | 
|  | 3143 | } else { | 
|  | 3144 | __ ColtS(0, rhs, lhs); | 
|  | 3145 | } | 
|  | 3146 | __ Bc1t(0, label); | 
|  | 3147 | break; | 
|  | 3148 | case kCondGE: | 
|  | 3149 | if (gt_bias) { | 
|  | 3150 | __ CuleS(0, rhs, lhs); | 
|  | 3151 | } else { | 
|  | 3152 | __ ColeS(0, rhs, lhs); | 
|  | 3153 | } | 
|  | 3154 | __ Bc1t(0, label); | 
|  | 3155 | break; | 
|  | 3156 | default: | 
|  | 3157 | LOG(FATAL) << "Unexpected non-floating-point condition"; | 
|  | 3158 | } | 
|  | 3159 | } | 
|  | 3160 | } else { | 
|  | 3161 | DCHECK_EQ(type, Primitive::kPrimDouble); | 
|  | 3162 | if (isR6) { | 
|  | 3163 | switch (cond) { | 
|  | 3164 | case kCondEQ: | 
|  | 3165 | __ CmpEqD(FTMP, lhs, rhs); | 
|  | 3166 | __ Bc1nez(FTMP, label); | 
|  | 3167 | break; | 
|  | 3168 | case kCondNE: | 
|  | 3169 | __ CmpEqD(FTMP, lhs, rhs); | 
|  | 3170 | __ Bc1eqz(FTMP, label); | 
|  | 3171 | break; | 
|  | 3172 | case kCondLT: | 
|  | 3173 | if (gt_bias) { | 
|  | 3174 | __ CmpLtD(FTMP, lhs, rhs); | 
|  | 3175 | } else { | 
|  | 3176 | __ CmpUltD(FTMP, lhs, rhs); | 
|  | 3177 | } | 
|  | 3178 | __ Bc1nez(FTMP, label); | 
|  | 3179 | break; | 
|  | 3180 | case kCondLE: | 
|  | 3181 | if (gt_bias) { | 
|  | 3182 | __ CmpLeD(FTMP, lhs, rhs); | 
|  | 3183 | } else { | 
|  | 3184 | __ CmpUleD(FTMP, lhs, rhs); | 
|  | 3185 | } | 
|  | 3186 | __ Bc1nez(FTMP, label); | 
|  | 3187 | break; | 
|  | 3188 | case kCondGT: | 
|  | 3189 | if (gt_bias) { | 
|  | 3190 | __ CmpUltD(FTMP, rhs, lhs); | 
|  | 3191 | } else { | 
|  | 3192 | __ CmpLtD(FTMP, rhs, lhs); | 
|  | 3193 | } | 
|  | 3194 | __ Bc1nez(FTMP, label); | 
|  | 3195 | break; | 
|  | 3196 | case kCondGE: | 
|  | 3197 | if (gt_bias) { | 
|  | 3198 | __ CmpUleD(FTMP, rhs, lhs); | 
|  | 3199 | } else { | 
|  | 3200 | __ CmpLeD(FTMP, rhs, lhs); | 
|  | 3201 | } | 
|  | 3202 | __ Bc1nez(FTMP, label); | 
|  | 3203 | break; | 
|  | 3204 | default: | 
|  | 3205 | LOG(FATAL) << "Unexpected non-floating-point condition"; | 
|  | 3206 | } | 
|  | 3207 | } else { | 
|  | 3208 | switch (cond) { | 
|  | 3209 | case kCondEQ: | 
|  | 3210 | __ CeqD(0, lhs, rhs); | 
|  | 3211 | __ Bc1t(0, label); | 
|  | 3212 | break; | 
|  | 3213 | case kCondNE: | 
|  | 3214 | __ CeqD(0, lhs, rhs); | 
|  | 3215 | __ Bc1f(0, label); | 
|  | 3216 | break; | 
|  | 3217 | case kCondLT: | 
|  | 3218 | if (gt_bias) { | 
|  | 3219 | __ ColtD(0, lhs, rhs); | 
|  | 3220 | } else { | 
|  | 3221 | __ CultD(0, lhs, rhs); | 
|  | 3222 | } | 
|  | 3223 | __ Bc1t(0, label); | 
|  | 3224 | break; | 
|  | 3225 | case kCondLE: | 
|  | 3226 | if (gt_bias) { | 
|  | 3227 | __ ColeD(0, lhs, rhs); | 
|  | 3228 | } else { | 
|  | 3229 | __ CuleD(0, lhs, rhs); | 
|  | 3230 | } | 
|  | 3231 | __ Bc1t(0, label); | 
|  | 3232 | break; | 
|  | 3233 | case kCondGT: | 
|  | 3234 | if (gt_bias) { | 
|  | 3235 | __ CultD(0, rhs, lhs); | 
|  | 3236 | } else { | 
|  | 3237 | __ ColtD(0, rhs, lhs); | 
|  | 3238 | } | 
|  | 3239 | __ Bc1t(0, label); | 
|  | 3240 | break; | 
|  | 3241 | case kCondGE: | 
|  | 3242 | if (gt_bias) { | 
|  | 3243 | __ CuleD(0, rhs, lhs); | 
|  | 3244 | } else { | 
|  | 3245 | __ ColeD(0, rhs, lhs); | 
|  | 3246 | } | 
|  | 3247 | __ Bc1t(0, label); | 
|  | 3248 | break; | 
|  | 3249 | default: | 
|  | 3250 | LOG(FATAL) << "Unexpected non-floating-point condition"; | 
|  | 3251 | } | 
|  | 3252 | } | 
|  | 3253 | } | 
|  | 3254 | } | 
|  | 3255 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3256 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3257 | size_t condition_input_index, | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3258 | MipsLabel* true_target, | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3259 | MipsLabel* false_target) { | 
|  | 3260 | HInstruction* cond = instruction->InputAt(condition_input_index); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3261 |  | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3262 | if (true_target == nullptr && false_target == nullptr) { | 
|  | 3263 | // Nothing to do. The code always falls through. | 
|  | 3264 | return; | 
|  | 3265 | } else if (cond->IsIntConstant()) { | 
|  | 3266 | // Constant condition, statically compared against 1. | 
|  | 3267 | if (cond->AsIntConstant()->IsOne()) { | 
|  | 3268 | if (true_target != nullptr) { | 
|  | 3269 | __ B(true_target); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3270 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3271 | } else { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3272 | DCHECK(cond->AsIntConstant()->IsZero()); | 
|  | 3273 | if (false_target != nullptr) { | 
|  | 3274 | __ B(false_target); | 
|  | 3275 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3276 | } | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3277 | return; | 
|  | 3278 | } | 
|  | 3279 |  | 
|  | 3280 | // The following code generates these patterns: | 
|  | 3281 | //  (1) true_target == nullptr && false_target != nullptr | 
|  | 3282 | //        - opposite condition true => branch to false_target | 
|  | 3283 | //  (2) true_target != nullptr && false_target == nullptr | 
|  | 3284 | //        - condition true => branch to true_target | 
|  | 3285 | //  (3) true_target != nullptr && false_target != nullptr | 
|  | 3286 | //        - condition true => branch to true_target | 
|  | 3287 | //        - branch to false_target | 
|  | 3288 | if (IsBooleanValueOrMaterializedCondition(cond)) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3289 | // The condition instruction has been materialized, compare the output to 0. | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3290 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3291 | DCHECK(cond_val.IsRegister()); | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3292 | if (true_target == nullptr) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3293 | __ Beqz(cond_val.AsRegister<Register>(), false_target); | 
|  | 3294 | } else { | 
|  | 3295 | __ Bnez(cond_val.AsRegister<Register>(), true_target); | 
|  | 3296 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3297 | } else { | 
|  | 3298 | // The condition instruction has not been materialized, use its inputs as | 
|  | 3299 | // the comparison and its condition as the branch condition. | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3300 | HCondition* condition = cond->AsCondition(); | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3301 | Primitive::Type type = condition->InputAt(0)->GetType(); | 
|  | 3302 | LocationSummary* locations = cond->GetLocations(); | 
|  | 3303 | IfCondition if_cond = condition->GetCondition(); | 
|  | 3304 | MipsLabel* branch_target = true_target; | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3305 |  | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3306 | if (true_target == nullptr) { | 
|  | 3307 | if_cond = condition->GetOppositeCondition(); | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3308 | branch_target = false_target; | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3309 | } | 
|  | 3310 |  | 
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3311 | switch (type) { | 
|  | 3312 | default: | 
|  | 3313 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); | 
|  | 3314 | break; | 
|  | 3315 | case Primitive::kPrimLong: | 
|  | 3316 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); | 
|  | 3317 | break; | 
|  | 3318 | case Primitive::kPrimFloat: | 
|  | 3319 | case Primitive::kPrimDouble: | 
|  | 3320 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); | 
|  | 3321 | break; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3322 | } | 
|  | 3323 | } | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3324 |  | 
|  | 3325 | // If neither branch falls through (case 3), the conditional branch to `true_target` | 
|  | 3326 | // was already emitted (case 2) and we need to emit a jump to `false_target`. | 
|  | 3327 | if (true_target != nullptr && false_target != nullptr) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3328 | __ B(false_target); | 
|  | 3329 | } | 
|  | 3330 | } | 
|  | 3331 |  | 
|  | 3332 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { | 
|  | 3333 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3334 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3335 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3336 | } | 
|  | 3337 | } | 
|  | 3338 |  | 
|  | 3339 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3340 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); | 
|  | 3341 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); | 
|  | 3342 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? | 
|  | 3343 | nullptr : codegen_->GetLabelOf(true_successor); | 
|  | 3344 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? | 
|  | 3345 | nullptr : codegen_->GetLabelOf(false_successor); | 
|  | 3346 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3347 | } | 
|  | 3348 |  | 
|  | 3349 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { | 
|  | 3350 | LocationSummary* locations = new (GetGraph()->GetArena()) | 
|  | 3351 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3352 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3353 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3354 | } | 
|  | 3355 | } | 
|  | 3356 |  | 
|  | 3357 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3358 | SlowPathCodeMIPS* slow_path = | 
|  | 3359 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3360 | GenerateTestAndBranch(deoptimize, | 
|  | 3361 | /* condition_input_index */ 0, | 
|  | 3362 | slow_path->GetEntryLabel(), | 
|  | 3363 | /* false_target */ nullptr); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3364 | } | 
|  | 3365 |  | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3366 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { | 
|  | 3367 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); | 
|  | 3368 | if (Primitive::IsFloatingPointType(select->GetType())) { | 
|  | 3369 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 3370 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 3371 | } else { | 
|  | 3372 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3373 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 3374 | } | 
|  | 3375 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { | 
|  | 3376 | locations->SetInAt(2, Location::RequiresRegister()); | 
|  | 3377 | } | 
|  | 3378 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3379 | } | 
|  | 3380 |  | 
|  | 3381 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { | 
|  | 3382 | LocationSummary* locations = select->GetLocations(); | 
|  | 3383 | MipsLabel false_target; | 
|  | 3384 | GenerateTestAndBranch(select, | 
|  | 3385 | /* condition_input_index */ 2, | 
|  | 3386 | /* true_target */ nullptr, | 
|  | 3387 | &false_target); | 
|  | 3388 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); | 
|  | 3389 | __ Bind(&false_target); | 
|  | 3390 | } | 
|  | 3391 |  | 
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3392 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { | 
|  | 3393 | new (GetGraph()->GetArena()) LocationSummary(info); | 
|  | 3394 | } | 
|  | 3395 |  | 
|  | 3396 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { | 
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3397 | codegen_->MaybeRecordNativeDebugInfo(info, info->GetDexPc()); | 
|  | 3398 | } | 
|  | 3399 |  | 
|  | 3400 | void CodeGeneratorMIPS::GenerateNop() { | 
|  | 3401 | __ Nop(); | 
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3402 | } | 
|  | 3403 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3404 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { | 
|  | 3405 | Primitive::Type field_type = field_info.GetFieldType(); | 
|  | 3406 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); | 
|  | 3407 | bool generate_volatile = field_info.IsVolatile() && is_wide; | 
|  | 3408 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( | 
|  | 3409 | instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall); | 
|  | 3410 |  | 
|  | 3411 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3412 | if (generate_volatile) { | 
|  | 3413 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3414 | // need A0 to hold base + offset | 
|  | 3415 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 3416 | if (field_type == Primitive::kPrimLong) { | 
|  | 3417 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong)); | 
|  | 3418 | } else { | 
|  | 3419 | locations->SetOut(Location::RequiresFpuRegister()); | 
|  | 3420 | // Need some temp core regs since FP results are returned in core registers | 
|  | 3421 | Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong); | 
|  | 3422 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); | 
|  | 3423 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); | 
|  | 3424 | } | 
|  | 3425 | } else { | 
|  | 3426 | if (Primitive::IsFloatingPointType(instruction->GetType())) { | 
|  | 3427 | locations->SetOut(Location::RequiresFpuRegister()); | 
|  | 3428 | } else { | 
|  | 3429 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3430 | } | 
|  | 3431 | } | 
|  | 3432 | } | 
|  | 3433 |  | 
|  | 3434 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, | 
|  | 3435 | const FieldInfo& field_info, | 
|  | 3436 | uint32_t dex_pc) { | 
|  | 3437 | Primitive::Type type = field_info.GetFieldType(); | 
|  | 3438 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3439 | Register obj = locations->InAt(0).AsRegister<Register>(); | 
|  | 3440 | LoadOperandType load_type = kLoadUnsignedByte; | 
|  | 3441 | bool is_volatile = field_info.IsVolatile(); | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3442 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3443 |  | 
|  | 3444 | switch (type) { | 
|  | 3445 | case Primitive::kPrimBoolean: | 
|  | 3446 | load_type = kLoadUnsignedByte; | 
|  | 3447 | break; | 
|  | 3448 | case Primitive::kPrimByte: | 
|  | 3449 | load_type = kLoadSignedByte; | 
|  | 3450 | break; | 
|  | 3451 | case Primitive::kPrimShort: | 
|  | 3452 | load_type = kLoadSignedHalfword; | 
|  | 3453 | break; | 
|  | 3454 | case Primitive::kPrimChar: | 
|  | 3455 | load_type = kLoadUnsignedHalfword; | 
|  | 3456 | break; | 
|  | 3457 | case Primitive::kPrimInt: | 
|  | 3458 | case Primitive::kPrimFloat: | 
|  | 3459 | case Primitive::kPrimNot: | 
|  | 3460 | load_type = kLoadWord; | 
|  | 3461 | break; | 
|  | 3462 | case Primitive::kPrimLong: | 
|  | 3463 | case Primitive::kPrimDouble: | 
|  | 3464 | load_type = kLoadDoubleword; | 
|  | 3465 | break; | 
|  | 3466 | case Primitive::kPrimVoid: | 
|  | 3467 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 3468 | UNREACHABLE(); | 
|  | 3469 | } | 
|  | 3470 |  | 
|  | 3471 | if (is_volatile && load_type == kLoadDoubleword) { | 
|  | 3472 | InvokeRuntimeCallingConvention calling_convention; | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3473 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3474 | // Do implicit Null check | 
|  | 3475 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); | 
|  | 3476 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); | 
|  | 3477 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Load), | 
|  | 3478 | instruction, | 
|  | 3479 | dex_pc, | 
|  | 3480 | nullptr, | 
|  | 3481 | IsDirectEntrypoint(kQuickA64Load)); | 
|  | 3482 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); | 
|  | 3483 | if (type == Primitive::kPrimDouble) { | 
|  | 3484 | // Need to move to FP regs since FP results are returned in core registers. | 
|  | 3485 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), | 
|  | 3486 | locations->Out().AsFpuRegister<FRegister>()); | 
| Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 3487 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), | 
|  | 3488 | locations->Out().AsFpuRegister<FRegister>()); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3489 | } | 
|  | 3490 | } else { | 
|  | 3491 | if (!Primitive::IsFloatingPointType(type)) { | 
|  | 3492 | Register dst; | 
|  | 3493 | if (type == Primitive::kPrimLong) { | 
|  | 3494 | DCHECK(locations->Out().IsRegisterPair()); | 
|  | 3495 | dst = locations->Out().AsRegisterPairLow<Register>(); | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3496 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); | 
|  | 3497 | if (obj == dst) { | 
|  | 3498 | __ LoadFromOffset(kLoadWord, dst_high, obj, offset + kMipsWordSize); | 
|  | 3499 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 3500 | __ LoadFromOffset(kLoadWord, dst, obj, offset); | 
|  | 3501 | } else { | 
|  | 3502 | __ LoadFromOffset(kLoadWord, dst, obj, offset); | 
|  | 3503 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 3504 | __ LoadFromOffset(kLoadWord, dst_high, obj, offset + kMipsWordSize); | 
|  | 3505 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3506 | } else { | 
|  | 3507 | DCHECK(locations->Out().IsRegister()); | 
|  | 3508 | dst = locations->Out().AsRegister<Register>(); | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3509 | __ LoadFromOffset(load_type, dst, obj, offset); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3510 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3511 | } else { | 
|  | 3512 | DCHECK(locations->Out().IsFpuRegister()); | 
|  | 3513 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 3514 | if (type == Primitive::kPrimFloat) { | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3515 | __ LoadSFromOffset(dst, obj, offset); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3516 | } else { | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3517 | __ LoadDFromOffset(dst, obj, offset); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3518 | } | 
|  | 3519 | } | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3520 | // Longs are handled earlier. | 
|  | 3521 | if (type != Primitive::kPrimLong) { | 
|  | 3522 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 3523 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3524 | } | 
|  | 3525 |  | 
|  | 3526 | if (is_volatile) { | 
|  | 3527 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); | 
|  | 3528 | } | 
|  | 3529 | } | 
|  | 3530 |  | 
|  | 3531 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { | 
|  | 3532 | Primitive::Type field_type = field_info.GetFieldType(); | 
|  | 3533 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); | 
|  | 3534 | bool generate_volatile = field_info.IsVolatile() && is_wide; | 
|  | 3535 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( | 
|  | 3536 | instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall); | 
|  | 3537 |  | 
|  | 3538 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3539 | if (generate_volatile) { | 
|  | 3540 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3541 | // need A0 to hold base + offset | 
|  | 3542 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 3543 | if (field_type == Primitive::kPrimLong) { | 
|  | 3544 | locations->SetInAt(1, Location::RegisterPairLocation( | 
|  | 3545 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); | 
|  | 3546 | } else { | 
|  | 3547 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 3548 | // Pass FP parameters in core registers. | 
|  | 3549 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); | 
|  | 3550 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); | 
|  | 3551 | } | 
|  | 3552 | } else { | 
|  | 3553 | if (Primitive::IsFloatingPointType(field_type)) { | 
|  | 3554 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 3555 | } else { | 
|  | 3556 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 3557 | } | 
|  | 3558 | } | 
|  | 3559 | } | 
|  | 3560 |  | 
|  | 3561 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, | 
|  | 3562 | const FieldInfo& field_info, | 
|  | 3563 | uint32_t dex_pc) { | 
|  | 3564 | Primitive::Type type = field_info.GetFieldType(); | 
|  | 3565 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3566 | Register obj = locations->InAt(0).AsRegister<Register>(); | 
|  | 3567 | StoreOperandType store_type = kStoreByte; | 
|  | 3568 | bool is_volatile = field_info.IsVolatile(); | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3569 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3570 |  | 
|  | 3571 | switch (type) { | 
|  | 3572 | case Primitive::kPrimBoolean: | 
|  | 3573 | case Primitive::kPrimByte: | 
|  | 3574 | store_type = kStoreByte; | 
|  | 3575 | break; | 
|  | 3576 | case Primitive::kPrimShort: | 
|  | 3577 | case Primitive::kPrimChar: | 
|  | 3578 | store_type = kStoreHalfword; | 
|  | 3579 | break; | 
|  | 3580 | case Primitive::kPrimInt: | 
|  | 3581 | case Primitive::kPrimFloat: | 
|  | 3582 | case Primitive::kPrimNot: | 
|  | 3583 | store_type = kStoreWord; | 
|  | 3584 | break; | 
|  | 3585 | case Primitive::kPrimLong: | 
|  | 3586 | case Primitive::kPrimDouble: | 
|  | 3587 | store_type = kStoreDoubleword; | 
|  | 3588 | break; | 
|  | 3589 | case Primitive::kPrimVoid: | 
|  | 3590 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 3591 | UNREACHABLE(); | 
|  | 3592 | } | 
|  | 3593 |  | 
|  | 3594 | if (is_volatile) { | 
|  | 3595 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); | 
|  | 3596 | } | 
|  | 3597 |  | 
|  | 3598 | if (is_volatile && store_type == kStoreDoubleword) { | 
|  | 3599 | InvokeRuntimeCallingConvention calling_convention; | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3600 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3601 | // Do implicit Null check. | 
|  | 3602 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); | 
|  | 3603 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); | 
|  | 3604 | if (type == Primitive::kPrimDouble) { | 
|  | 3605 | // Pass FP parameters in core registers. | 
|  | 3606 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), | 
|  | 3607 | locations->InAt(1).AsFpuRegister<FRegister>()); | 
| Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 3608 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), | 
|  | 3609 | locations->InAt(1).AsFpuRegister<FRegister>()); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3610 | } | 
|  | 3611 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Store), | 
|  | 3612 | instruction, | 
|  | 3613 | dex_pc, | 
|  | 3614 | nullptr, | 
|  | 3615 | IsDirectEntrypoint(kQuickA64Store)); | 
|  | 3616 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); | 
|  | 3617 | } else { | 
|  | 3618 | if (!Primitive::IsFloatingPointType(type)) { | 
|  | 3619 | Register src; | 
|  | 3620 | if (type == Primitive::kPrimLong) { | 
|  | 3621 | DCHECK(locations->InAt(1).IsRegisterPair()); | 
|  | 3622 | src = locations->InAt(1).AsRegisterPairLow<Register>(); | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3623 | Register src_high = locations->InAt(1).AsRegisterPairHigh<Register>(); | 
|  | 3624 | __ StoreToOffset(kStoreWord, src, obj, offset); | 
|  | 3625 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 3626 | __ StoreToOffset(kStoreWord, src_high, obj, offset + kMipsWordSize); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3627 | } else { | 
|  | 3628 | DCHECK(locations->InAt(1).IsRegister()); | 
|  | 3629 | src = locations->InAt(1).AsRegister<Register>(); | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3630 | __ StoreToOffset(store_type, src, obj, offset); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3631 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3632 | } else { | 
|  | 3633 | DCHECK(locations->InAt(1).IsFpuRegister()); | 
|  | 3634 | FRegister src = locations->InAt(1).AsFpuRegister<FRegister>(); | 
|  | 3635 | if (type == Primitive::kPrimFloat) { | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3636 | __ StoreSToOffset(src, obj, offset); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3637 | } else { | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3638 | __ StoreDToOffset(src, obj, offset); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3639 | } | 
|  | 3640 | } | 
| Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3641 | // Longs are handled earlier. | 
|  | 3642 | if (type != Primitive::kPrimLong) { | 
|  | 3643 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 3644 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3645 | } | 
|  | 3646 |  | 
|  | 3647 | // TODO: memory barriers? | 
|  | 3648 | if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) { | 
|  | 3649 | DCHECK(locations->InAt(1).IsRegister()); | 
|  | 3650 | Register src = locations->InAt(1).AsRegister<Register>(); | 
|  | 3651 | codegen_->MarkGCCard(obj, src); | 
|  | 3652 | } | 
|  | 3653 |  | 
|  | 3654 | if (is_volatile) { | 
|  | 3655 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); | 
|  | 3656 | } | 
|  | 3657 | } | 
|  | 3658 |  | 
|  | 3659 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
|  | 3660 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
|  | 3661 | } | 
|  | 3662 |  | 
|  | 3663 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
|  | 3664 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); | 
|  | 3665 | } | 
|  | 3666 |  | 
|  | 3667 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
|  | 3668 | HandleFieldSet(instruction, instruction->GetFieldInfo()); | 
|  | 3669 | } | 
|  | 3670 |  | 
|  | 3671 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
|  | 3672 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); | 
|  | 3673 | } | 
|  | 3674 |  | 
|  | 3675 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { | 
|  | 3676 | LocationSummary::CallKind call_kind = | 
|  | 3677 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; | 
|  | 3678 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
|  | 3679 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3680 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 3681 | // The output does overlap inputs. | 
|  | 3682 | // Note that TypeCheckSlowPathMIPS uses this register too. | 
|  | 3683 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); | 
|  | 3684 | } | 
|  | 3685 |  | 
|  | 3686 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { | 
|  | 3687 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3688 | Register obj = locations->InAt(0).AsRegister<Register>(); | 
|  | 3689 | Register cls = locations->InAt(1).AsRegister<Register>(); | 
|  | 3690 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 3691 |  | 
|  | 3692 | MipsLabel done; | 
|  | 3693 |  | 
|  | 3694 | // Return 0 if `obj` is null. | 
|  | 3695 | // TODO: Avoid this check if we know `obj` is not null. | 
|  | 3696 | __ Move(out, ZERO); | 
|  | 3697 | __ Beqz(obj, &done); | 
|  | 3698 |  | 
|  | 3699 | // Compare the class of `obj` with `cls`. | 
|  | 3700 | __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value()); | 
|  | 3701 | if (instruction->IsExactCheck()) { | 
|  | 3702 | // Classes must be equal for the instanceof to succeed. | 
|  | 3703 | __ Xor(out, out, cls); | 
|  | 3704 | __ Sltiu(out, out, 1); | 
|  | 3705 | } else { | 
|  | 3706 | // If the classes are not equal, we go into a slow path. | 
|  | 3707 | DCHECK(locations->OnlyCallsOnSlowPath()); | 
|  | 3708 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); | 
|  | 3709 | codegen_->AddSlowPath(slow_path); | 
|  | 3710 | __ Bne(out, cls, slow_path->GetEntryLabel()); | 
|  | 3711 | __ LoadConst32(out, 1); | 
|  | 3712 | __ Bind(slow_path->GetExitLabel()); | 
|  | 3713 | } | 
|  | 3714 |  | 
|  | 3715 | __ Bind(&done); | 
|  | 3716 | } | 
|  | 3717 |  | 
|  | 3718 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { | 
|  | 3719 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); | 
|  | 3720 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 3721 | } | 
|  | 3722 |  | 
|  | 3723 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { | 
|  | 3724 | // Will be generated at use site. | 
|  | 3725 | } | 
|  | 3726 |  | 
|  | 3727 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { | 
|  | 3728 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); | 
|  | 3729 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 3730 | } | 
|  | 3731 |  | 
|  | 3732 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { | 
|  | 3733 | // Will be generated at use site. | 
|  | 3734 | } | 
|  | 3735 |  | 
|  | 3736 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { | 
|  | 3737 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; | 
|  | 3738 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); | 
|  | 3739 | } | 
|  | 3740 |  | 
|  | 3741 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { | 
|  | 3742 | HandleInvoke(invoke); | 
|  | 3743 | // The register T0 is required to be used for the hidden argument in | 
|  | 3744 | // art_quick_imt_conflict_trampoline, so add the hidden argument. | 
|  | 3745 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); | 
|  | 3746 | } | 
|  | 3747 |  | 
|  | 3748 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { | 
|  | 3749 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. | 
|  | 3750 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); | 
|  | 3751 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( | 
|  | 3752 | invoke->GetImtIndex() % mirror::Class::kImtSize, kMipsPointerSize).Uint32Value(); | 
|  | 3753 | Location receiver = invoke->GetLocations()->InAt(0); | 
|  | 3754 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
|  | 3755 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize); | 
|  | 3756 |  | 
|  | 3757 | // Set the hidden argument. | 
|  | 3758 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), | 
|  | 3759 | invoke->GetDexMethodIndex()); | 
|  | 3760 |  | 
|  | 3761 | // temp = object->GetClass(); | 
|  | 3762 | if (receiver.IsStackSlot()) { | 
|  | 3763 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); | 
|  | 3764 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); | 
|  | 3765 | } else { | 
|  | 3766 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); | 
|  | 3767 | } | 
|  | 3768 | codegen_->MaybeRecordImplicitNullCheck(invoke); | 
|  | 3769 | // temp = temp->GetImtEntryAt(method_offset); | 
|  | 3770 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); | 
|  | 3771 | // T9 = temp->GetEntryPoint(); | 
|  | 3772 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); | 
|  | 3773 | // T9(); | 
|  | 3774 | __ Jalr(T9); | 
|  | 3775 | __ Nop(); | 
|  | 3776 | DCHECK(!codegen_->IsLeafMethod()); | 
|  | 3777 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
|  | 3778 | } | 
|  | 3779 |  | 
|  | 3780 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
| Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 3781 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); | 
|  | 3782 | if (intrinsic.TryDispatch(invoke)) { | 
|  | 3783 | return; | 
|  | 3784 | } | 
|  | 3785 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3786 | HandleInvoke(invoke); | 
|  | 3787 | } | 
|  | 3788 |  | 
|  | 3789 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3790 | // Explicit clinit checks triggered by static invokes must have been pruned by | 
|  | 3791 | // art::PrepareForRegisterAllocation. | 
|  | 3792 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3793 |  | 
| Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 3794 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); | 
|  | 3795 | if (intrinsic.TryDispatch(invoke)) { | 
|  | 3796 | return; | 
|  | 3797 | } | 
|  | 3798 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3799 | HandleInvoke(invoke); | 
|  | 3800 | } | 
|  | 3801 |  | 
| Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 3802 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3803 | if (invoke->GetLocations()->Intrinsified()) { | 
| Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 3804 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); | 
|  | 3805 | intrinsic.Dispatch(invoke); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3806 | return true; | 
|  | 3807 | } | 
|  | 3808 | return false; | 
|  | 3809 | } | 
|  | 3810 |  | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3811 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( | 
|  | 3812 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, | 
|  | 3813 | MethodReference target_method ATTRIBUTE_UNUSED) { | 
|  | 3814 | switch (desired_dispatch_info.method_load_kind) { | 
|  | 3815 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: | 
|  | 3816 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: | 
|  | 3817 | // TODO: Implement these types. For the moment, we fall back to kDexCacheViaMethod. | 
|  | 3818 | return HInvokeStaticOrDirect::DispatchInfo { | 
|  | 3819 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, | 
|  | 3820 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, | 
|  | 3821 | 0u, | 
|  | 3822 | 0u | 
|  | 3823 | }; | 
|  | 3824 | default: | 
|  | 3825 | break; | 
|  | 3826 | } | 
|  | 3827 | switch (desired_dispatch_info.code_ptr_location) { | 
|  | 3828 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: | 
|  | 3829 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: | 
|  | 3830 | // TODO: Implement these types. For the moment, we fall back to kCallArtMethod. | 
|  | 3831 | return HInvokeStaticOrDirect::DispatchInfo { | 
|  | 3832 | desired_dispatch_info.method_load_kind, | 
|  | 3833 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, | 
|  | 3834 | desired_dispatch_info.method_load_data, | 
|  | 3835 | 0u | 
|  | 3836 | }; | 
|  | 3837 | default: | 
|  | 3838 | return desired_dispatch_info; | 
|  | 3839 | } | 
|  | 3840 | } | 
|  | 3841 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3842 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { | 
|  | 3843 | // All registers are assumed to be correctly set up per the calling convention. | 
|  | 3844 |  | 
|  | 3845 | Location callee_method = temp;  // For all kinds except kRecursive, callee will be in temp. | 
|  | 3846 | switch (invoke->GetMethodLoadKind()) { | 
|  | 3847 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: | 
|  | 3848 | // temp = thread->string_init_entrypoint | 
|  | 3849 | __ LoadFromOffset(kLoadWord, | 
|  | 3850 | temp.AsRegister<Register>(), | 
|  | 3851 | TR, | 
|  | 3852 | invoke->GetStringInitOffset()); | 
|  | 3853 | break; | 
|  | 3854 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3855 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3856 | break; | 
|  | 3857 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: | 
|  | 3858 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); | 
|  | 3859 | break; | 
|  | 3860 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3861 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3862 | // TODO: Implement these types. | 
|  | 3863 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). | 
|  | 3864 | LOG(FATAL) << "Unsupported"; | 
|  | 3865 | UNREACHABLE(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3866 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3867 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3868 | Register reg = temp.AsRegister<Register>(); | 
|  | 3869 | Register method_reg; | 
|  | 3870 | if (current_method.IsRegister()) { | 
|  | 3871 | method_reg = current_method.AsRegister<Register>(); | 
|  | 3872 | } else { | 
|  | 3873 | // TODO: use the appropriate DCHECK() here if possible. | 
|  | 3874 | // DCHECK(invoke->GetLocations()->Intrinsified()); | 
|  | 3875 | DCHECK(!current_method.IsValid()); | 
|  | 3876 | method_reg = reg; | 
|  | 3877 | __ Lw(reg, SP, kCurrentMethodStackOffset); | 
|  | 3878 | } | 
|  | 3879 |  | 
|  | 3880 | // temp = temp->dex_cache_resolved_methods_; | 
|  | 3881 | __ LoadFromOffset(kLoadWord, | 
|  | 3882 | reg, | 
|  | 3883 | method_reg, | 
|  | 3884 | ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value()); | 
|  | 3885 | // temp = temp[index_in_cache] | 
|  | 3886 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; | 
|  | 3887 | __ LoadFromOffset(kLoadWord, | 
|  | 3888 | reg, | 
|  | 3889 | reg, | 
|  | 3890 | CodeGenerator::GetCachePointerOffset(index_in_cache)); | 
|  | 3891 | break; | 
|  | 3892 | } | 
|  | 3893 | } | 
|  | 3894 |  | 
|  | 3895 | switch (invoke->GetCodePtrLocation()) { | 
|  | 3896 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: | 
|  | 3897 | __ Jalr(&frame_entry_label_, T9); | 
|  | 3898 | break; | 
|  | 3899 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: | 
|  | 3900 | // LR = invoke->GetDirectCodePtr(); | 
|  | 3901 | __ LoadConst32(T9, invoke->GetDirectCodePtr()); | 
|  | 3902 | // LR() | 
|  | 3903 | __ Jalr(T9); | 
|  | 3904 | __ Nop(); | 
|  | 3905 | break; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3906 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3907 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: | 
|  | 3908 | // TODO: Implement these types. | 
|  | 3909 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). | 
|  | 3910 | LOG(FATAL) << "Unsupported"; | 
|  | 3911 | UNREACHABLE(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3912 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: | 
|  | 3913 | // T9 = callee_method->entry_point_from_quick_compiled_code_; | 
| Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 3914 | __ LoadFromOffset(kLoadWord, | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3915 | T9, | 
|  | 3916 | callee_method.AsRegister<Register>(), | 
|  | 3917 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( | 
|  | 3918 | kMipsWordSize).Int32Value()); | 
|  | 3919 | // T9() | 
|  | 3920 | __ Jalr(T9); | 
|  | 3921 | __ Nop(); | 
|  | 3922 | break; | 
|  | 3923 | } | 
|  | 3924 | DCHECK(!IsLeafMethod()); | 
|  | 3925 | } | 
|  | 3926 |  | 
|  | 3927 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3928 | // Explicit clinit checks triggered by static invokes must have been pruned by | 
|  | 3929 | // art::PrepareForRegisterAllocation. | 
|  | 3930 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3931 |  | 
|  | 3932 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
|  | 3933 | return; | 
|  | 3934 | } | 
|  | 3935 |  | 
|  | 3936 | LocationSummary* locations = invoke->GetLocations(); | 
|  | 3937 | codegen_->GenerateStaticOrDirectCall(invoke, | 
|  | 3938 | locations->HasTemps() | 
|  | 3939 | ? locations->GetTemp(0) | 
|  | 3940 | : Location::NoLocation()); | 
|  | 3941 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
|  | 3942 | } | 
|  | 3943 |  | 
| Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 3944 | void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3945 | LocationSummary* locations = invoke->GetLocations(); | 
|  | 3946 | Location receiver = locations->InAt(0); | 
| Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 3947 | Register temp = temp_location.AsRegister<Register>(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3948 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( | 
|  | 3949 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); | 
|  | 3950 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
|  | 3951 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize); | 
|  | 3952 |  | 
|  | 3953 | // temp = object->GetClass(); | 
| Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 3954 | DCHECK(receiver.IsRegister()); | 
|  | 3955 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); | 
|  | 3956 | MaybeRecordImplicitNullCheck(invoke); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3957 | // temp = temp->GetMethodAt(method_offset); | 
|  | 3958 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); | 
|  | 3959 | // T9 = temp->GetEntryPoint(); | 
|  | 3960 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); | 
|  | 3961 | // T9(); | 
|  | 3962 | __ Jalr(T9); | 
|  | 3963 | __ Nop(); | 
| Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 3964 | } | 
|  | 3965 |  | 
|  | 3966 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
|  | 3967 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
|  | 3968 | return; | 
|  | 3969 | } | 
|  | 3970 |  | 
|  | 3971 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3972 | DCHECK(!codegen_->IsLeafMethod()); | 
|  | 3973 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
|  | 3974 | } | 
|  | 3975 |  | 
|  | 3976 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { | 
| Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 3977 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3978 | CodeGenerator::CreateLoadClassLocationSummary( | 
|  | 3979 | cls, | 
|  | 3980 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
|  | 3981 | Location::RegisterLocation(V0)); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3982 | } | 
|  | 3983 |  | 
|  | 3984 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) { | 
|  | 3985 | LocationSummary* locations = cls->GetLocations(); | 
| Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 3986 | if (cls->NeedsAccessCheck()) { | 
|  | 3987 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); | 
|  | 3988 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), | 
|  | 3989 | cls, | 
|  | 3990 | cls->GetDexPc(), | 
|  | 3991 | nullptr, | 
|  | 3992 | IsDirectEntrypoint(kQuickInitializeTypeAndVerifyAccess)); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3993 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); | 
| Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 3994 | return; | 
|  | 3995 | } | 
|  | 3996 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3997 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 3998 | Register current_method = locations->InAt(0).AsRegister<Register>(); | 
|  | 3999 | if (cls->IsReferrersClass()) { | 
|  | 4000 | DCHECK(!cls->CanCallRuntime()); | 
|  | 4001 | DCHECK(!cls->MustGenerateClinitCheck()); | 
|  | 4002 | __ LoadFromOffset(kLoadWord, out, current_method, | 
|  | 4003 | ArtMethod::DeclaringClassOffset().Int32Value()); | 
|  | 4004 | } else { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4005 | __ LoadFromOffset(kLoadWord, out, current_method, | 
|  | 4006 | ArtMethod::DexCacheResolvedTypesOffset(kMipsPointerSize).Int32Value()); | 
|  | 4007 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); | 
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4008 |  | 
|  | 4009 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { | 
|  | 4010 | DCHECK(cls->CanCallRuntime()); | 
|  | 4011 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( | 
|  | 4012 | cls, | 
|  | 4013 | cls, | 
|  | 4014 | cls->GetDexPc(), | 
|  | 4015 | cls->MustGenerateClinitCheck()); | 
|  | 4016 | codegen_->AddSlowPath(slow_path); | 
|  | 4017 | if (!cls->IsInDexCache()) { | 
|  | 4018 | __ Beqz(out, slow_path->GetEntryLabel()); | 
|  | 4019 | } | 
|  | 4020 | if (cls->MustGenerateClinitCheck()) { | 
|  | 4021 | GenerateClassInitializationCheck(slow_path, out); | 
|  | 4022 | } else { | 
|  | 4023 | __ Bind(slow_path->GetExitLabel()); | 
|  | 4024 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4025 | } | 
|  | 4026 | } | 
|  | 4027 | } | 
|  | 4028 |  | 
|  | 4029 | static int32_t GetExceptionTlsOffset() { | 
|  | 4030 | return Thread::ExceptionOffset<kMipsWordSize>().Int32Value(); | 
|  | 4031 | } | 
|  | 4032 |  | 
|  | 4033 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { | 
|  | 4034 | LocationSummary* locations = | 
|  | 4035 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); | 
|  | 4036 | locations->SetOut(Location::RequiresRegister()); | 
|  | 4037 | } | 
|  | 4038 |  | 
|  | 4039 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { | 
|  | 4040 | Register out = load->GetLocations()->Out().AsRegister<Register>(); | 
|  | 4041 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); | 
|  | 4042 | } | 
|  | 4043 |  | 
|  | 4044 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { | 
|  | 4045 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); | 
|  | 4046 | } | 
|  | 4047 |  | 
|  | 4048 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { | 
|  | 4049 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); | 
|  | 4050 | } | 
|  | 4051 |  | 
|  | 4052 | void LocationsBuilderMIPS::VisitLoadLocal(HLoadLocal* load) { | 
|  | 4053 | load->SetLocations(nullptr); | 
|  | 4054 | } | 
|  | 4055 |  | 
|  | 4056 | void InstructionCodeGeneratorMIPS::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { | 
|  | 4057 | // Nothing to do, this is driven by the code generator. | 
|  | 4058 | } | 
|  | 4059 |  | 
|  | 4060 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { | 
| Roland Levillain | 698fa97 | 2015-12-16 17:06:47 +0000 | [diff] [blame] | 4061 | LocationSummary::CallKind call_kind = load->IsInDexCache() | 
|  | 4062 | ? LocationSummary::kNoCall | 
|  | 4063 | : LocationSummary::kCallOnSlowPath; | 
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4064 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4065 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4066 | locations->SetOut(Location::RequiresRegister()); | 
|  | 4067 | } | 
|  | 4068 |  | 
|  | 4069 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4070 | LocationSummary* locations = load->GetLocations(); | 
|  | 4071 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 4072 | Register current_method = locations->InAt(0).AsRegister<Register>(); | 
|  | 4073 | __ LoadFromOffset(kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); | 
|  | 4074 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); | 
|  | 4075 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); | 
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4076 |  | 
|  | 4077 | if (!load->IsInDexCache()) { | 
|  | 4078 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load); | 
|  | 4079 | codegen_->AddSlowPath(slow_path); | 
|  | 4080 | __ Beqz(out, slow_path->GetEntryLabel()); | 
|  | 4081 | __ Bind(slow_path->GetExitLabel()); | 
|  | 4082 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4083 | } | 
|  | 4084 |  | 
|  | 4085 | void LocationsBuilderMIPS::VisitLocal(HLocal* local) { | 
|  | 4086 | local->SetLocations(nullptr); | 
|  | 4087 | } | 
|  | 4088 |  | 
|  | 4089 | void InstructionCodeGeneratorMIPS::VisitLocal(HLocal* local) { | 
|  | 4090 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); | 
|  | 4091 | } | 
|  | 4092 |  | 
|  | 4093 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { | 
|  | 4094 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); | 
|  | 4095 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 4096 | } | 
|  | 4097 |  | 
|  | 4098 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { | 
|  | 4099 | // Will be generated at use site. | 
|  | 4100 | } | 
|  | 4101 |  | 
|  | 4102 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { | 
|  | 4103 | LocationSummary* locations = | 
|  | 4104 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
|  | 4105 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 4106 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 4107 | } | 
|  | 4108 |  | 
|  | 4109 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { | 
|  | 4110 | if (instruction->IsEnter()) { | 
|  | 4111 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLockObject), | 
|  | 4112 | instruction, | 
|  | 4113 | instruction->GetDexPc(), | 
|  | 4114 | nullptr, | 
|  | 4115 | IsDirectEntrypoint(kQuickLockObject)); | 
|  | 4116 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); | 
|  | 4117 | } else { | 
|  | 4118 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pUnlockObject), | 
|  | 4119 | instruction, | 
|  | 4120 | instruction->GetDexPc(), | 
|  | 4121 | nullptr, | 
|  | 4122 | IsDirectEntrypoint(kQuickUnlockObject)); | 
|  | 4123 | } | 
|  | 4124 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); | 
|  | 4125 | } | 
|  | 4126 |  | 
|  | 4127 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { | 
|  | 4128 | LocationSummary* locations = | 
|  | 4129 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); | 
|  | 4130 | switch (mul->GetResultType()) { | 
|  | 4131 | case Primitive::kPrimInt: | 
|  | 4132 | case Primitive::kPrimLong: | 
|  | 4133 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4134 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 4135 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 4136 | break; | 
|  | 4137 |  | 
|  | 4138 | case Primitive::kPrimFloat: | 
|  | 4139 | case Primitive::kPrimDouble: | 
|  | 4140 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 4141 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 4142 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 4143 | break; | 
|  | 4144 |  | 
|  | 4145 | default: | 
|  | 4146 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); | 
|  | 4147 | } | 
|  | 4148 | } | 
|  | 4149 |  | 
|  | 4150 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { | 
|  | 4151 | Primitive::Type type = instruction->GetType(); | 
|  | 4152 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 4153 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); | 
|  | 4154 |  | 
|  | 4155 | switch (type) { | 
|  | 4156 | case Primitive::kPrimInt: { | 
|  | 4157 | Register dst = locations->Out().AsRegister<Register>(); | 
|  | 4158 | Register lhs = locations->InAt(0).AsRegister<Register>(); | 
|  | 4159 | Register rhs = locations->InAt(1).AsRegister<Register>(); | 
|  | 4160 |  | 
|  | 4161 | if (isR6) { | 
|  | 4162 | __ MulR6(dst, lhs, rhs); | 
|  | 4163 | } else { | 
|  | 4164 | __ MulR2(dst, lhs, rhs); | 
|  | 4165 | } | 
|  | 4166 | break; | 
|  | 4167 | } | 
|  | 4168 | case Primitive::kPrimLong: { | 
|  | 4169 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); | 
|  | 4170 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); | 
|  | 4171 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); | 
|  | 4172 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); | 
|  | 4173 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); | 
|  | 4174 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); | 
|  | 4175 |  | 
|  | 4176 | // Extra checks to protect caused by the existance of A1_A2. | 
|  | 4177 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: | 
|  | 4178 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). | 
|  | 4179 | DCHECK_NE(dst_high, lhs_low); | 
|  | 4180 | DCHECK_NE(dst_high, rhs_low); | 
|  | 4181 |  | 
|  | 4182 | // A_B * C_D | 
|  | 4183 | // dst_hi:  [ low(A*D) + low(B*C) + hi(B*D) ] | 
|  | 4184 | // dst_lo:  [ low(B*D) ] | 
|  | 4185 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. | 
|  | 4186 |  | 
|  | 4187 | if (isR6) { | 
|  | 4188 | __ MulR6(TMP, lhs_high, rhs_low); | 
|  | 4189 | __ MulR6(dst_high, lhs_low, rhs_high); | 
|  | 4190 | __ Addu(dst_high, dst_high, TMP); | 
|  | 4191 | __ MuhuR6(TMP, lhs_low, rhs_low); | 
|  | 4192 | __ Addu(dst_high, dst_high, TMP); | 
|  | 4193 | __ MulR6(dst_low, lhs_low, rhs_low); | 
|  | 4194 | } else { | 
|  | 4195 | __ MulR2(TMP, lhs_high, rhs_low); | 
|  | 4196 | __ MulR2(dst_high, lhs_low, rhs_high); | 
|  | 4197 | __ Addu(dst_high, dst_high, TMP); | 
|  | 4198 | __ MultuR2(lhs_low, rhs_low); | 
|  | 4199 | __ Mfhi(TMP); | 
|  | 4200 | __ Addu(dst_high, dst_high, TMP); | 
|  | 4201 | __ Mflo(dst_low); | 
|  | 4202 | } | 
|  | 4203 | break; | 
|  | 4204 | } | 
|  | 4205 | case Primitive::kPrimFloat: | 
|  | 4206 | case Primitive::kPrimDouble: { | 
|  | 4207 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 4208 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 4209 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); | 
|  | 4210 | if (type == Primitive::kPrimFloat) { | 
|  | 4211 | __ MulS(dst, lhs, rhs); | 
|  | 4212 | } else { | 
|  | 4213 | __ MulD(dst, lhs, rhs); | 
|  | 4214 | } | 
|  | 4215 | break; | 
|  | 4216 | } | 
|  | 4217 | default: | 
|  | 4218 | LOG(FATAL) << "Unexpected mul type " << type; | 
|  | 4219 | } | 
|  | 4220 | } | 
|  | 4221 |  | 
|  | 4222 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { | 
|  | 4223 | LocationSummary* locations = | 
|  | 4224 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); | 
|  | 4225 | switch (neg->GetResultType()) { | 
|  | 4226 | case Primitive::kPrimInt: | 
|  | 4227 | case Primitive::kPrimLong: | 
|  | 4228 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4229 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 4230 | break; | 
|  | 4231 |  | 
|  | 4232 | case Primitive::kPrimFloat: | 
|  | 4233 | case Primitive::kPrimDouble: | 
|  | 4234 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 4235 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 4236 | break; | 
|  | 4237 |  | 
|  | 4238 | default: | 
|  | 4239 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); | 
|  | 4240 | } | 
|  | 4241 | } | 
|  | 4242 |  | 
|  | 4243 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { | 
|  | 4244 | Primitive::Type type = instruction->GetType(); | 
|  | 4245 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 4246 |  | 
|  | 4247 | switch (type) { | 
|  | 4248 | case Primitive::kPrimInt: { | 
|  | 4249 | Register dst = locations->Out().AsRegister<Register>(); | 
|  | 4250 | Register src = locations->InAt(0).AsRegister<Register>(); | 
|  | 4251 | __ Subu(dst, ZERO, src); | 
|  | 4252 | break; | 
|  | 4253 | } | 
|  | 4254 | case Primitive::kPrimLong: { | 
|  | 4255 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); | 
|  | 4256 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); | 
|  | 4257 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); | 
|  | 4258 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); | 
|  | 4259 | __ Subu(dst_low, ZERO, src_low); | 
|  | 4260 | __ Sltu(TMP, ZERO, dst_low); | 
|  | 4261 | __ Subu(dst_high, ZERO, src_high); | 
|  | 4262 | __ Subu(dst_high, dst_high, TMP); | 
|  | 4263 | break; | 
|  | 4264 | } | 
|  | 4265 | case Primitive::kPrimFloat: | 
|  | 4266 | case Primitive::kPrimDouble: { | 
|  | 4267 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 4268 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 4269 | if (type == Primitive::kPrimFloat) { | 
|  | 4270 | __ NegS(dst, src); | 
|  | 4271 | } else { | 
|  | 4272 | __ NegD(dst, src); | 
|  | 4273 | } | 
|  | 4274 | break; | 
|  | 4275 | } | 
|  | 4276 | default: | 
|  | 4277 | LOG(FATAL) << "Unexpected neg type " << type; | 
|  | 4278 | } | 
|  | 4279 | } | 
|  | 4280 |  | 
|  | 4281 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { | 
|  | 4282 | LocationSummary* locations = | 
|  | 4283 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
|  | 4284 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 4285 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 4286 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); | 
|  | 4287 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); | 
|  | 4288 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
|  | 4289 | } | 
|  | 4290 |  | 
|  | 4291 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { | 
|  | 4292 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 4293 | Register current_method_register = calling_convention.GetRegisterAt(2); | 
|  | 4294 | __ Lw(current_method_register, SP, kCurrentMethodStackOffset); | 
|  | 4295 | // Move an uint16_t value to a register. | 
|  | 4296 | __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); | 
|  | 4297 | codegen_->InvokeRuntime( | 
|  | 4298 | GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(), | 
|  | 4299 | instruction, | 
|  | 4300 | instruction->GetDexPc(), | 
|  | 4301 | nullptr, | 
|  | 4302 | IsDirectEntrypoint(kQuickAllocArrayWithAccessCheck)); | 
|  | 4303 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, | 
|  | 4304 | void*, uint32_t, int32_t, ArtMethod*>(); | 
|  | 4305 | } | 
|  | 4306 |  | 
|  | 4307 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { | 
|  | 4308 | LocationSummary* locations = | 
|  | 4309 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
|  | 4310 | InvokeRuntimeCallingConvention calling_convention; | 
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4311 | if (instruction->IsStringAlloc()) { | 
|  | 4312 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); | 
|  | 4313 | } else { | 
|  | 4314 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 4315 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
|  | 4316 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4317 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); | 
|  | 4318 | } | 
|  | 4319 |  | 
|  | 4320 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { | 
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4321 | if (instruction->IsStringAlloc()) { | 
|  | 4322 | // String is allocated through StringFactory. Call NewEmptyString entry point. | 
|  | 4323 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); | 
|  | 4324 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize); | 
|  | 4325 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); | 
|  | 4326 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); | 
|  | 4327 | __ Jalr(T9); | 
|  | 4328 | __ Nop(); | 
|  | 4329 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); | 
|  | 4330 | } else { | 
|  | 4331 | codegen_->InvokeRuntime( | 
|  | 4332 | GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(), | 
|  | 4333 | instruction, | 
|  | 4334 | instruction->GetDexPc(), | 
|  | 4335 | nullptr, | 
|  | 4336 | IsDirectEntrypoint(kQuickAllocObjectWithAccessCheck)); | 
|  | 4337 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); | 
|  | 4338 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4339 | } | 
|  | 4340 |  | 
|  | 4341 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { | 
|  | 4342 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 4343 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4344 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 4345 | } | 
|  | 4346 |  | 
|  | 4347 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { | 
|  | 4348 | Primitive::Type type = instruction->GetType(); | 
|  | 4349 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 4350 |  | 
|  | 4351 | switch (type) { | 
|  | 4352 | case Primitive::kPrimInt: { | 
|  | 4353 | Register dst = locations->Out().AsRegister<Register>(); | 
|  | 4354 | Register src = locations->InAt(0).AsRegister<Register>(); | 
|  | 4355 | __ Nor(dst, src, ZERO); | 
|  | 4356 | break; | 
|  | 4357 | } | 
|  | 4358 |  | 
|  | 4359 | case Primitive::kPrimLong: { | 
|  | 4360 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); | 
|  | 4361 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); | 
|  | 4362 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); | 
|  | 4363 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); | 
|  | 4364 | __ Nor(dst_high, src_high, ZERO); | 
|  | 4365 | __ Nor(dst_low, src_low, ZERO); | 
|  | 4366 | break; | 
|  | 4367 | } | 
|  | 4368 |  | 
|  | 4369 | default: | 
|  | 4370 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); | 
|  | 4371 | } | 
|  | 4372 | } | 
|  | 4373 |  | 
|  | 4374 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { | 
|  | 4375 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 4376 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 4378 | } | 
|  | 4379 |  | 
|  | 4380 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { | 
|  | 4381 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 4382 | __ Xori(locations->Out().AsRegister<Register>(), | 
|  | 4383 | locations->InAt(0).AsRegister<Register>(), | 
|  | 4384 | 1); | 
|  | 4385 | } | 
|  | 4386 |  | 
|  | 4387 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { | 
|  | 4388 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
|  | 4389 | ? LocationSummary::kCallOnSlowPath | 
|  | 4390 | : LocationSummary::kNoCall; | 
|  | 4391 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
|  | 4392 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4393 | if (instruction->HasUses()) { | 
|  | 4394 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 4395 | } | 
|  | 4396 | } | 
|  | 4397 |  | 
|  | 4398 | void InstructionCodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { | 
|  | 4399 | if (codegen_->CanMoveNullCheckToUser(instruction)) { | 
|  | 4400 | return; | 
|  | 4401 | } | 
|  | 4402 | Location obj = instruction->GetLocations()->InAt(0); | 
|  | 4403 |  | 
|  | 4404 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); | 
|  | 4405 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); | 
|  | 4406 | } | 
|  | 4407 |  | 
|  | 4408 | void InstructionCodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { | 
|  | 4409 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction); | 
|  | 4410 | codegen_->AddSlowPath(slow_path); | 
|  | 4411 |  | 
|  | 4412 | Location obj = instruction->GetLocations()->InAt(0); | 
|  | 4413 |  | 
|  | 4414 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); | 
|  | 4415 | } | 
|  | 4416 |  | 
|  | 4417 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { | 
|  | 4418 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { | 
|  | 4419 | GenerateImplicitNullCheck(instruction); | 
|  | 4420 | } else { | 
|  | 4421 | GenerateExplicitNullCheck(instruction); | 
|  | 4422 | } | 
|  | 4423 | } | 
|  | 4424 |  | 
|  | 4425 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { | 
|  | 4426 | HandleBinaryOp(instruction); | 
|  | 4427 | } | 
|  | 4428 |  | 
|  | 4429 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { | 
|  | 4430 | HandleBinaryOp(instruction); | 
|  | 4431 | } | 
|  | 4432 |  | 
|  | 4433 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { | 
|  | 4434 | LOG(FATAL) << "Unreachable"; | 
|  | 4435 | } | 
|  | 4436 |  | 
|  | 4437 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { | 
|  | 4438 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); | 
|  | 4439 | } | 
|  | 4440 |  | 
|  | 4441 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { | 
|  | 4442 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 4443 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); | 
|  | 4444 | if (location.IsStackSlot()) { | 
|  | 4445 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
|  | 4446 | } else if (location.IsDoubleStackSlot()) { | 
|  | 4447 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
|  | 4448 | } | 
|  | 4449 | locations->SetOut(location); | 
|  | 4450 | } | 
|  | 4451 |  | 
|  | 4452 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction | 
|  | 4453 | ATTRIBUTE_UNUSED) { | 
|  | 4454 | // Nothing to do, the parameter is already at its location. | 
|  | 4455 | } | 
|  | 4456 |  | 
|  | 4457 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { | 
|  | 4458 | LocationSummary* locations = | 
|  | 4459 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 4460 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); | 
|  | 4461 | } | 
|  | 4462 |  | 
|  | 4463 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction | 
|  | 4464 | ATTRIBUTE_UNUSED) { | 
|  | 4465 | // Nothing to do, the method is already at its location. | 
|  | 4466 | } | 
|  | 4467 |  | 
|  | 4468 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { | 
|  | 4469 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 4470 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { | 
|  | 4471 | locations->SetInAt(i, Location::Any()); | 
|  | 4472 | } | 
|  | 4473 | locations->SetOut(Location::Any()); | 
|  | 4474 | } | 
|  | 4475 |  | 
|  | 4476 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { | 
|  | 4477 | LOG(FATAL) << "Unreachable"; | 
|  | 4478 | } | 
|  | 4479 |  | 
|  | 4480 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { | 
|  | 4481 | Primitive::Type type = rem->GetResultType(); | 
|  | 4482 | LocationSummary::CallKind call_kind = | 
|  | 4483 | (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCall; | 
|  | 4484 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); | 
|  | 4485 |  | 
|  | 4486 | switch (type) { | 
|  | 4487 | case Primitive::kPrimInt: | 
|  | 4488 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4489 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4490 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 4491 | break; | 
|  | 4492 |  | 
|  | 4493 | case Primitive::kPrimLong: { | 
|  | 4494 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 4495 | locations->SetInAt(0, Location::RegisterPairLocation( | 
|  | 4496 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); | 
|  | 4497 | locations->SetInAt(1, Location::RegisterPairLocation( | 
|  | 4498 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); | 
|  | 4499 | locations->SetOut(calling_convention.GetReturnLocation(type)); | 
|  | 4500 | break; | 
|  | 4501 | } | 
|  | 4502 |  | 
|  | 4503 | case Primitive::kPrimFloat: | 
|  | 4504 | case Primitive::kPrimDouble: { | 
|  | 4505 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 4506 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); | 
|  | 4507 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); | 
|  | 4508 | locations->SetOut(calling_convention.GetReturnLocation(type)); | 
|  | 4509 | break; | 
|  | 4510 | } | 
|  | 4511 |  | 
|  | 4512 | default: | 
|  | 4513 | LOG(FATAL) << "Unexpected rem type " << type; | 
|  | 4514 | } | 
|  | 4515 | } | 
|  | 4516 |  | 
|  | 4517 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { | 
|  | 4518 | Primitive::Type type = instruction->GetType(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4519 |  | 
|  | 4520 | switch (type) { | 
| Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4521 | case Primitive::kPrimInt: | 
|  | 4522 | GenerateDivRemIntegral(instruction); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4523 | break; | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4524 | case Primitive::kPrimLong: { | 
|  | 4525 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), | 
|  | 4526 | instruction, | 
|  | 4527 | instruction->GetDexPc(), | 
|  | 4528 | nullptr, | 
|  | 4529 | IsDirectEntrypoint(kQuickLmod)); | 
|  | 4530 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); | 
|  | 4531 | break; | 
|  | 4532 | } | 
|  | 4533 | case Primitive::kPrimFloat: { | 
|  | 4534 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), | 
|  | 4535 | instruction, instruction->GetDexPc(), | 
|  | 4536 | nullptr, | 
|  | 4537 | IsDirectEntrypoint(kQuickFmodf)); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4538 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4539 | break; | 
|  | 4540 | } | 
|  | 4541 | case Primitive::kPrimDouble: { | 
|  | 4542 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), | 
|  | 4543 | instruction, instruction->GetDexPc(), | 
|  | 4544 | nullptr, | 
|  | 4545 | IsDirectEntrypoint(kQuickFmod)); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4546 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4547 | break; | 
|  | 4548 | } | 
|  | 4549 | default: | 
|  | 4550 | LOG(FATAL) << "Unexpected rem type " << type; | 
|  | 4551 | } | 
|  | 4552 | } | 
|  | 4553 |  | 
|  | 4554 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
|  | 4555 | memory_barrier->SetLocations(nullptr); | 
|  | 4556 | } | 
|  | 4557 |  | 
|  | 4558 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
|  | 4559 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); | 
|  | 4560 | } | 
|  | 4561 |  | 
|  | 4562 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { | 
|  | 4563 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); | 
|  | 4564 | Primitive::Type return_type = ret->InputAt(0)->GetType(); | 
|  | 4565 | locations->SetInAt(0, MipsReturnLocation(return_type)); | 
|  | 4566 | } | 
|  | 4567 |  | 
|  | 4568 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { | 
|  | 4569 | codegen_->GenerateFrameExit(); | 
|  | 4570 | } | 
|  | 4571 |  | 
|  | 4572 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { | 
|  | 4573 | ret->SetLocations(nullptr); | 
|  | 4574 | } | 
|  | 4575 |  | 
|  | 4576 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { | 
|  | 4577 | codegen_->GenerateFrameExit(); | 
|  | 4578 | } | 
|  | 4579 |  | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 4580 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { | 
|  | 4581 | HandleShift(ror); | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4582 | } | 
|  | 4583 |  | 
| Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 4584 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { | 
|  | 4585 | HandleShift(ror); | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4586 | } | 
|  | 4587 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4588 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { | 
|  | 4589 | HandleShift(shl); | 
|  | 4590 | } | 
|  | 4591 |  | 
|  | 4592 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { | 
|  | 4593 | HandleShift(shl); | 
|  | 4594 | } | 
|  | 4595 |  | 
|  | 4596 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { | 
|  | 4597 | HandleShift(shr); | 
|  | 4598 | } | 
|  | 4599 |  | 
|  | 4600 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { | 
|  | 4601 | HandleShift(shr); | 
|  | 4602 | } | 
|  | 4603 |  | 
|  | 4604 | void LocationsBuilderMIPS::VisitStoreLocal(HStoreLocal* store) { | 
|  | 4605 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); | 
|  | 4606 | Primitive::Type field_type = store->InputAt(1)->GetType(); | 
|  | 4607 | switch (field_type) { | 
|  | 4608 | case Primitive::kPrimNot: | 
|  | 4609 | case Primitive::kPrimBoolean: | 
|  | 4610 | case Primitive::kPrimByte: | 
|  | 4611 | case Primitive::kPrimChar: | 
|  | 4612 | case Primitive::kPrimShort: | 
|  | 4613 | case Primitive::kPrimInt: | 
|  | 4614 | case Primitive::kPrimFloat: | 
|  | 4615 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); | 
|  | 4616 | break; | 
|  | 4617 |  | 
|  | 4618 | case Primitive::kPrimLong: | 
|  | 4619 | case Primitive::kPrimDouble: | 
|  | 4620 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); | 
|  | 4621 | break; | 
|  | 4622 |  | 
|  | 4623 | default: | 
|  | 4624 | LOG(FATAL) << "Unimplemented local type " << field_type; | 
|  | 4625 | } | 
|  | 4626 | } | 
|  | 4627 |  | 
|  | 4628 | void InstructionCodeGeneratorMIPS::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { | 
|  | 4629 | } | 
|  | 4630 |  | 
|  | 4631 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { | 
|  | 4632 | HandleBinaryOp(instruction); | 
|  | 4633 | } | 
|  | 4634 |  | 
|  | 4635 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { | 
|  | 4636 | HandleBinaryOp(instruction); | 
|  | 4637 | } | 
|  | 4638 |  | 
|  | 4639 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
|  | 4640 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
|  | 4641 | } | 
|  | 4642 |  | 
|  | 4643 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
|  | 4644 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); | 
|  | 4645 | } | 
|  | 4646 |  | 
|  | 4647 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
|  | 4648 | HandleFieldSet(instruction, instruction->GetFieldInfo()); | 
|  | 4649 | } | 
|  | 4650 |  | 
|  | 4651 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
|  | 4652 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); | 
|  | 4653 | } | 
|  | 4654 |  | 
|  | 4655 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( | 
|  | 4656 | HUnresolvedInstanceFieldGet* instruction) { | 
|  | 4657 | FieldAccessCallingConventionMIPS calling_convention; | 
|  | 4658 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, | 
|  | 4659 | instruction->GetFieldType(), | 
|  | 4660 | calling_convention); | 
|  | 4661 | } | 
|  | 4662 |  | 
|  | 4663 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( | 
|  | 4664 | HUnresolvedInstanceFieldGet* instruction) { | 
|  | 4665 | FieldAccessCallingConventionMIPS calling_convention; | 
|  | 4666 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 4667 | instruction->GetFieldType(), | 
|  | 4668 | instruction->GetFieldIndex(), | 
|  | 4669 | instruction->GetDexPc(), | 
|  | 4670 | calling_convention); | 
|  | 4671 | } | 
|  | 4672 |  | 
|  | 4673 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( | 
|  | 4674 | HUnresolvedInstanceFieldSet* instruction) { | 
|  | 4675 | FieldAccessCallingConventionMIPS calling_convention; | 
|  | 4676 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, | 
|  | 4677 | instruction->GetFieldType(), | 
|  | 4678 | calling_convention); | 
|  | 4679 | } | 
|  | 4680 |  | 
|  | 4681 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( | 
|  | 4682 | HUnresolvedInstanceFieldSet* instruction) { | 
|  | 4683 | FieldAccessCallingConventionMIPS calling_convention; | 
|  | 4684 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 4685 | instruction->GetFieldType(), | 
|  | 4686 | instruction->GetFieldIndex(), | 
|  | 4687 | instruction->GetDexPc(), | 
|  | 4688 | calling_convention); | 
|  | 4689 | } | 
|  | 4690 |  | 
|  | 4691 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( | 
|  | 4692 | HUnresolvedStaticFieldGet* instruction) { | 
|  | 4693 | FieldAccessCallingConventionMIPS calling_convention; | 
|  | 4694 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, | 
|  | 4695 | instruction->GetFieldType(), | 
|  | 4696 | calling_convention); | 
|  | 4697 | } | 
|  | 4698 |  | 
|  | 4699 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( | 
|  | 4700 | HUnresolvedStaticFieldGet* instruction) { | 
|  | 4701 | FieldAccessCallingConventionMIPS calling_convention; | 
|  | 4702 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 4703 | instruction->GetFieldType(), | 
|  | 4704 | instruction->GetFieldIndex(), | 
|  | 4705 | instruction->GetDexPc(), | 
|  | 4706 | calling_convention); | 
|  | 4707 | } | 
|  | 4708 |  | 
|  | 4709 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( | 
|  | 4710 | HUnresolvedStaticFieldSet* instruction) { | 
|  | 4711 | FieldAccessCallingConventionMIPS calling_convention; | 
|  | 4712 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, | 
|  | 4713 | instruction->GetFieldType(), | 
|  | 4714 | calling_convention); | 
|  | 4715 | } | 
|  | 4716 |  | 
|  | 4717 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( | 
|  | 4718 | HUnresolvedStaticFieldSet* instruction) { | 
|  | 4719 | FieldAccessCallingConventionMIPS calling_convention; | 
|  | 4720 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 4721 | instruction->GetFieldType(), | 
|  | 4722 | instruction->GetFieldIndex(), | 
|  | 4723 | instruction->GetDexPc(), | 
|  | 4724 | calling_convention); | 
|  | 4725 | } | 
|  | 4726 |  | 
|  | 4727 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { | 
|  | 4728 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); | 
|  | 4729 | } | 
|  | 4730 |  | 
|  | 4731 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { | 
|  | 4732 | HBasicBlock* block = instruction->GetBlock(); | 
|  | 4733 | if (block->GetLoopInformation() != nullptr) { | 
|  | 4734 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); | 
|  | 4735 | // The back edge will generate the suspend check. | 
|  | 4736 | return; | 
|  | 4737 | } | 
|  | 4738 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { | 
|  | 4739 | // The goto will generate the suspend check. | 
|  | 4740 | return; | 
|  | 4741 | } | 
|  | 4742 | GenerateSuspendCheck(instruction, nullptr); | 
|  | 4743 | } | 
|  | 4744 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4745 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { | 
|  | 4746 | LocationSummary* locations = | 
|  | 4747 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
|  | 4748 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 4749 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 4750 | } | 
|  | 4751 |  | 
|  | 4752 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { | 
|  | 4753 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), | 
|  | 4754 | instruction, | 
|  | 4755 | instruction->GetDexPc(), | 
|  | 4756 | nullptr, | 
|  | 4757 | IsDirectEntrypoint(kQuickDeliverException)); | 
|  | 4758 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); | 
|  | 4759 | } | 
|  | 4760 |  | 
|  | 4761 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { | 
|  | 4762 | Primitive::Type input_type = conversion->GetInputType(); | 
|  | 4763 | Primitive::Type result_type = conversion->GetResultType(); | 
|  | 4764 | DCHECK_NE(input_type, result_type); | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 4765 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4766 |  | 
|  | 4767 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || | 
|  | 4768 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { | 
|  | 4769 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; | 
|  | 4770 | } | 
|  | 4771 |  | 
|  | 4772 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 4773 | if (!isR6 && | 
|  | 4774 | ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) || | 
|  | 4775 | (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4776 | call_kind = LocationSummary::kCall; | 
|  | 4777 | } | 
|  | 4778 |  | 
|  | 4779 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); | 
|  | 4780 |  | 
|  | 4781 | if (call_kind == LocationSummary::kNoCall) { | 
|  | 4782 | if (Primitive::IsFloatingPointType(input_type)) { | 
|  | 4783 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 4784 | } else { | 
|  | 4785 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4786 | } | 
|  | 4787 |  | 
|  | 4788 | if (Primitive::IsFloatingPointType(result_type)) { | 
|  | 4789 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 4790 | } else { | 
|  | 4791 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 4792 | } | 
|  | 4793 | } else { | 
|  | 4794 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 4795 |  | 
|  | 4796 | if (Primitive::IsFloatingPointType(input_type)) { | 
|  | 4797 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); | 
|  | 4798 | } else { | 
|  | 4799 | DCHECK_EQ(input_type, Primitive::kPrimLong); | 
|  | 4800 | locations->SetInAt(0, Location::RegisterPairLocation( | 
|  | 4801 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); | 
|  | 4802 | } | 
|  | 4803 |  | 
|  | 4804 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); | 
|  | 4805 | } | 
|  | 4806 | } | 
|  | 4807 |  | 
|  | 4808 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { | 
|  | 4809 | LocationSummary* locations = conversion->GetLocations(); | 
|  | 4810 | Primitive::Type result_type = conversion->GetResultType(); | 
|  | 4811 | Primitive::Type input_type = conversion->GetInputType(); | 
|  | 4812 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 4813 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); | 
|  | 4814 | bool fpu_32bit = codegen_->GetInstructionSetFeatures().Is32BitFloatingPoint(); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4815 |  | 
|  | 4816 | DCHECK_NE(input_type, result_type); | 
|  | 4817 |  | 
|  | 4818 | if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) { | 
|  | 4819 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); | 
|  | 4820 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); | 
|  | 4821 | Register src = locations->InAt(0).AsRegister<Register>(); | 
|  | 4822 |  | 
|  | 4823 | __ Move(dst_low, src); | 
|  | 4824 | __ Sra(dst_high, src, 31); | 
|  | 4825 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { | 
|  | 4826 | Register dst = locations->Out().AsRegister<Register>(); | 
|  | 4827 | Register src = (input_type == Primitive::kPrimLong) | 
|  | 4828 | ? locations->InAt(0).AsRegisterPairLow<Register>() | 
|  | 4829 | : locations->InAt(0).AsRegister<Register>(); | 
|  | 4830 |  | 
|  | 4831 | switch (result_type) { | 
|  | 4832 | case Primitive::kPrimChar: | 
|  | 4833 | __ Andi(dst, src, 0xFFFF); | 
|  | 4834 | break; | 
|  | 4835 | case Primitive::kPrimByte: | 
|  | 4836 | if (has_sign_extension) { | 
|  | 4837 | __ Seb(dst, src); | 
|  | 4838 | } else { | 
|  | 4839 | __ Sll(dst, src, 24); | 
|  | 4840 | __ Sra(dst, dst, 24); | 
|  | 4841 | } | 
|  | 4842 | break; | 
|  | 4843 | case Primitive::kPrimShort: | 
|  | 4844 | if (has_sign_extension) { | 
|  | 4845 | __ Seh(dst, src); | 
|  | 4846 | } else { | 
|  | 4847 | __ Sll(dst, src, 16); | 
|  | 4848 | __ Sra(dst, dst, 16); | 
|  | 4849 | } | 
|  | 4850 | break; | 
|  | 4851 | case Primitive::kPrimInt: | 
|  | 4852 | __ Move(dst, src); | 
|  | 4853 | break; | 
|  | 4854 |  | 
|  | 4855 | default: | 
|  | 4856 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 4857 | << " to " << result_type; | 
|  | 4858 | } | 
|  | 4859 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 4860 | if (input_type == Primitive::kPrimLong) { | 
|  | 4861 | if (isR6) { | 
|  | 4862 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary | 
|  | 4863 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. | 
|  | 4864 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); | 
|  | 4865 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); | 
|  | 4866 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 4867 | __ Mtc1(src_low, FTMP); | 
|  | 4868 | __ Mthc1(src_high, FTMP); | 
|  | 4869 | if (result_type == Primitive::kPrimFloat) { | 
|  | 4870 | __ Cvtsl(dst, FTMP); | 
|  | 4871 | } else { | 
|  | 4872 | __ Cvtdl(dst, FTMP); | 
|  | 4873 | } | 
|  | 4874 | } else { | 
|  | 4875 | int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f) | 
|  | 4876 | : QUICK_ENTRY_POINT(pL2d); | 
|  | 4877 | bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickL2f) | 
|  | 4878 | : IsDirectEntrypoint(kQuickL2d); | 
|  | 4879 | codegen_->InvokeRuntime(entry_offset, | 
|  | 4880 | conversion, | 
|  | 4881 | conversion->GetDexPc(), | 
|  | 4882 | nullptr, | 
|  | 4883 | direct); | 
|  | 4884 | if (result_type == Primitive::kPrimFloat) { | 
|  | 4885 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); | 
|  | 4886 | } else { | 
|  | 4887 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); | 
|  | 4888 | } | 
|  | 4889 | } | 
|  | 4890 | } else { | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4891 | Register src = locations->InAt(0).AsRegister<Register>(); | 
|  | 4892 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 4893 | __ Mtc1(src, FTMP); | 
|  | 4894 | if (result_type == Primitive::kPrimFloat) { | 
|  | 4895 | __ Cvtsw(dst, FTMP); | 
|  | 4896 | } else { | 
|  | 4897 | __ Cvtdw(dst, FTMP); | 
|  | 4898 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4899 | } | 
|  | 4900 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { | 
|  | 4901 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 4902 | if (result_type == Primitive::kPrimLong) { | 
|  | 4903 | if (isR6) { | 
|  | 4904 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary | 
|  | 4905 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. | 
|  | 4906 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 4907 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); | 
|  | 4908 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); | 
|  | 4909 | MipsLabel truncate; | 
|  | 4910 | MipsLabel done; | 
|  | 4911 |  | 
|  | 4912 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive | 
|  | 4913 | // value when the input is either a NaN or is outside of the range of the output type | 
|  | 4914 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce | 
|  | 4915 | // the same result. | 
|  | 4916 | // | 
|  | 4917 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum | 
|  | 4918 | // value of the output type if the input is outside of the range after the truncation or | 
|  | 4919 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct | 
|  | 4920 | // results. This matches the desired float/double-to-int/long conversion exactly. | 
|  | 4921 | // | 
|  | 4922 | // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction. | 
|  | 4923 | // | 
|  | 4924 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate | 
|  | 4925 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, | 
|  | 4926 | // even though it must be NAN2008=1 on R6. | 
|  | 4927 | // | 
|  | 4928 | // The code takes care of the different behaviors by first comparing the input to the | 
|  | 4929 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). | 
|  | 4930 | // If the input is greater than or equal to the minimum, it procedes to the truncate | 
|  | 4931 | // instruction, which will handle such an input the same way irrespective of NAN2008. | 
|  | 4932 | // Otherwise the input is compared to itself to determine whether it is a NaN or not | 
|  | 4933 | // in order to return either zero or the minimum value. | 
|  | 4934 | // | 
|  | 4935 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the | 
|  | 4936 | // truncate instruction for MIPS64R6. | 
|  | 4937 | if (input_type == Primitive::kPrimFloat) { | 
|  | 4938 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min()); | 
|  | 4939 | __ LoadConst32(TMP, min_val); | 
|  | 4940 | __ Mtc1(TMP, FTMP); | 
|  | 4941 | __ CmpLeS(FTMP, FTMP, src); | 
|  | 4942 | } else { | 
|  | 4943 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min()); | 
|  | 4944 | __ LoadConst32(TMP, High32Bits(min_val)); | 
|  | 4945 | __ Mtc1(ZERO, FTMP); | 
|  | 4946 | __ Mthc1(TMP, FTMP); | 
|  | 4947 | __ CmpLeD(FTMP, FTMP, src); | 
|  | 4948 | } | 
|  | 4949 |  | 
|  | 4950 | __ Bc1nez(FTMP, &truncate); | 
|  | 4951 |  | 
|  | 4952 | if (input_type == Primitive::kPrimFloat) { | 
|  | 4953 | __ CmpEqS(FTMP, src, src); | 
|  | 4954 | } else { | 
|  | 4955 | __ CmpEqD(FTMP, src, src); | 
|  | 4956 | } | 
|  | 4957 | __ Move(dst_low, ZERO); | 
|  | 4958 | __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min()); | 
|  | 4959 | __ Mfc1(TMP, FTMP); | 
|  | 4960 | __ And(dst_high, dst_high, TMP); | 
|  | 4961 |  | 
|  | 4962 | __ B(&done); | 
|  | 4963 |  | 
|  | 4964 | __ Bind(&truncate); | 
|  | 4965 |  | 
|  | 4966 | if (input_type == Primitive::kPrimFloat) { | 
|  | 4967 | __ TruncLS(FTMP, src); | 
|  | 4968 | } else { | 
|  | 4969 | __ TruncLD(FTMP, src); | 
|  | 4970 | } | 
|  | 4971 | __ Mfc1(dst_low, FTMP); | 
|  | 4972 | __ Mfhc1(dst_high, FTMP); | 
|  | 4973 |  | 
|  | 4974 | __ Bind(&done); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4975 | } else { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 4976 | int32_t entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l) | 
|  | 4977 | : QUICK_ENTRY_POINT(pD2l); | 
|  | 4978 | bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickF2l) | 
|  | 4979 | : IsDirectEntrypoint(kQuickD2l); | 
|  | 4980 | codegen_->InvokeRuntime(entry_offset, conversion, conversion->GetDexPc(), nullptr, direct); | 
|  | 4981 | if (input_type == Primitive::kPrimFloat) { | 
|  | 4982 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); | 
|  | 4983 | } else { | 
|  | 4984 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); | 
|  | 4985 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4986 | } | 
|  | 4987 | } else { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 4988 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 4989 | Register dst = locations->Out().AsRegister<Register>(); | 
|  | 4990 | MipsLabel truncate; | 
|  | 4991 | MipsLabel done; | 
|  | 4992 |  | 
|  | 4993 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate | 
|  | 4994 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, | 
|  | 4995 | // even though it must be NAN2008=1 on R6. | 
|  | 4996 | // | 
|  | 4997 | // For details see the large comment above for the truncation of float/double to long on R6. | 
|  | 4998 | // | 
|  | 4999 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the | 
|  | 5000 | // truncate instruction for MIPS64R6. | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5001 | if (input_type == Primitive::kPrimFloat) { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5002 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); | 
|  | 5003 | __ LoadConst32(TMP, min_val); | 
|  | 5004 | __ Mtc1(TMP, FTMP); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5005 | } else { | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5006 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); | 
|  | 5007 | __ LoadConst32(TMP, High32Bits(min_val)); | 
|  | 5008 | __ Mtc1(ZERO, FTMP); | 
|  | 5009 | if (fpu_32bit) { | 
|  | 5010 | __ Mtc1(TMP, static_cast<FRegister>(FTMP + 1)); | 
|  | 5011 | } else { | 
|  | 5012 | __ Mthc1(TMP, FTMP); | 
|  | 5013 | } | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5014 | } | 
| Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5015 |  | 
|  | 5016 | if (isR6) { | 
|  | 5017 | if (input_type == Primitive::kPrimFloat) { | 
|  | 5018 | __ CmpLeS(FTMP, FTMP, src); | 
|  | 5019 | } else { | 
|  | 5020 | __ CmpLeD(FTMP, FTMP, src); | 
|  | 5021 | } | 
|  | 5022 | __ Bc1nez(FTMP, &truncate); | 
|  | 5023 |  | 
|  | 5024 | if (input_type == Primitive::kPrimFloat) { | 
|  | 5025 | __ CmpEqS(FTMP, src, src); | 
|  | 5026 | } else { | 
|  | 5027 | __ CmpEqD(FTMP, src, src); | 
|  | 5028 | } | 
|  | 5029 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); | 
|  | 5030 | __ Mfc1(TMP, FTMP); | 
|  | 5031 | __ And(dst, dst, TMP); | 
|  | 5032 | } else { | 
|  | 5033 | if (input_type == Primitive::kPrimFloat) { | 
|  | 5034 | __ ColeS(0, FTMP, src); | 
|  | 5035 | } else { | 
|  | 5036 | __ ColeD(0, FTMP, src); | 
|  | 5037 | } | 
|  | 5038 | __ Bc1t(0, &truncate); | 
|  | 5039 |  | 
|  | 5040 | if (input_type == Primitive::kPrimFloat) { | 
|  | 5041 | __ CeqS(0, src, src); | 
|  | 5042 | } else { | 
|  | 5043 | __ CeqD(0, src, src); | 
|  | 5044 | } | 
|  | 5045 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); | 
|  | 5046 | __ Movf(dst, ZERO, 0); | 
|  | 5047 | } | 
|  | 5048 |  | 
|  | 5049 | __ B(&done); | 
|  | 5050 |  | 
|  | 5051 | __ Bind(&truncate); | 
|  | 5052 |  | 
|  | 5053 | if (input_type == Primitive::kPrimFloat) { | 
|  | 5054 | __ TruncWS(FTMP, src); | 
|  | 5055 | } else { | 
|  | 5056 | __ TruncWD(FTMP, src); | 
|  | 5057 | } | 
|  | 5058 | __ Mfc1(dst, FTMP); | 
|  | 5059 |  | 
|  | 5060 | __ Bind(&done); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5061 | } | 
|  | 5062 | } else if (Primitive::IsFloatingPointType(result_type) && | 
|  | 5063 | Primitive::IsFloatingPointType(input_type)) { | 
|  | 5064 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); | 
|  | 5065 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); | 
|  | 5066 | if (result_type == Primitive::kPrimFloat) { | 
|  | 5067 | __ Cvtsd(dst, src); | 
|  | 5068 | } else { | 
|  | 5069 | __ Cvtds(dst, src); | 
|  | 5070 | } | 
|  | 5071 | } else { | 
|  | 5072 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type | 
|  | 5073 | << " to " << result_type; | 
|  | 5074 | } | 
|  | 5075 | } | 
|  | 5076 |  | 
|  | 5077 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { | 
|  | 5078 | HandleShift(ushr); | 
|  | 5079 | } | 
|  | 5080 |  | 
|  | 5081 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { | 
|  | 5082 | HandleShift(ushr); | 
|  | 5083 | } | 
|  | 5084 |  | 
|  | 5085 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { | 
|  | 5086 | HandleBinaryOp(instruction); | 
|  | 5087 | } | 
|  | 5088 |  | 
|  | 5089 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { | 
|  | 5090 | HandleBinaryOp(instruction); | 
|  | 5091 | } | 
|  | 5092 |  | 
|  | 5093 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { | 
|  | 5094 | // Nothing to do, this should be removed during prepare for register allocator. | 
|  | 5095 | LOG(FATAL) << "Unreachable"; | 
|  | 5096 | } | 
|  | 5097 |  | 
|  | 5098 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { | 
|  | 5099 | // Nothing to do, this should be removed during prepare for register allocator. | 
|  | 5100 | LOG(FATAL) << "Unreachable"; | 
|  | 5101 | } | 
|  | 5102 |  | 
|  | 5103 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5104 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5105 | } | 
|  | 5106 |  | 
|  | 5107 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5108 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5109 | } | 
|  | 5110 |  | 
|  | 5111 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5112 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5113 | } | 
|  | 5114 |  | 
|  | 5115 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5116 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5117 | } | 
|  | 5118 |  | 
|  | 5119 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5120 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5121 | } | 
|  | 5122 |  | 
|  | 5123 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5124 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5125 | } | 
|  | 5126 |  | 
|  | 5127 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5128 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5129 | } | 
|  | 5130 |  | 
|  | 5131 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5132 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5133 | } | 
|  | 5134 |  | 
|  | 5135 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5136 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5137 | } | 
|  | 5138 |  | 
|  | 5139 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5140 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5141 | } | 
|  | 5142 |  | 
|  | 5143 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5144 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5145 | } | 
|  | 5146 |  | 
|  | 5147 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5148 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5149 | } | 
|  | 5150 |  | 
|  | 5151 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5152 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5153 | } | 
|  | 5154 |  | 
|  | 5155 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5156 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5157 | } | 
|  | 5158 |  | 
|  | 5159 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5160 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5161 | } | 
|  | 5162 |  | 
|  | 5163 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5164 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5165 | } | 
|  | 5166 |  | 
|  | 5167 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5168 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5169 | } | 
|  | 5170 |  | 
|  | 5171 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5172 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5173 | } | 
|  | 5174 |  | 
|  | 5175 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5176 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5177 | } | 
|  | 5178 |  | 
|  | 5179 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5180 | HandleCondition(comp); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5181 | } | 
|  | 5182 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5183 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
|  | 5184 | LocationSummary* locations = | 
|  | 5185 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); | 
|  | 5186 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 5187 | } | 
|  | 5188 |  | 
|  | 5189 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
|  | 5190 | int32_t lower_bound = switch_instr->GetStartValue(); | 
|  | 5191 | int32_t num_entries = switch_instr->GetNumEntries(); | 
|  | 5192 | LocationSummary* locations = switch_instr->GetLocations(); | 
|  | 5193 | Register value_reg = locations->InAt(0).AsRegister<Register>(); | 
|  | 5194 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); | 
|  | 5195 |  | 
|  | 5196 | // Create a set of compare/jumps. | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5197 | Register temp_reg = TMP; | 
|  | 5198 | __ Addiu32(temp_reg, value_reg, -lower_bound); | 
|  | 5199 | // Jump to default if index is negative | 
|  | 5200 | // Note: We don't check the case that index is positive while value < lower_bound, because in | 
|  | 5201 | // this case, index >= num_entries must be true. So that we can save one branch instruction. | 
|  | 5202 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); | 
|  | 5203 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5204 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5205 | // Jump to successors[0] if value == lower_bound. | 
|  | 5206 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); | 
|  | 5207 | int32_t last_index = 0; | 
|  | 5208 | for (; num_entries - last_index > 2; last_index += 2) { | 
|  | 5209 | __ Addiu(temp_reg, temp_reg, -2); | 
|  | 5210 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. | 
|  | 5211 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); | 
|  | 5212 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. | 
|  | 5213 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); | 
|  | 5214 | } | 
|  | 5215 | if (num_entries - last_index == 2) { | 
|  | 5216 | // The last missing case_value. | 
|  | 5217 | __ Addiu(temp_reg, temp_reg, -1); | 
|  | 5218 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5219 | } | 
|  | 5220 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5221 | // And the default for any other value. | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5222 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { | 
|  | 5223 | __ B(codegen_->GetLabelOf(default_block)); | 
|  | 5224 | } | 
|  | 5225 | } | 
|  | 5226 |  | 
|  | 5227 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
|  | 5228 | // The trampoline uses the same calling convention as dex calling conventions, | 
|  | 5229 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain | 
|  | 5230 | // the method_idx. | 
|  | 5231 | HandleInvoke(invoke); | 
|  | 5232 | } | 
|  | 5233 |  | 
|  | 5234 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
|  | 5235 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); | 
|  | 5236 | } | 
|  | 5237 |  | 
| Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 5238 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { | 
|  | 5239 | LocationSummary* locations = | 
|  | 5240 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 5241 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 5242 | locations->SetOut(Location::RequiresRegister()); | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5243 | } | 
|  | 5244 |  | 
| Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 5245 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { | 
|  | 5246 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 5247 | uint32_t method_offset = 0; | 
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5248 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { | 
| Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 5249 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( | 
|  | 5250 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); | 
|  | 5251 | } else { | 
|  | 5252 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( | 
|  | 5253 | instruction->GetIndex() % mirror::Class::kImtSize, kMipsPointerSize).Uint32Value(); | 
|  | 5254 | } | 
|  | 5255 | __ LoadFromOffset(kLoadWord, | 
|  | 5256 | locations->Out().AsRegister<Register>(), | 
|  | 5257 | locations->InAt(0).AsRegister<Register>(), | 
|  | 5258 | method_offset); | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5259 | } | 
|  | 5260 |  | 
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5261 | #undef __ | 
|  | 5262 | #undef QUICK_ENTRY_POINT | 
|  | 5263 |  | 
|  | 5264 | }  // namespace mips | 
|  | 5265 | }  // namespace art |