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