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