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 | |
| 19 | #include "entrypoints/quick/quick_entrypoints.h" |
| 20 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 21 | #include "gc/accounting/card_table.h" |
| 22 | #include "intrinsics.h" |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 23 | #include "intrinsics_mips64.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 24 | #include "art_method.h" |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 25 | #include "code_generator_utils.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" |
| 30 | #include "utils/mips64/assembler_mips64.h" |
| 31 | #include "utils/assembler.h" |
| 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); |
| 213 | __ B(GetExitLabel()); |
| 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); |
| 260 | __ B(GetExitLabel()); |
| 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) { |
| 315 | __ B(GetReturnLabel()); |
| 316 | } else { |
| 317 | __ B(mips64_codegen->GetLabelOf(successor_)); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | Label* GetReturnLabel() { |
| 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. |
| 334 | Label return_label_; |
| 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(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 345 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 346 | : locations->Out(); |
| 347 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 348 | DCHECK(instruction_->IsCheckCast() |
| 349 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 350 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 351 | |
| 352 | __ Bind(GetEntryLabel()); |
| 353 | SaveLiveRegisters(codegen, locations); |
| 354 | |
| 355 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 356 | // move resolver. |
| 357 | InvokeRuntimeCallingConvention calling_convention; |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 358 | codegen->EmitParallelMoves(locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 359 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 360 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 361 | object_class, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 362 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 363 | Primitive::kPrimNot); |
| 364 | |
| 365 | if (instruction_->IsInstanceOf()) { |
| 366 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 367 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 368 | dex_pc, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 369 | this); |
| 370 | Primitive::Type ret_type = instruction_->GetType(); |
| 371 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 372 | mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 373 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, |
| 374 | uint32_t, |
| 375 | const mirror::Class*, |
| 376 | const mirror::Class*>(); |
| 377 | } else { |
| 378 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 379 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 380 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
| 381 | } |
| 382 | |
| 383 | RestoreLiveRegisters(codegen, locations); |
| 384 | __ B(GetExitLabel()); |
| 385 | } |
| 386 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 387 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; } |
| 388 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 389 | private: |
| 390 | HInstruction* const instruction_; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 391 | |
| 392 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64); |
| 393 | }; |
| 394 | |
| 395 | class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 396 | public: |
| 397 | explicit DeoptimizationSlowPathMIPS64(HInstruction* instruction) |
| 398 | : instruction_(instruction) {} |
| 399 | |
| 400 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 401 | __ Bind(GetEntryLabel()); |
| 402 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 403 | DCHECK(instruction_->IsDeoptimize()); |
| 404 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 405 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 406 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 407 | mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this); |
| 408 | } |
| 409 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 410 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; } |
| 411 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 412 | private: |
| 413 | HInstruction* const instruction_; |
| 414 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64); |
| 415 | }; |
| 416 | |
| 417 | CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph, |
| 418 | const Mips64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 419 | const CompilerOptions& compiler_options, |
| 420 | OptimizingCompilerStats* stats) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 421 | : CodeGenerator(graph, |
| 422 | kNumberOfGpuRegisters, |
| 423 | kNumberOfFpuRegisters, |
| 424 | 0, // kNumberOfRegisterPairs |
| 425 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 426 | arraysize(kCoreCalleeSaves)), |
| 427 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 428 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 429 | compiler_options, |
| 430 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 431 | block_labels_(nullptr), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 432 | location_builder_(graph, this), |
| 433 | instruction_visitor_(graph, this), |
| 434 | move_resolver_(graph->GetArena(), this), |
| 435 | isa_features_(isa_features) { |
| 436 | // Save RA (containing the return address) to mimic Quick. |
| 437 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 438 | } |
| 439 | |
| 440 | #undef __ |
| 441 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> |
| 442 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, x).Int32Value() |
| 443 | |
| 444 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { |
| 445 | CodeGenerator::Finalize(allocator); |
| 446 | } |
| 447 | |
| 448 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { |
| 449 | return codegen_->GetAssembler(); |
| 450 | } |
| 451 | |
| 452 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 453 | DCHECK_LT(index, moves_.size()); |
| 454 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 455 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 456 | } |
| 457 | |
| 458 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 459 | DCHECK_LT(index, moves_.size()); |
| 460 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 461 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); |
| 462 | } |
| 463 | |
| 464 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { |
| 465 | // Pop reg |
| 466 | __ Ld(GpuRegister(reg), SP, 0); |
| 467 | __ DecreaseFrameSize(kMips64WordSize); |
| 468 | } |
| 469 | |
| 470 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { |
| 471 | // Push reg |
| 472 | __ IncreaseFrameSize(kMips64WordSize); |
| 473 | __ Sd(GpuRegister(reg), SP, 0); |
| 474 | } |
| 475 | |
| 476 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { |
| 477 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; |
| 478 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; |
| 479 | // Allocate a scratch register other than TMP, if available. |
| 480 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 481 | // automatically unspilled when the scratch scope object is destroyed). |
| 482 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 483 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
| 484 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64WordSize : 0; |
| 485 | __ LoadFromOffset(load_type, |
| 486 | GpuRegister(ensure_scratch.GetRegister()), |
| 487 | SP, |
| 488 | index1 + stack_offset); |
| 489 | __ LoadFromOffset(load_type, |
| 490 | TMP, |
| 491 | SP, |
| 492 | index2 + stack_offset); |
| 493 | __ StoreToOffset(store_type, |
| 494 | GpuRegister(ensure_scratch.GetRegister()), |
| 495 | SP, |
| 496 | index2 + stack_offset); |
| 497 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); |
| 498 | } |
| 499 | |
| 500 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 501 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 502 | } |
| 503 | |
| 504 | // TODO: mapping of floating-point registers to DWARF |
| 505 | |
| 506 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 507 | __ Bind(&frame_entry_label_); |
| 508 | |
| 509 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod(); |
| 510 | |
| 511 | if (do_overflow_check) { |
| 512 | __ LoadFromOffset(kLoadWord, |
| 513 | ZERO, |
| 514 | SP, |
| 515 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64))); |
| 516 | RecordPcInfo(nullptr, 0); |
| 517 | } |
| 518 | |
| 519 | // TODO: anything related to T9/GP/GOT/PIC/.so's? |
| 520 | |
| 521 | if (HasEmptyFrame()) { |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | // Make sure the frame size isn't unreasonably large. Per the various APIs |
| 526 | // it looks like it should always be less than 2GB in size, which allows |
| 527 | // us using 32-bit signed offsets from the stack pointer. |
| 528 | if (GetFrameSize() > 0x7FFFFFFF) |
| 529 | LOG(FATAL) << "Stack frame larger than 2GB"; |
| 530 | |
| 531 | // Spill callee-saved registers. |
| 532 | // Note that their cumulative size is small and they can be indexed using |
| 533 | // 16-bit offsets. |
| 534 | |
| 535 | // TODO: increment/decrement SP in one step instead of two or remove this comment. |
| 536 | |
| 537 | uint32_t ofs = FrameEntrySpillSize(); |
| 538 | __ IncreaseFrameSize(ofs); |
| 539 | |
| 540 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 541 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 542 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 543 | ofs -= kMips64WordSize; |
| 544 | __ Sd(reg, SP, ofs); |
| 545 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 550 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 551 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 552 | ofs -= kMips64WordSize; |
| 553 | __ Sdc1(reg, SP, ofs); |
| 554 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | // Allocate the rest of the frame and store the current method pointer |
| 559 | // at its end. |
| 560 | |
| 561 | __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); |
| 562 | |
| 563 | static_assert(IsInt<16>(kCurrentMethodStackOffset), |
| 564 | "kCurrentMethodStackOffset must fit into int16_t"); |
| 565 | __ Sd(kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 566 | } |
| 567 | |
| 568 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 569 | __ cfi().RememberState(); |
| 570 | |
| 571 | // TODO: anything related to T9/GP/GOT/PIC/.so's? |
| 572 | |
| 573 | if (!HasEmptyFrame()) { |
| 574 | // Deallocate the rest of the frame. |
| 575 | |
| 576 | __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); |
| 577 | |
| 578 | // Restore callee-saved registers. |
| 579 | // Note that their cumulative size is small and they can be indexed using |
| 580 | // 16-bit offsets. |
| 581 | |
| 582 | // TODO: increment/decrement SP in one step instead of two or remove this comment. |
| 583 | |
| 584 | uint32_t ofs = 0; |
| 585 | |
| 586 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 587 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 588 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 589 | __ Ldc1(reg, SP, ofs); |
| 590 | ofs += kMips64WordSize; |
| 591 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 596 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 597 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 598 | __ Ld(reg, SP, ofs); |
| 599 | ofs += kMips64WordSize; |
| 600 | __ cfi().Restore(DWARFReg(reg)); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | DCHECK_EQ(ofs, FrameEntrySpillSize()); |
| 605 | __ DecreaseFrameSize(ofs); |
| 606 | } |
| 607 | |
| 608 | __ Jr(RA); |
| 609 | |
| 610 | __ cfi().RestoreState(); |
| 611 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 612 | } |
| 613 | |
| 614 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 615 | __ Bind(GetLabelOf(block)); |
| 616 | } |
| 617 | |
| 618 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 619 | Location source, |
| 620 | Primitive::Type type) { |
| 621 | if (source.Equals(destination)) { |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | // A valid move can always be inferred from the destination and source |
| 626 | // locations. When moving from and to a register, the argument type can be |
| 627 | // used to generate 32bit instead of 64bit moves. |
| 628 | bool unspecified_type = (type == Primitive::kPrimVoid); |
| 629 | DCHECK_EQ(unspecified_type, false); |
| 630 | |
| 631 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 632 | if (unspecified_type) { |
| 633 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 634 | if (source.IsStackSlot() || |
| 635 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 636 | || src_cst->IsFloatConstant() |
| 637 | || src_cst->IsNullConstant()))) { |
| 638 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
| 639 | type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
| 640 | } else { |
| 641 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 642 | // type is appropriate. Else the source is a register, and since the |
| 643 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 644 | // move. |
| 645 | type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
| 646 | } |
| 647 | } |
| 648 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) || |
| 649 | (destination.IsRegister() && !Primitive::IsFloatingPointType(type))); |
| 650 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 651 | // Move to GPR/FPR from stack |
| 652 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 653 | if (Primitive::IsFloatingPointType(type)) { |
| 654 | __ LoadFpuFromOffset(load_type, |
| 655 | destination.AsFpuRegister<FpuRegister>(), |
| 656 | SP, |
| 657 | source.GetStackIndex()); |
| 658 | } else { |
| 659 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 660 | __ LoadFromOffset(load_type, |
| 661 | destination.AsRegister<GpuRegister>(), |
| 662 | SP, |
| 663 | source.GetStackIndex()); |
| 664 | } |
| 665 | } else if (source.IsConstant()) { |
| 666 | // Move to GPR/FPR from constant |
| 667 | GpuRegister gpr = AT; |
| 668 | if (!Primitive::IsFloatingPointType(type)) { |
| 669 | gpr = destination.AsRegister<GpuRegister>(); |
| 670 | } |
| 671 | if (type == Primitive::kPrimInt || type == Primitive::kPrimFloat) { |
| 672 | __ LoadConst32(gpr, GetInt32ValueOf(source.GetConstant()->AsConstant())); |
| 673 | } else { |
| 674 | __ LoadConst64(gpr, GetInt64ValueOf(source.GetConstant()->AsConstant())); |
| 675 | } |
| 676 | if (type == Primitive::kPrimFloat) { |
| 677 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 678 | } else if (type == Primitive::kPrimDouble) { |
| 679 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 680 | } |
| 681 | } else { |
| 682 | if (destination.IsRegister()) { |
| 683 | // Move to GPR from GPR |
| 684 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 685 | } else { |
| 686 | // Move to FPR from FPR |
| 687 | if (type == Primitive::kPrimFloat) { |
| 688 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 689 | } else { |
| 690 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 691 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | } else { // The destination is not a register. It must be a stack slot. |
| 696 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 697 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 698 | if (unspecified_type) { |
| 699 | if (source.IsRegister()) { |
| 700 | type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
| 701 | } else { |
| 702 | type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
| 703 | } |
| 704 | } |
| 705 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) && |
| 706 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(type))); |
| 707 | // Move to stack from GPR/FPR |
| 708 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 709 | if (source.IsRegister()) { |
| 710 | __ StoreToOffset(store_type, |
| 711 | source.AsRegister<GpuRegister>(), |
| 712 | SP, |
| 713 | destination.GetStackIndex()); |
| 714 | } else { |
| 715 | __ StoreFpuToOffset(store_type, |
| 716 | source.AsFpuRegister<FpuRegister>(), |
| 717 | SP, |
| 718 | destination.GetStackIndex()); |
| 719 | } |
| 720 | } else if (source.IsConstant()) { |
| 721 | // Move to stack from constant |
| 722 | HConstant* src_cst = source.GetConstant(); |
| 723 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 724 | if (destination.IsStackSlot()) { |
| 725 | __ LoadConst32(TMP, GetInt32ValueOf(src_cst->AsConstant())); |
| 726 | } else { |
| 727 | __ LoadConst64(TMP, GetInt64ValueOf(src_cst->AsConstant())); |
| 728 | } |
| 729 | __ StoreToOffset(store_type, TMP, SP, destination.GetStackIndex()); |
| 730 | } else { |
| 731 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 732 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 733 | // Move to stack from stack |
| 734 | if (destination.IsStackSlot()) { |
| 735 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 736 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 737 | } else { |
| 738 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 739 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, |
| 746 | Location loc2, |
| 747 | Primitive::Type type ATTRIBUTE_UNUSED) { |
| 748 | DCHECK(!loc1.IsConstant()); |
| 749 | DCHECK(!loc2.IsConstant()); |
| 750 | |
| 751 | if (loc1.Equals(loc2)) { |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 756 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
| 757 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 758 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 759 | |
| 760 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 761 | // Swap 2 GPRs |
| 762 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 763 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 764 | __ Move(TMP, r2); |
| 765 | __ Move(r2, r1); |
| 766 | __ Move(r1, TMP); |
| 767 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 768 | // Swap 2 FPRs |
| 769 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 770 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
| 771 | // TODO: Can MOV.S/MOV.D be used here to save one instruction? |
| 772 | // Need to distinguish float from double, right? |
| 773 | __ Dmfc1(TMP, r2); |
| 774 | __ Dmfc1(AT, r1); |
| 775 | __ Dmtc1(TMP, r1); |
| 776 | __ Dmtc1(AT, r2); |
| 777 | } else if (is_slot1 != is_slot2) { |
| 778 | // Swap GPR/FPR and stack slot |
| 779 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 780 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 781 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 782 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 783 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 784 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 785 | if (reg_loc.IsFpuRegister()) { |
| 786 | __ StoreFpuToOffset(store_type, |
| 787 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 788 | SP, |
| 789 | mem_loc.GetStackIndex()); |
| 790 | // TODO: review this MTC1/DMTC1 move |
| 791 | if (mem_loc.IsStackSlot()) { |
| 792 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 793 | } else { |
| 794 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 795 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 796 | } |
| 797 | } else { |
| 798 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 799 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 800 | } |
| 801 | } else if (is_slot1 && is_slot2) { |
| 802 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 803 | loc2.GetStackIndex(), |
| 804 | loc1.IsDoubleStackSlot()); |
| 805 | } else { |
| 806 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | void CodeGeneratorMIPS64::Move(HInstruction* instruction, |
| 811 | Location location, |
| 812 | HInstruction* move_for) { |
| 813 | LocationSummary* locations = instruction->GetLocations(); |
| 814 | Primitive::Type type = instruction->GetType(); |
| 815 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 816 | |
| 817 | if (instruction->IsCurrentMethod()) { |
| 818 | MoveLocation(location, Location::DoubleStackSlot(kCurrentMethodStackOffset), type); |
| 819 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
| 820 | return; |
| 821 | } else if (instruction->IsIntConstant() |
| 822 | || instruction->IsLongConstant() |
| 823 | || instruction->IsNullConstant()) { |
| 824 | if (location.IsRegister()) { |
| 825 | // Move to GPR from constant |
| 826 | GpuRegister dst = location.AsRegister<GpuRegister>(); |
| 827 | if (instruction->IsNullConstant() || instruction->IsIntConstant()) { |
| 828 | __ LoadConst32(dst, GetInt32ValueOf(instruction->AsConstant())); |
| 829 | } else { |
| 830 | __ LoadConst64(dst, instruction->AsLongConstant()->GetValue()); |
| 831 | } |
| 832 | } else { |
| 833 | DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot()); |
| 834 | // Move to stack from constant |
| 835 | if (location.IsStackSlot()) { |
| 836 | __ LoadConst32(TMP, GetInt32ValueOf(instruction->AsConstant())); |
| 837 | __ StoreToOffset(kStoreWord, TMP, SP, location.GetStackIndex()); |
| 838 | } else { |
| 839 | __ LoadConst64(TMP, instruction->AsLongConstant()->GetValue()); |
| 840 | __ StoreToOffset(kStoreDoubleword, TMP, SP, location.GetStackIndex()); |
| 841 | } |
| 842 | } |
| 843 | } else if (instruction->IsTemporary()) { |
| 844 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 845 | MoveLocation(location, temp_location, type); |
| 846 | } else if (instruction->IsLoadLocal()) { |
| 847 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 848 | if (Primitive::Is64BitType(type)) { |
| 849 | MoveLocation(location, Location::DoubleStackSlot(stack_slot), type); |
| 850 | } else { |
| 851 | MoveLocation(location, Location::StackSlot(stack_slot), type); |
| 852 | } |
| 853 | } else { |
| 854 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
| 855 | MoveLocation(location, locations->Out(), type); |
| 856 | } |
| 857 | } |
| 858 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 859 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 860 | DCHECK(location.IsRegister()); |
| 861 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 862 | } |
| 863 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 864 | Location CodeGeneratorMIPS64::GetStackLocation(HLoadLocal* load) const { |
| 865 | Primitive::Type type = load->GetType(); |
| 866 | |
| 867 | switch (type) { |
| 868 | case Primitive::kPrimNot: |
| 869 | case Primitive::kPrimInt: |
| 870 | case Primitive::kPrimFloat: |
| 871 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 872 | |
| 873 | case Primitive::kPrimLong: |
| 874 | case Primitive::kPrimDouble: |
| 875 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 876 | |
| 877 | case Primitive::kPrimBoolean: |
| 878 | case Primitive::kPrimByte: |
| 879 | case Primitive::kPrimChar: |
| 880 | case Primitive::kPrimShort: |
| 881 | case Primitive::kPrimVoid: |
| 882 | LOG(FATAL) << "Unexpected type " << type; |
| 883 | } |
| 884 | |
| 885 | LOG(FATAL) << "Unreachable"; |
| 886 | return Location::NoLocation(); |
| 887 | } |
| 888 | |
| 889 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, GpuRegister value) { |
| 890 | Label done; |
| 891 | GpuRegister card = AT; |
| 892 | GpuRegister temp = TMP; |
| 893 | __ Beqzc(value, &done); |
| 894 | __ LoadFromOffset(kLoadDoubleword, |
| 895 | card, |
| 896 | TR, |
| 897 | Thread::CardTableOffset<kMips64WordSize>().Int32Value()); |
| 898 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 899 | __ Daddu(temp, card, temp); |
| 900 | __ Sb(card, temp, 0); |
| 901 | __ Bind(&done); |
| 902 | } |
| 903 | |
| 904 | void CodeGeneratorMIPS64::SetupBlockedRegisters(bool is_baseline ATTRIBUTE_UNUSED) const { |
| 905 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 906 | blocked_core_registers_[ZERO] = true; |
| 907 | blocked_core_registers_[K0] = true; |
| 908 | blocked_core_registers_[K1] = true; |
| 909 | blocked_core_registers_[GP] = true; |
| 910 | blocked_core_registers_[SP] = true; |
| 911 | blocked_core_registers_[RA] = true; |
| 912 | |
| 913 | // AT and TMP(T8) are used as temporary/scratch registers |
| 914 | // (similar to how AT is used by MIPS assemblers). |
| 915 | blocked_core_registers_[AT] = true; |
| 916 | blocked_core_registers_[TMP] = true; |
| 917 | blocked_fpu_registers_[FTMP] = true; |
| 918 | |
| 919 | // Reserve suspend and thread registers. |
| 920 | blocked_core_registers_[S0] = true; |
| 921 | blocked_core_registers_[TR] = true; |
| 922 | |
| 923 | // Reserve T9 for function calls |
| 924 | blocked_core_registers_[T9] = true; |
| 925 | |
| 926 | // TODO: review; anything else? |
| 927 | |
| 928 | // TODO: make these two for's conditional on is_baseline once |
| 929 | // all the issues with register saving/restoring are sorted out. |
| 930 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 931 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 932 | } |
| 933 | |
| 934 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 935 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | Location CodeGeneratorMIPS64::AllocateFreeRegister(Primitive::Type type) const { |
| 940 | if (type == Primitive::kPrimVoid) { |
| 941 | LOG(FATAL) << "Unreachable type " << type; |
| 942 | } |
| 943 | |
| 944 | if (Primitive::IsFloatingPointType(type)) { |
| 945 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFpuRegisters); |
| 946 | return Location::FpuRegisterLocation(reg); |
| 947 | } else { |
| 948 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfGpuRegisters); |
| 949 | return Location::RegisterLocation(reg); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 954 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
| 955 | return kMips64WordSize; |
| 956 | } |
| 957 | |
| 958 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 959 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
| 960 | return kMips64WordSize; |
| 961 | } |
| 962 | |
| 963 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 964 | __ StoreFpuToOffset(kStoreDoubleword, FpuRegister(reg_id), SP, stack_index); |
| 965 | return kMips64WordSize; |
| 966 | } |
| 967 | |
| 968 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 969 | __ LoadFpuFromOffset(kLoadDoubleword, FpuRegister(reg_id), SP, stack_index); |
| 970 | return kMips64WordSize; |
| 971 | } |
| 972 | |
| 973 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 974 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 978 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 981 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 982 | HInstruction* instruction, |
| 983 | uint32_t dex_pc, |
| 984 | SlowPathCode* slow_path) { |
| 985 | InvokeRuntime(GetThreadOffset<kMips64WordSize>(entrypoint).Int32Value(), |
| 986 | instruction, |
| 987 | dex_pc, |
| 988 | slow_path); |
| 989 | } |
| 990 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 991 | void CodeGeneratorMIPS64::InvokeRuntime(int32_t entry_point_offset, |
| 992 | HInstruction* instruction, |
| 993 | uint32_t dex_pc, |
| 994 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 995 | ValidateInvokeRuntime(instruction, slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 996 | // TODO: anything related to T9/GP/GOT/PIC/.so's? |
| 997 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 998 | __ Jalr(T9); |
| 999 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1003 | GpuRegister class_reg) { |
| 1004 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1005 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1006 | __ Bltc(TMP, AT, slow_path->GetEntryLabel()); |
| 1007 | // TODO: barrier needed? |
| 1008 | __ Bind(slow_path->GetExitLabel()); |
| 1009 | } |
| 1010 | |
| 1011 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1012 | __ Sync(0); // only stype 0 is supported |
| 1013 | } |
| 1014 | |
| 1015 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1016 | HBasicBlock* successor) { |
| 1017 | SuspendCheckSlowPathMIPS64* slow_path = |
| 1018 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1019 | codegen_->AddSlowPath(slow_path); |
| 1020 | |
| 1021 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1022 | TMP, |
| 1023 | TR, |
| 1024 | Thread::ThreadFlagsOffset<kMips64WordSize>().Int32Value()); |
| 1025 | if (successor == nullptr) { |
| 1026 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1027 | __ Bind(slow_path->GetReturnLabel()); |
| 1028 | } else { |
| 1029 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
| 1030 | __ B(slow_path->GetEntryLabel()); |
| 1031 | // slow_path will return to GetLabelOf(successor). |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1036 | CodeGeneratorMIPS64* codegen) |
| 1037 | : HGraphVisitor(graph), |
| 1038 | assembler_(codegen->GetAssembler()), |
| 1039 | codegen_(codegen) {} |
| 1040 | |
| 1041 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1042 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1043 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1044 | Primitive::Type type = instruction->GetResultType(); |
| 1045 | switch (type) { |
| 1046 | case Primitive::kPrimInt: |
| 1047 | case Primitive::kPrimLong: { |
| 1048 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1049 | HInstruction* right = instruction->InputAt(1); |
| 1050 | bool can_use_imm = false; |
| 1051 | if (right->IsConstant()) { |
| 1052 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1053 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1054 | can_use_imm = IsUint<16>(imm); |
| 1055 | } else if (instruction->IsAdd()) { |
| 1056 | can_use_imm = IsInt<16>(imm); |
| 1057 | } else { |
| 1058 | DCHECK(instruction->IsSub()); |
| 1059 | can_use_imm = IsInt<16>(-imm); |
| 1060 | } |
| 1061 | } |
| 1062 | if (can_use_imm) |
| 1063 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1064 | else |
| 1065 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1066 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1067 | } |
| 1068 | break; |
| 1069 | |
| 1070 | case Primitive::kPrimFloat: |
| 1071 | case Primitive::kPrimDouble: |
| 1072 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1073 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1074 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1075 | break; |
| 1076 | |
| 1077 | default: |
| 1078 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1083 | Primitive::Type type = instruction->GetType(); |
| 1084 | LocationSummary* locations = instruction->GetLocations(); |
| 1085 | |
| 1086 | switch (type) { |
| 1087 | case Primitive::kPrimInt: |
| 1088 | case Primitive::kPrimLong: { |
| 1089 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1090 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1091 | Location rhs_location = locations->InAt(1); |
| 1092 | |
| 1093 | GpuRegister rhs_reg = ZERO; |
| 1094 | int64_t rhs_imm = 0; |
| 1095 | bool use_imm = rhs_location.IsConstant(); |
| 1096 | if (use_imm) { |
| 1097 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1098 | } else { |
| 1099 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1100 | } |
| 1101 | |
| 1102 | if (instruction->IsAnd()) { |
| 1103 | if (use_imm) |
| 1104 | __ Andi(dst, lhs, rhs_imm); |
| 1105 | else |
| 1106 | __ And(dst, lhs, rhs_reg); |
| 1107 | } else if (instruction->IsOr()) { |
| 1108 | if (use_imm) |
| 1109 | __ Ori(dst, lhs, rhs_imm); |
| 1110 | else |
| 1111 | __ Or(dst, lhs, rhs_reg); |
| 1112 | } else if (instruction->IsXor()) { |
| 1113 | if (use_imm) |
| 1114 | __ Xori(dst, lhs, rhs_imm); |
| 1115 | else |
| 1116 | __ Xor(dst, lhs, rhs_reg); |
| 1117 | } else if (instruction->IsAdd()) { |
| 1118 | if (type == Primitive::kPrimInt) { |
| 1119 | if (use_imm) |
| 1120 | __ Addiu(dst, lhs, rhs_imm); |
| 1121 | else |
| 1122 | __ Addu(dst, lhs, rhs_reg); |
| 1123 | } else { |
| 1124 | if (use_imm) |
| 1125 | __ Daddiu(dst, lhs, rhs_imm); |
| 1126 | else |
| 1127 | __ Daddu(dst, lhs, rhs_reg); |
| 1128 | } |
| 1129 | } else { |
| 1130 | DCHECK(instruction->IsSub()); |
| 1131 | if (type == Primitive::kPrimInt) { |
| 1132 | if (use_imm) |
| 1133 | __ Addiu(dst, lhs, -rhs_imm); |
| 1134 | else |
| 1135 | __ Subu(dst, lhs, rhs_reg); |
| 1136 | } else { |
| 1137 | if (use_imm) |
| 1138 | __ Daddiu(dst, lhs, -rhs_imm); |
| 1139 | else |
| 1140 | __ Dsubu(dst, lhs, rhs_reg); |
| 1141 | } |
| 1142 | } |
| 1143 | break; |
| 1144 | } |
| 1145 | case Primitive::kPrimFloat: |
| 1146 | case Primitive::kPrimDouble: { |
| 1147 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1148 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1149 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1150 | if (instruction->IsAdd()) { |
| 1151 | if (type == Primitive::kPrimFloat) |
| 1152 | __ AddS(dst, lhs, rhs); |
| 1153 | else |
| 1154 | __ AddD(dst, lhs, rhs); |
| 1155 | } else if (instruction->IsSub()) { |
| 1156 | if (type == Primitive::kPrimFloat) |
| 1157 | __ SubS(dst, lhs, rhs); |
| 1158 | else |
| 1159 | __ SubD(dst, lhs, rhs); |
| 1160 | } else { |
| 1161 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 1162 | } |
| 1163 | break; |
| 1164 | } |
| 1165 | default: |
| 1166 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
| 1171 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1172 | |
| 1173 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1174 | Primitive::Type type = instr->GetResultType(); |
| 1175 | switch (type) { |
| 1176 | case Primitive::kPrimInt: |
| 1177 | case Primitive::kPrimLong: { |
| 1178 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1179 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1180 | locations->SetOut(Location::RequiresRegister()); |
| 1181 | break; |
| 1182 | } |
| 1183 | default: |
| 1184 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
| 1189 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1190 | LocationSummary* locations = instr->GetLocations(); |
| 1191 | Primitive::Type type = instr->GetType(); |
| 1192 | |
| 1193 | switch (type) { |
| 1194 | case Primitive::kPrimInt: |
| 1195 | case Primitive::kPrimLong: { |
| 1196 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1197 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1198 | Location rhs_location = locations->InAt(1); |
| 1199 | |
| 1200 | GpuRegister rhs_reg = ZERO; |
| 1201 | int64_t rhs_imm = 0; |
| 1202 | bool use_imm = rhs_location.IsConstant(); |
| 1203 | if (use_imm) { |
| 1204 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1205 | } else { |
| 1206 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1207 | } |
| 1208 | |
| 1209 | if (use_imm) { |
| 1210 | uint32_t shift_value = (type == Primitive::kPrimInt) |
| 1211 | ? static_cast<uint32_t>(rhs_imm & kMaxIntShiftValue) |
| 1212 | : static_cast<uint32_t>(rhs_imm & kMaxLongShiftValue); |
| 1213 | |
| 1214 | if (type == Primitive::kPrimInt) { |
| 1215 | if (instr->IsShl()) { |
| 1216 | __ Sll(dst, lhs, shift_value); |
| 1217 | } else if (instr->IsShr()) { |
| 1218 | __ Sra(dst, lhs, shift_value); |
| 1219 | } else { |
| 1220 | __ Srl(dst, lhs, shift_value); |
| 1221 | } |
| 1222 | } else { |
| 1223 | if (shift_value < 32) { |
| 1224 | if (instr->IsShl()) { |
| 1225 | __ Dsll(dst, lhs, shift_value); |
| 1226 | } else if (instr->IsShr()) { |
| 1227 | __ Dsra(dst, lhs, shift_value); |
| 1228 | } else { |
| 1229 | __ Dsrl(dst, lhs, shift_value); |
| 1230 | } |
| 1231 | } else { |
| 1232 | shift_value -= 32; |
| 1233 | if (instr->IsShl()) { |
| 1234 | __ Dsll32(dst, lhs, shift_value); |
| 1235 | } else if (instr->IsShr()) { |
| 1236 | __ Dsra32(dst, lhs, shift_value); |
| 1237 | } else { |
| 1238 | __ Dsrl32(dst, lhs, shift_value); |
| 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | } else { |
| 1243 | if (type == Primitive::kPrimInt) { |
| 1244 | if (instr->IsShl()) { |
| 1245 | __ Sllv(dst, lhs, rhs_reg); |
| 1246 | } else if (instr->IsShr()) { |
| 1247 | __ Srav(dst, lhs, rhs_reg); |
| 1248 | } else { |
| 1249 | __ Srlv(dst, lhs, rhs_reg); |
| 1250 | } |
| 1251 | } else { |
| 1252 | if (instr->IsShl()) { |
| 1253 | __ Dsllv(dst, lhs, rhs_reg); |
| 1254 | } else if (instr->IsShr()) { |
| 1255 | __ Dsrav(dst, lhs, rhs_reg); |
| 1256 | } else { |
| 1257 | __ Dsrlv(dst, lhs, rhs_reg); |
| 1258 | } |
| 1259 | } |
| 1260 | } |
| 1261 | break; |
| 1262 | } |
| 1263 | default: |
| 1264 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 1269 | HandleBinaryOp(instruction); |
| 1270 | } |
| 1271 | |
| 1272 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 1273 | HandleBinaryOp(instruction); |
| 1274 | } |
| 1275 | |
| 1276 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 1277 | HandleBinaryOp(instruction); |
| 1278 | } |
| 1279 | |
| 1280 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 1281 | HandleBinaryOp(instruction); |
| 1282 | } |
| 1283 | |
| 1284 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 1285 | LocationSummary* locations = |
| 1286 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1287 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1288 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1289 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1290 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1291 | } else { |
| 1292 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 1297 | LocationSummary* locations = instruction->GetLocations(); |
| 1298 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1299 | Location index = locations->InAt(1); |
| 1300 | Primitive::Type type = instruction->GetType(); |
| 1301 | |
| 1302 | switch (type) { |
| 1303 | case Primitive::kPrimBoolean: { |
| 1304 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1305 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1306 | if (index.IsConstant()) { |
| 1307 | size_t offset = |
| 1308 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1309 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 1310 | } else { |
| 1311 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
| 1312 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 1313 | } |
| 1314 | break; |
| 1315 | } |
| 1316 | |
| 1317 | case Primitive::kPrimByte: { |
| 1318 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
| 1319 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1320 | if (index.IsConstant()) { |
| 1321 | size_t offset = |
| 1322 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1323 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 1324 | } else { |
| 1325 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
| 1326 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset); |
| 1327 | } |
| 1328 | break; |
| 1329 | } |
| 1330 | |
| 1331 | case Primitive::kPrimShort: { |
| 1332 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
| 1333 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1334 | if (index.IsConstant()) { |
| 1335 | size_t offset = |
| 1336 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1337 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 1338 | } else { |
| 1339 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2); |
| 1340 | __ Daddu(TMP, obj, TMP); |
| 1341 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset); |
| 1342 | } |
| 1343 | break; |
| 1344 | } |
| 1345 | |
| 1346 | case Primitive::kPrimChar: { |
| 1347 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1348 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1349 | if (index.IsConstant()) { |
| 1350 | size_t offset = |
| 1351 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1352 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 1353 | } else { |
| 1354 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2); |
| 1355 | __ Daddu(TMP, obj, TMP); |
| 1356 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 1357 | } |
| 1358 | break; |
| 1359 | } |
| 1360 | |
| 1361 | case Primitive::kPrimInt: |
| 1362 | case Primitive::kPrimNot: { |
| 1363 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 1364 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1365 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1366 | LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord; |
| 1367 | if (index.IsConstant()) { |
| 1368 | size_t offset = |
| 1369 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1370 | __ LoadFromOffset(load_type, out, obj, offset); |
| 1371 | } else { |
| 1372 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); |
| 1373 | __ Daddu(TMP, obj, TMP); |
| 1374 | __ LoadFromOffset(load_type, out, TMP, data_offset); |
| 1375 | } |
| 1376 | break; |
| 1377 | } |
| 1378 | |
| 1379 | case Primitive::kPrimLong: { |
| 1380 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1381 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1382 | if (index.IsConstant()) { |
| 1383 | size_t offset = |
| 1384 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1385 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset); |
| 1386 | } else { |
| 1387 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); |
| 1388 | __ Daddu(TMP, obj, TMP); |
| 1389 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset); |
| 1390 | } |
| 1391 | break; |
| 1392 | } |
| 1393 | |
| 1394 | case Primitive::kPrimFloat: { |
| 1395 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 1396 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1397 | if (index.IsConstant()) { |
| 1398 | size_t offset = |
| 1399 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1400 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset); |
| 1401 | } else { |
| 1402 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); |
| 1403 | __ Daddu(TMP, obj, TMP); |
| 1404 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset); |
| 1405 | } |
| 1406 | break; |
| 1407 | } |
| 1408 | |
| 1409 | case Primitive::kPrimDouble: { |
| 1410 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 1411 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1412 | if (index.IsConstant()) { |
| 1413 | size_t offset = |
| 1414 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1415 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset); |
| 1416 | } else { |
| 1417 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); |
| 1418 | __ Daddu(TMP, obj, TMP); |
| 1419 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset); |
| 1420 | } |
| 1421 | break; |
| 1422 | } |
| 1423 | |
| 1424 | case Primitive::kPrimVoid: |
| 1425 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1426 | UNREACHABLE(); |
| 1427 | } |
| 1428 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1429 | } |
| 1430 | |
| 1431 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 1432 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1433 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1434 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1435 | } |
| 1436 | |
| 1437 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 1438 | LocationSummary* locations = instruction->GetLocations(); |
| 1439 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
| 1440 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1441 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1442 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1443 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1444 | } |
| 1445 | |
| 1446 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
David Brazdil | bb3d505 | 2015-09-21 18:39:16 +0100 | [diff] [blame] | 1447 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1448 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1449 | instruction, |
David Brazdil | bb3d505 | 2015-09-21 18:39:16 +0100 | [diff] [blame] | 1450 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 1451 | if (needs_runtime_call) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1452 | InvokeRuntimeCallingConvention calling_convention; |
| 1453 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1454 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1455 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1456 | } else { |
| 1457 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1458 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1459 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 1460 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 1461 | } else { |
| 1462 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1463 | } |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 1468 | LocationSummary* locations = instruction->GetLocations(); |
| 1469 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1470 | Location index = locations->InAt(1); |
| 1471 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1472 | bool needs_runtime_call = locations->WillCall(); |
| 1473 | bool needs_write_barrier = |
| 1474 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 1475 | |
| 1476 | switch (value_type) { |
| 1477 | case Primitive::kPrimBoolean: |
| 1478 | case Primitive::kPrimByte: { |
| 1479 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1480 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1481 | if (index.IsConstant()) { |
| 1482 | size_t offset = |
| 1483 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1484 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 1485 | } else { |
| 1486 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
| 1487 | __ StoreToOffset(kStoreByte, value, TMP, data_offset); |
| 1488 | } |
| 1489 | break; |
| 1490 | } |
| 1491 | |
| 1492 | case Primitive::kPrimShort: |
| 1493 | case Primitive::kPrimChar: { |
| 1494 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1495 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1496 | if (index.IsConstant()) { |
| 1497 | size_t offset = |
| 1498 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1499 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 1500 | } else { |
| 1501 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2); |
| 1502 | __ Daddu(TMP, obj, TMP); |
| 1503 | __ StoreToOffset(kStoreHalfword, value, TMP, data_offset); |
| 1504 | } |
| 1505 | break; |
| 1506 | } |
| 1507 | |
| 1508 | case Primitive::kPrimInt: |
| 1509 | case Primitive::kPrimNot: { |
| 1510 | if (!needs_runtime_call) { |
| 1511 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1512 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1513 | if (index.IsConstant()) { |
| 1514 | size_t offset = |
| 1515 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1516 | __ StoreToOffset(kStoreWord, value, obj, offset); |
| 1517 | } else { |
| 1518 | DCHECK(index.IsRegister()) << index; |
| 1519 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); |
| 1520 | __ Daddu(TMP, obj, TMP); |
| 1521 | __ StoreToOffset(kStoreWord, value, TMP, data_offset); |
| 1522 | } |
| 1523 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1524 | if (needs_write_barrier) { |
| 1525 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 1526 | codegen_->MarkGCCard(obj, value); |
| 1527 | } |
| 1528 | } else { |
| 1529 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 1530 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 1531 | instruction, |
| 1532 | instruction->GetDexPc(), |
| 1533 | nullptr); |
| 1534 | } |
| 1535 | break; |
| 1536 | } |
| 1537 | |
| 1538 | case Primitive::kPrimLong: { |
| 1539 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1540 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1541 | if (index.IsConstant()) { |
| 1542 | size_t offset = |
| 1543 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1544 | __ StoreToOffset(kStoreDoubleword, value, obj, offset); |
| 1545 | } else { |
| 1546 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); |
| 1547 | __ Daddu(TMP, obj, TMP); |
| 1548 | __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset); |
| 1549 | } |
| 1550 | break; |
| 1551 | } |
| 1552 | |
| 1553 | case Primitive::kPrimFloat: { |
| 1554 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 1555 | FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>(); |
| 1556 | DCHECK(locations->InAt(2).IsFpuRegister()); |
| 1557 | if (index.IsConstant()) { |
| 1558 | size_t offset = |
| 1559 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1560 | __ StoreFpuToOffset(kStoreWord, value, obj, offset); |
| 1561 | } else { |
| 1562 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); |
| 1563 | __ Daddu(TMP, obj, TMP); |
| 1564 | __ StoreFpuToOffset(kStoreWord, value, TMP, data_offset); |
| 1565 | } |
| 1566 | break; |
| 1567 | } |
| 1568 | |
| 1569 | case Primitive::kPrimDouble: { |
| 1570 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 1571 | FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>(); |
| 1572 | DCHECK(locations->InAt(2).IsFpuRegister()); |
| 1573 | if (index.IsConstant()) { |
| 1574 | size_t offset = |
| 1575 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1576 | __ StoreFpuToOffset(kStoreDoubleword, value, obj, offset); |
| 1577 | } else { |
| 1578 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); |
| 1579 | __ Daddu(TMP, obj, TMP); |
| 1580 | __ StoreFpuToOffset(kStoreDoubleword, value, TMP, data_offset); |
| 1581 | } |
| 1582 | break; |
| 1583 | } |
| 1584 | |
| 1585 | case Primitive::kPrimVoid: |
| 1586 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1587 | UNREACHABLE(); |
| 1588 | } |
| 1589 | |
| 1590 | // Ints and objects are handled in the switch. |
| 1591 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 1592 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1597 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 1598 | ? LocationSummary::kCallOnSlowPath |
| 1599 | : LocationSummary::kNoCall; |
| 1600 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1601 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1602 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1603 | if (instruction->HasUses()) { |
| 1604 | locations->SetOut(Location::SameAsFirstInput()); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1609 | LocationSummary* locations = instruction->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1610 | BoundsCheckSlowPathMIPS64* slow_path = |
| 1611 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1612 | codegen_->AddSlowPath(slow_path); |
| 1613 | |
| 1614 | GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1615 | GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1616 | |
| 1617 | // length is limited by the maximum positive signed 32-bit integer. |
| 1618 | // Unsigned comparison of length and index checks for index < 0 |
| 1619 | // and for length <= index simultaneously. |
| 1620 | // Mips R6 requires lhs != rhs for compact branches. |
| 1621 | if (index == length) { |
| 1622 | __ B(slow_path->GetEntryLabel()); |
| 1623 | } else { |
| 1624 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
| 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
| 1629 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1630 | instruction, |
| 1631 | LocationSummary::kCallOnSlowPath); |
| 1632 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1633 | locations->SetInAt(1, Location::RequiresRegister()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1634 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1635 | locations->AddTemp(Location::RequiresRegister()); |
| 1636 | } |
| 1637 | |
| 1638 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
| 1639 | LocationSummary* locations = instruction->GetLocations(); |
| 1640 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1641 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1642 | GpuRegister obj_cls = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 1643 | |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1644 | SlowPathCodeMIPS64* slow_path = |
| 1645 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1646 | codegen_->AddSlowPath(slow_path); |
| 1647 | |
| 1648 | // TODO: avoid this check if we know obj is not null. |
| 1649 | __ Beqzc(obj, slow_path->GetExitLabel()); |
| 1650 | // Compare the class of `obj` with `cls`. |
| 1651 | __ LoadFromOffset(kLoadUnsignedWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); |
| 1652 | __ Bnec(obj_cls, cls, slow_path->GetEntryLabel()); |
| 1653 | __ Bind(slow_path->GetExitLabel()); |
| 1654 | } |
| 1655 | |
| 1656 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 1657 | LocationSummary* locations = |
| 1658 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 1659 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1660 | if (check->HasUses()) { |
| 1661 | locations->SetOut(Location::SameAsFirstInput()); |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 1666 | // We assume the class is not null. |
| 1667 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 1668 | check->GetLoadClass(), |
| 1669 | check, |
| 1670 | check->GetDexPc(), |
| 1671 | true); |
| 1672 | codegen_->AddSlowPath(slow_path); |
| 1673 | GenerateClassInitializationCheck(slow_path, |
| 1674 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 1675 | } |
| 1676 | |
| 1677 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
| 1678 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 1679 | |
| 1680 | LocationSummary::CallKind call_kind = Primitive::IsFloatingPointType(in_type) |
| 1681 | ? LocationSummary::kCall |
| 1682 | : LocationSummary::kNoCall; |
| 1683 | |
| 1684 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare, call_kind); |
| 1685 | |
| 1686 | switch (in_type) { |
| 1687 | case Primitive::kPrimLong: |
| 1688 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1689 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1690 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1691 | break; |
| 1692 | |
| 1693 | case Primitive::kPrimFloat: |
| 1694 | case Primitive::kPrimDouble: { |
| 1695 | InvokeRuntimeCallingConvention calling_convention; |
| 1696 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 1697 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 1698 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt)); |
| 1699 | break; |
| 1700 | } |
| 1701 | |
| 1702 | default: |
| 1703 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 1708 | LocationSummary* locations = instruction->GetLocations(); |
| 1709 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
| 1710 | |
| 1711 | // 0 if: left == right |
| 1712 | // 1 if: left > right |
| 1713 | // -1 if: left < right |
| 1714 | switch (in_type) { |
| 1715 | case Primitive::kPrimLong: { |
| 1716 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1717 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1718 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1719 | // TODO: more efficient (direct) comparison with a constant |
| 1720 | __ Slt(TMP, lhs, rhs); |
| 1721 | __ Slt(dst, rhs, lhs); |
| 1722 | __ Subu(dst, dst, TMP); |
| 1723 | break; |
| 1724 | } |
| 1725 | |
| 1726 | case Primitive::kPrimFloat: |
| 1727 | case Primitive::kPrimDouble: { |
| 1728 | int32_t entry_point_offset; |
| 1729 | if (in_type == Primitive::kPrimFloat) { |
| 1730 | entry_point_offset = instruction->IsGtBias() ? QUICK_ENTRY_POINT(pCmpgFloat) |
| 1731 | : QUICK_ENTRY_POINT(pCmplFloat); |
| 1732 | } else { |
| 1733 | entry_point_offset = instruction->IsGtBias() ? QUICK_ENTRY_POINT(pCmpgDouble) |
| 1734 | : QUICK_ENTRY_POINT(pCmplDouble); |
| 1735 | } |
| 1736 | codegen_->InvokeRuntime(entry_point_offset, instruction, instruction->GetDexPc(), nullptr); |
| 1737 | break; |
| 1738 | } |
| 1739 | |
| 1740 | default: |
| 1741 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | void LocationsBuilderMIPS64::VisitCondition(HCondition* instruction) { |
| 1746 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1747 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1748 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1749 | if (instruction->NeedsMaterialization()) { |
| 1750 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | void InstructionCodeGeneratorMIPS64::VisitCondition(HCondition* instruction) { |
| 1755 | if (!instruction->NeedsMaterialization()) { |
| 1756 | return; |
| 1757 | } |
| 1758 | |
| 1759 | LocationSummary* locations = instruction->GetLocations(); |
| 1760 | |
| 1761 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1762 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1763 | Location rhs_location = locations->InAt(1); |
| 1764 | |
| 1765 | GpuRegister rhs_reg = ZERO; |
| 1766 | int64_t rhs_imm = 0; |
| 1767 | bool use_imm = rhs_location.IsConstant(); |
| 1768 | if (use_imm) { |
| 1769 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 1770 | } else { |
| 1771 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1772 | } |
| 1773 | |
| 1774 | IfCondition if_cond = instruction->GetCondition(); |
| 1775 | |
| 1776 | switch (if_cond) { |
| 1777 | case kCondEQ: |
| 1778 | case kCondNE: |
| 1779 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 1780 | __ Xori(dst, lhs, rhs_imm); |
| 1781 | } else { |
| 1782 | if (use_imm) { |
| 1783 | rhs_reg = TMP; |
| 1784 | __ LoadConst32(rhs_reg, rhs_imm); |
| 1785 | } |
| 1786 | __ Xor(dst, lhs, rhs_reg); |
| 1787 | } |
| 1788 | if (if_cond == kCondEQ) { |
| 1789 | __ Sltiu(dst, dst, 1); |
| 1790 | } else { |
| 1791 | __ Sltu(dst, ZERO, dst); |
| 1792 | } |
| 1793 | break; |
| 1794 | |
| 1795 | case kCondLT: |
| 1796 | case kCondGE: |
| 1797 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 1798 | __ Slti(dst, lhs, rhs_imm); |
| 1799 | } else { |
| 1800 | if (use_imm) { |
| 1801 | rhs_reg = TMP; |
| 1802 | __ LoadConst32(rhs_reg, rhs_imm); |
| 1803 | } |
| 1804 | __ Slt(dst, lhs, rhs_reg); |
| 1805 | } |
| 1806 | if (if_cond == kCondGE) { |
| 1807 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 1808 | // only the slt instruction but no sge. |
| 1809 | __ Xori(dst, dst, 1); |
| 1810 | } |
| 1811 | break; |
| 1812 | |
| 1813 | case kCondLE: |
| 1814 | case kCondGT: |
| 1815 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 1816 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 1817 | __ Slti(dst, lhs, rhs_imm + 1); |
| 1818 | if (if_cond == kCondGT) { |
| 1819 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 1820 | // only the slti instruction but no sgti. |
| 1821 | __ Xori(dst, dst, 1); |
| 1822 | } |
| 1823 | } else { |
| 1824 | if (use_imm) { |
| 1825 | rhs_reg = TMP; |
| 1826 | __ LoadConst32(rhs_reg, rhs_imm); |
| 1827 | } |
| 1828 | __ Slt(dst, rhs_reg, lhs); |
| 1829 | if (if_cond == kCondLE) { |
| 1830 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 1831 | // only the slt instruction but no sle. |
| 1832 | __ Xori(dst, dst, 1); |
| 1833 | } |
| 1834 | } |
| 1835 | break; |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 1840 | LocationSummary* locations = |
| 1841 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1842 | switch (div->GetResultType()) { |
| 1843 | case Primitive::kPrimInt: |
| 1844 | case Primitive::kPrimLong: |
| 1845 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1846 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1847 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1848 | break; |
| 1849 | |
| 1850 | case Primitive::kPrimFloat: |
| 1851 | case Primitive::kPrimDouble: |
| 1852 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1853 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1854 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1855 | break; |
| 1856 | |
| 1857 | default: |
| 1858 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
| 1863 | Primitive::Type type = instruction->GetType(); |
| 1864 | LocationSummary* locations = instruction->GetLocations(); |
| 1865 | |
| 1866 | switch (type) { |
| 1867 | case Primitive::kPrimInt: |
| 1868 | case Primitive::kPrimLong: { |
| 1869 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1870 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1871 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1872 | if (type == Primitive::kPrimInt) |
| 1873 | __ DivR6(dst, lhs, rhs); |
| 1874 | else |
| 1875 | __ Ddiv(dst, lhs, rhs); |
| 1876 | break; |
| 1877 | } |
| 1878 | case Primitive::kPrimFloat: |
| 1879 | case Primitive::kPrimDouble: { |
| 1880 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1881 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1882 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1883 | if (type == Primitive::kPrimFloat) |
| 1884 | __ DivS(dst, lhs, rhs); |
| 1885 | else |
| 1886 | __ DivD(dst, lhs, rhs); |
| 1887 | break; |
| 1888 | } |
| 1889 | default: |
| 1890 | LOG(FATAL) << "Unexpected div type " << type; |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1895 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 1896 | ? LocationSummary::kCallOnSlowPath |
| 1897 | : LocationSummary::kNoCall; |
| 1898 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1899 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 1900 | if (instruction->HasUses()) { |
| 1901 | locations->SetOut(Location::SameAsFirstInput()); |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1906 | SlowPathCodeMIPS64* slow_path = |
| 1907 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction); |
| 1908 | codegen_->AddSlowPath(slow_path); |
| 1909 | Location value = instruction->GetLocations()->InAt(0); |
| 1910 | |
| 1911 | Primitive::Type type = instruction->GetType(); |
| 1912 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 1913 | if ((type == Primitive::kPrimBoolean) || !Primitive::IsIntegralType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1914 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 1915 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | if (value.IsConstant()) { |
| 1919 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 1920 | if (divisor == 0) { |
| 1921 | __ B(slow_path->GetEntryLabel()); |
| 1922 | } else { |
| 1923 | // A division by a non-null constant is valid. We don't need to perform |
| 1924 | // any check, so simply fall through. |
| 1925 | } |
| 1926 | } else { |
| 1927 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1932 | LocationSummary* locations = |
| 1933 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1934 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1935 | } |
| 1936 | |
| 1937 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 1938 | // Will be generated at use site. |
| 1939 | } |
| 1940 | |
| 1941 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 1942 | exit->SetLocations(nullptr); |
| 1943 | } |
| 1944 | |
| 1945 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 1946 | } |
| 1947 | |
| 1948 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 1949 | LocationSummary* locations = |
| 1950 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1951 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1952 | } |
| 1953 | |
| 1954 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 1955 | // Will be generated at use site. |
| 1956 | } |
| 1957 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1958 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1959 | DCHECK(!successor->IsExitBlock()); |
| 1960 | HBasicBlock* block = got->GetBlock(); |
| 1961 | HInstruction* previous = got->GetPrevious(); |
| 1962 | HLoopInformation* info = block->GetLoopInformation(); |
| 1963 | |
| 1964 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 1965 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1966 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1967 | return; |
| 1968 | } |
| 1969 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1970 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1971 | } |
| 1972 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 1973 | __ B(codegen_->GetLabelOf(successor)); |
| 1974 | } |
| 1975 | } |
| 1976 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1977 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 1978 | got->SetLocations(nullptr); |
| 1979 | } |
| 1980 | |
| 1981 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 1982 | HandleGoto(got, got->GetSuccessor()); |
| 1983 | } |
| 1984 | |
| 1985 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1986 | try_boundary->SetLocations(nullptr); |
| 1987 | } |
| 1988 | |
| 1989 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1990 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1991 | if (!successor->IsExitBlock()) { |
| 1992 | HandleGoto(try_boundary, successor); |
| 1993 | } |
| 1994 | } |
| 1995 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1996 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
| 1997 | Label* true_target, |
| 1998 | Label* false_target, |
| 1999 | Label* always_true_target) { |
| 2000 | HInstruction* cond = instruction->InputAt(0); |
| 2001 | HCondition* condition = cond->AsCondition(); |
| 2002 | |
| 2003 | if (cond->IsIntConstant()) { |
| 2004 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 2005 | if (cond_value == 1) { |
| 2006 | if (always_true_target != nullptr) { |
| 2007 | __ B(always_true_target); |
| 2008 | } |
| 2009 | return; |
| 2010 | } else { |
| 2011 | DCHECK_EQ(cond_value, 0); |
| 2012 | } |
| 2013 | } else if (!cond->IsCondition() || condition->NeedsMaterialization()) { |
| 2014 | // The condition instruction has been materialized, compare the output to 0. |
| 2015 | Location cond_val = instruction->GetLocations()->InAt(0); |
| 2016 | DCHECK(cond_val.IsRegister()); |
| 2017 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 2018 | } else { |
| 2019 | // The condition instruction has not been materialized, use its inputs as |
| 2020 | // the comparison and its condition as the branch condition. |
| 2021 | GpuRegister lhs = condition->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 2022 | Location rhs_location = condition->GetLocations()->InAt(1); |
| 2023 | GpuRegister rhs_reg = ZERO; |
| 2024 | int32_t rhs_imm = 0; |
| 2025 | bool use_imm = rhs_location.IsConstant(); |
| 2026 | if (use_imm) { |
| 2027 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2028 | } else { |
| 2029 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 2030 | } |
| 2031 | |
| 2032 | IfCondition if_cond = condition->GetCondition(); |
| 2033 | if (use_imm && rhs_imm == 0) { |
| 2034 | switch (if_cond) { |
| 2035 | case kCondEQ: |
| 2036 | __ Beqzc(lhs, true_target); |
| 2037 | break; |
| 2038 | case kCondNE: |
| 2039 | __ Bnezc(lhs, true_target); |
| 2040 | break; |
| 2041 | case kCondLT: |
| 2042 | __ Bltzc(lhs, true_target); |
| 2043 | break; |
| 2044 | case kCondGE: |
| 2045 | __ Bgezc(lhs, true_target); |
| 2046 | break; |
| 2047 | case kCondLE: |
| 2048 | __ Blezc(lhs, true_target); |
| 2049 | break; |
| 2050 | case kCondGT: |
| 2051 | __ Bgtzc(lhs, true_target); |
| 2052 | break; |
| 2053 | } |
| 2054 | } else { |
| 2055 | if (use_imm) { |
| 2056 | rhs_reg = TMP; |
| 2057 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2058 | } |
| 2059 | // It looks like we can get here with lhs == rhs. Should that be possible at all? |
| 2060 | // Mips R6 requires lhs != rhs for compact branches. |
| 2061 | if (lhs == rhs_reg) { |
| 2062 | DCHECK(!use_imm); |
| 2063 | switch (if_cond) { |
| 2064 | case kCondEQ: |
| 2065 | case kCondGE: |
| 2066 | case kCondLE: |
| 2067 | // if lhs == rhs for a positive condition, then it is a branch |
| 2068 | __ B(true_target); |
| 2069 | break; |
| 2070 | case kCondNE: |
| 2071 | case kCondLT: |
| 2072 | case kCondGT: |
| 2073 | // if lhs == rhs for a negative condition, then it is a NOP |
| 2074 | break; |
| 2075 | } |
| 2076 | } else { |
| 2077 | switch (if_cond) { |
| 2078 | case kCondEQ: |
| 2079 | __ Beqc(lhs, rhs_reg, true_target); |
| 2080 | break; |
| 2081 | case kCondNE: |
| 2082 | __ Bnec(lhs, rhs_reg, true_target); |
| 2083 | break; |
| 2084 | case kCondLT: |
| 2085 | __ Bltc(lhs, rhs_reg, true_target); |
| 2086 | break; |
| 2087 | case kCondGE: |
| 2088 | __ Bgec(lhs, rhs_reg, true_target); |
| 2089 | break; |
| 2090 | case kCondLE: |
| 2091 | __ Bgec(rhs_reg, lhs, true_target); |
| 2092 | break; |
| 2093 | case kCondGT: |
| 2094 | __ Bltc(rhs_reg, lhs, true_target); |
| 2095 | break; |
| 2096 | } |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | if (false_target != nullptr) { |
| 2101 | __ B(false_target); |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
| 2106 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2107 | HInstruction* cond = if_instr->InputAt(0); |
| 2108 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 2109 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
| 2114 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 2115 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 2116 | Label* always_true_target = true_target; |
| 2117 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 2118 | if_instr->IfTrueSuccessor())) { |
| 2119 | always_true_target = nullptr; |
| 2120 | } |
| 2121 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 2122 | if_instr->IfFalseSuccessor())) { |
| 2123 | false_target = nullptr; |
| 2124 | } |
| 2125 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 2126 | } |
| 2127 | |
| 2128 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2129 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2130 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 2131 | HInstruction* cond = deoptimize->InputAt(0); |
| 2132 | DCHECK(cond->IsCondition()); |
| 2133 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 2134 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2139 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) |
| 2140 | DeoptimizationSlowPathMIPS64(deoptimize); |
| 2141 | codegen_->AddSlowPath(slow_path); |
| 2142 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 2143 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 2144 | } |
| 2145 | |
| 2146 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
| 2147 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 2148 | LocationSummary* locations = |
| 2149 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2150 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2151 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2152 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2153 | } else { |
| 2154 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 2159 | const FieldInfo& field_info) { |
| 2160 | Primitive::Type type = field_info.GetFieldType(); |
| 2161 | LocationSummary* locations = instruction->GetLocations(); |
| 2162 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2163 | LoadOperandType load_type = kLoadUnsignedByte; |
| 2164 | switch (type) { |
| 2165 | case Primitive::kPrimBoolean: |
| 2166 | load_type = kLoadUnsignedByte; |
| 2167 | break; |
| 2168 | case Primitive::kPrimByte: |
| 2169 | load_type = kLoadSignedByte; |
| 2170 | break; |
| 2171 | case Primitive::kPrimShort: |
| 2172 | load_type = kLoadSignedHalfword; |
| 2173 | break; |
| 2174 | case Primitive::kPrimChar: |
| 2175 | load_type = kLoadUnsignedHalfword; |
| 2176 | break; |
| 2177 | case Primitive::kPrimInt: |
| 2178 | case Primitive::kPrimFloat: |
| 2179 | load_type = kLoadWord; |
| 2180 | break; |
| 2181 | case Primitive::kPrimLong: |
| 2182 | case Primitive::kPrimDouble: |
| 2183 | load_type = kLoadDoubleword; |
| 2184 | break; |
| 2185 | case Primitive::kPrimNot: |
| 2186 | load_type = kLoadUnsignedWord; |
| 2187 | break; |
| 2188 | case Primitive::kPrimVoid: |
| 2189 | LOG(FATAL) << "Unreachable type " << type; |
| 2190 | UNREACHABLE(); |
| 2191 | } |
| 2192 | if (!Primitive::IsFloatingPointType(type)) { |
| 2193 | DCHECK(locations->Out().IsRegister()); |
| 2194 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2195 | __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2196 | } else { |
| 2197 | DCHECK(locations->Out().IsFpuRegister()); |
| 2198 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 2199 | __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2200 | } |
| 2201 | |
| 2202 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2203 | // TODO: memory barrier? |
| 2204 | } |
| 2205 | |
| 2206 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 2207 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 2208 | LocationSummary* locations = |
| 2209 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2210 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2211 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 2212 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2213 | } else { |
| 2214 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
| 2219 | const FieldInfo& field_info) { |
| 2220 | Primitive::Type type = field_info.GetFieldType(); |
| 2221 | LocationSummary* locations = instruction->GetLocations(); |
| 2222 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2223 | StoreOperandType store_type = kStoreByte; |
| 2224 | switch (type) { |
| 2225 | case Primitive::kPrimBoolean: |
| 2226 | case Primitive::kPrimByte: |
| 2227 | store_type = kStoreByte; |
| 2228 | break; |
| 2229 | case Primitive::kPrimShort: |
| 2230 | case Primitive::kPrimChar: |
| 2231 | store_type = kStoreHalfword; |
| 2232 | break; |
| 2233 | case Primitive::kPrimInt: |
| 2234 | case Primitive::kPrimFloat: |
| 2235 | case Primitive::kPrimNot: |
| 2236 | store_type = kStoreWord; |
| 2237 | break; |
| 2238 | case Primitive::kPrimLong: |
| 2239 | case Primitive::kPrimDouble: |
| 2240 | store_type = kStoreDoubleword; |
| 2241 | break; |
| 2242 | case Primitive::kPrimVoid: |
| 2243 | LOG(FATAL) << "Unreachable type " << type; |
| 2244 | UNREACHABLE(); |
| 2245 | } |
| 2246 | if (!Primitive::IsFloatingPointType(type)) { |
| 2247 | DCHECK(locations->InAt(1).IsRegister()); |
| 2248 | GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2249 | __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2250 | } else { |
| 2251 | DCHECK(locations->InAt(1).IsFpuRegister()); |
| 2252 | FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2253 | __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2254 | } |
| 2255 | |
| 2256 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2257 | // TODO: memory barriers? |
| 2258 | if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) { |
| 2259 | DCHECK(locations->InAt(1).IsRegister()); |
| 2260 | GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2261 | codegen_->MarkGCCard(obj, src); |
| 2262 | } |
| 2263 | } |
| 2264 | |
| 2265 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2266 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2267 | } |
| 2268 | |
| 2269 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2270 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2271 | } |
| 2272 | |
| 2273 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2274 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2275 | } |
| 2276 | |
| 2277 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2278 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2279 | } |
| 2280 | |
| 2281 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
| 2282 | LocationSummary::CallKind call_kind = |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2283 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2284 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2285 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2286 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2287 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2288 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2289 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2290 | } |
| 2291 | |
| 2292 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
| 2293 | LocationSummary* locations = instruction->GetLocations(); |
| 2294 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2295 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2296 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2297 | |
| 2298 | Label done; |
| 2299 | |
| 2300 | // Return 0 if `obj` is null. |
| 2301 | // TODO: Avoid this check if we know `obj` is not null. |
| 2302 | __ Move(out, ZERO); |
| 2303 | __ Beqzc(obj, &done); |
| 2304 | |
| 2305 | // Compare the class of `obj` with `cls`. |
| 2306 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2307 | if (instruction->IsExactCheck()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2308 | // Classes must be equal for the instanceof to succeed. |
| 2309 | __ Xor(out, out, cls); |
| 2310 | __ Sltiu(out, out, 1); |
| 2311 | } else { |
| 2312 | // If the classes are not equal, we go into a slow path. |
| 2313 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2314 | SlowPathCodeMIPS64* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2315 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2316 | codegen_->AddSlowPath(slow_path); |
| 2317 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
| 2318 | __ LoadConst32(out, 1); |
| 2319 | __ Bind(slow_path->GetExitLabel()); |
| 2320 | } |
| 2321 | |
| 2322 | __ Bind(&done); |
| 2323 | } |
| 2324 | |
| 2325 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
| 2326 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2327 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2328 | } |
| 2329 | |
| 2330 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 2331 | // Will be generated at use site. |
| 2332 | } |
| 2333 | |
| 2334 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
| 2335 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2336 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2337 | } |
| 2338 | |
| 2339 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 2340 | // Will be generated at use site. |
| 2341 | } |
| 2342 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2343 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2344 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2345 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2346 | // the method_idx. |
| 2347 | HandleInvoke(invoke); |
| 2348 | } |
| 2349 | |
| 2350 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2351 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2352 | } |
| 2353 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2354 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 2355 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 2356 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2357 | } |
| 2358 | |
| 2359 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2360 | HandleInvoke(invoke); |
| 2361 | // The register T0 is required to be used for the hidden argument in |
| 2362 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 2363 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 2364 | } |
| 2365 | |
| 2366 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2367 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 2368 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
| 2369 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2370 | invoke->GetImtIndex() % mirror::Class::kImtSize, kMips64PointerSize).Uint32Value(); |
| 2371 | Location receiver = invoke->GetLocations()->InAt(0); |
| 2372 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2373 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize); |
| 2374 | |
| 2375 | // Set the hidden argument. |
| 2376 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 2377 | invoke->GetDexMethodIndex()); |
| 2378 | |
| 2379 | // temp = object->GetClass(); |
| 2380 | if (receiver.IsStackSlot()) { |
| 2381 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 2382 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 2383 | } else { |
| 2384 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 2385 | } |
| 2386 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 2387 | // temp = temp->GetImtEntryAt(method_offset); |
| 2388 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 2389 | // T9 = temp->GetEntryPoint(); |
| 2390 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 2391 | // T9(); |
| 2392 | __ Jalr(T9); |
| 2393 | DCHECK(!codegen_->IsLeafMethod()); |
| 2394 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2395 | } |
| 2396 | |
| 2397 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2398 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 2399 | if (intrinsic.TryDispatch(invoke)) { |
| 2400 | return; |
| 2401 | } |
| 2402 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2403 | HandleInvoke(invoke); |
| 2404 | } |
| 2405 | |
| 2406 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 2407 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2408 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2409 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
| 2410 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2411 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 2412 | if (intrinsic.TryDispatch(invoke)) { |
| 2413 | return; |
| 2414 | } |
| 2415 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2416 | HandleInvoke(invoke); |
| 2417 | |
| 2418 | // While SetupBlockedRegisters() blocks registers S2-S8 due to their |
| 2419 | // clobbering somewhere else, reduce further register pressure by avoiding |
| 2420 | // allocation of a register for the current method pointer like on x86 baseline. |
| 2421 | // TODO: remove this once all the issues with register saving/restoring are |
| 2422 | // sorted out. |
| 2423 | LocationSummary* locations = invoke->GetLocations(); |
| 2424 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 2425 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 2426 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 2427 | } |
| 2428 | } |
| 2429 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2430 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2431 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2432 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 2433 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2434 | return true; |
| 2435 | } |
| 2436 | return false; |
| 2437 | } |
| 2438 | |
| 2439 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 2440 | // All registers are assumed to be correctly set up per the calling convention. |
| 2441 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2442 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 2443 | switch (invoke->GetMethodLoadKind()) { |
| 2444 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 2445 | // temp = thread->string_init_entrypoint |
| 2446 | __ LoadFromOffset(kLoadDoubleword, |
| 2447 | temp.AsRegister<GpuRegister>(), |
| 2448 | TR, |
| 2449 | invoke->GetStringInitOffset()); |
| 2450 | break; |
| 2451 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 2452 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 2453 | break; |
| 2454 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 2455 | __ LoadConst64(temp.AsRegister<GpuRegister>(), invoke->GetMethodAddress()); |
| 2456 | break; |
| 2457 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 2458 | // TODO: Implement this type. (Needs literal support.) At the moment, the |
| 2459 | // CompilerDriver will not direct the backend to use this type for MIPS. |
| 2460 | LOG(FATAL) << "Unsupported!"; |
| 2461 | UNREACHABLE(); |
| 2462 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 2463 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 2464 | FALLTHROUGH_INTENDED; |
| 2465 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 2466 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 2467 | GpuRegister reg = temp.AsRegister<GpuRegister>(); |
| 2468 | GpuRegister method_reg; |
| 2469 | if (current_method.IsRegister()) { |
| 2470 | method_reg = current_method.AsRegister<GpuRegister>(); |
| 2471 | } else { |
| 2472 | // TODO: use the appropriate DCHECK() here if possible. |
| 2473 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 2474 | DCHECK(!current_method.IsValid()); |
| 2475 | method_reg = reg; |
| 2476 | __ Ld(reg, SP, kCurrentMethodStackOffset); |
| 2477 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2478 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2479 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2480 | __ LoadFromOffset(kLoadDoubleword, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2481 | reg, |
| 2482 | method_reg, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2483 | ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2484 | // temp = temp[index_in_cache] |
| 2485 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 2486 | __ LoadFromOffset(kLoadDoubleword, |
| 2487 | reg, |
| 2488 | reg, |
| 2489 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 2490 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2491 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2494 | switch (invoke->GetCodePtrLocation()) { |
| 2495 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 2496 | __ Jalr(&frame_entry_label_, T9); |
| 2497 | break; |
| 2498 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 2499 | // LR = invoke->GetDirectCodePtr(); |
| 2500 | __ LoadConst64(T9, invoke->GetDirectCodePtr()); |
| 2501 | // LR() |
| 2502 | __ Jalr(T9); |
| 2503 | break; |
| 2504 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 2505 | // TODO: Implement kCallPCRelative. For the moment, we fall back to kMethodCode. |
| 2506 | FALLTHROUGH_INTENDED; |
| 2507 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 2508 | // TODO: Implement kDirectCodeFixup. For the moment, we fall back to kMethodCode. |
| 2509 | FALLTHROUGH_INTENDED; |
| 2510 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 2511 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 2512 | __ LoadFromOffset(kLoadDoubleword, |
| 2513 | T9, |
| 2514 | callee_method.AsRegister<GpuRegister>(), |
| 2515 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 2516 | kMips64WordSize).Int32Value()); |
| 2517 | // T9() |
| 2518 | __ Jalr(T9); |
| 2519 | break; |
| 2520 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2521 | DCHECK(!IsLeafMethod()); |
| 2522 | } |
| 2523 | |
| 2524 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 2525 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2526 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2527 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
| 2528 | |
| 2529 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2530 | return; |
| 2531 | } |
| 2532 | |
| 2533 | LocationSummary* locations = invoke->GetLocations(); |
| 2534 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 2535 | locations->HasTemps() |
| 2536 | ? locations->GetTemp(0) |
| 2537 | : Location::NoLocation()); |
| 2538 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2539 | } |
| 2540 | |
| 2541 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2542 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2543 | return; |
| 2544 | } |
| 2545 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2546 | LocationSummary* locations = invoke->GetLocations(); |
| 2547 | Location receiver = locations->InAt(0); |
| 2548 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
| 2549 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 2550 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 2551 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2552 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize); |
| 2553 | |
| 2554 | // temp = object->GetClass(); |
| 2555 | DCHECK(receiver.IsRegister()); |
| 2556 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 2557 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 2558 | // temp = temp->GetMethodAt(method_offset); |
| 2559 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 2560 | // T9 = temp->GetEntryPoint(); |
| 2561 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 2562 | // T9(); |
| 2563 | __ Jalr(T9); |
| 2564 | DCHECK(!codegen_->IsLeafMethod()); |
| 2565 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2566 | } |
| 2567 | |
| 2568 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
| 2569 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath |
| 2570 | : LocationSummary::kNoCall; |
| 2571 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 2572 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2573 | locations->SetOut(Location::RequiresRegister()); |
| 2574 | } |
| 2575 | |
| 2576 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) { |
| 2577 | LocationSummary* locations = cls->GetLocations(); |
| 2578 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2579 | GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2580 | if (cls->IsReferrersClass()) { |
| 2581 | DCHECK(!cls->CanCallRuntime()); |
| 2582 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 2583 | __ LoadFromOffset(kLoadUnsignedWord, out, current_method, |
| 2584 | ArtMethod::DeclaringClassOffset().Int32Value()); |
| 2585 | } else { |
| 2586 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2587 | __ LoadFromOffset(kLoadDoubleword, out, current_method, |
| 2588 | ArtMethod::DexCacheResolvedTypesOffset(kMips64PointerSize).Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2589 | __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2590 | // TODO: We will need a read barrier here. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2591 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 2592 | cls, |
| 2593 | cls, |
| 2594 | cls->GetDexPc(), |
| 2595 | cls->MustGenerateClinitCheck()); |
| 2596 | codegen_->AddSlowPath(slow_path); |
| 2597 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 2598 | if (cls->MustGenerateClinitCheck()) { |
| 2599 | GenerateClassInitializationCheck(slow_path, out); |
| 2600 | } else { |
| 2601 | __ Bind(slow_path->GetExitLabel()); |
| 2602 | } |
| 2603 | } |
| 2604 | } |
| 2605 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 2606 | static int32_t GetExceptionTlsOffset() { |
| 2607 | return Thread::ExceptionOffset<kMips64WordSize>().Int32Value(); |
| 2608 | } |
| 2609 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2610 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 2611 | LocationSummary* locations = |
| 2612 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 2613 | locations->SetOut(Location::RequiresRegister()); |
| 2614 | } |
| 2615 | |
| 2616 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 2617 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 2618 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 2619 | } |
| 2620 | |
| 2621 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
| 2622 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 2623 | } |
| 2624 | |
| 2625 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 2626 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | void LocationsBuilderMIPS64::VisitLoadLocal(HLoadLocal* load) { |
| 2630 | load->SetLocations(nullptr); |
| 2631 | } |
| 2632 | |
| 2633 | void InstructionCodeGeneratorMIPS64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
| 2634 | // Nothing to do, this is driven by the code generator. |
| 2635 | } |
| 2636 | |
| 2637 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
| 2638 | LocationSummary* locations = |
| 2639 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 2640 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2641 | locations->SetOut(Location::RequiresRegister()); |
| 2642 | } |
| 2643 | |
| 2644 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) { |
| 2645 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load); |
| 2646 | codegen_->AddSlowPath(slow_path); |
| 2647 | |
| 2648 | LocationSummary* locations = load->GetLocations(); |
| 2649 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2650 | GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2651 | __ LoadFromOffset(kLoadUnsignedWord, out, current_method, |
| 2652 | ArtMethod::DeclaringClassOffset().Int32Value()); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2653 | __ LoadFromOffset(kLoadDoubleword, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2654 | __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2655 | // TODO: We will need a read barrier here. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2656 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 2657 | __ Bind(slow_path->GetExitLabel()); |
| 2658 | } |
| 2659 | |
| 2660 | void LocationsBuilderMIPS64::VisitLocal(HLocal* local) { |
| 2661 | local->SetLocations(nullptr); |
| 2662 | } |
| 2663 | |
| 2664 | void InstructionCodeGeneratorMIPS64::VisitLocal(HLocal* local) { |
| 2665 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 2666 | } |
| 2667 | |
| 2668 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
| 2669 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2670 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2671 | } |
| 2672 | |
| 2673 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 2674 | // Will be generated at use site. |
| 2675 | } |
| 2676 | |
| 2677 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 2678 | LocationSummary* locations = |
| 2679 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2680 | InvokeRuntimeCallingConvention calling_convention; |
| 2681 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2682 | } |
| 2683 | |
| 2684 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 2685 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 2686 | ? QUICK_ENTRY_POINT(pLockObject) |
| 2687 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 2688 | instruction, |
| 2689 | instruction->GetDexPc(), |
| 2690 | nullptr); |
| 2691 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 2692 | } |
| 2693 | |
| 2694 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 2695 | LocationSummary* locations = |
| 2696 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2697 | switch (mul->GetResultType()) { |
| 2698 | case Primitive::kPrimInt: |
| 2699 | case Primitive::kPrimLong: |
| 2700 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2701 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2702 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2703 | break; |
| 2704 | |
| 2705 | case Primitive::kPrimFloat: |
| 2706 | case Primitive::kPrimDouble: |
| 2707 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2708 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2709 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2710 | break; |
| 2711 | |
| 2712 | default: |
| 2713 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
| 2718 | Primitive::Type type = instruction->GetType(); |
| 2719 | LocationSummary* locations = instruction->GetLocations(); |
| 2720 | |
| 2721 | switch (type) { |
| 2722 | case Primitive::kPrimInt: |
| 2723 | case Primitive::kPrimLong: { |
| 2724 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2725 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2726 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2727 | if (type == Primitive::kPrimInt) |
| 2728 | __ MulR6(dst, lhs, rhs); |
| 2729 | else |
| 2730 | __ Dmul(dst, lhs, rhs); |
| 2731 | break; |
| 2732 | } |
| 2733 | case Primitive::kPrimFloat: |
| 2734 | case Primitive::kPrimDouble: { |
| 2735 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 2736 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2737 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2738 | if (type == Primitive::kPrimFloat) |
| 2739 | __ MulS(dst, lhs, rhs); |
| 2740 | else |
| 2741 | __ MulD(dst, lhs, rhs); |
| 2742 | break; |
| 2743 | } |
| 2744 | default: |
| 2745 | LOG(FATAL) << "Unexpected mul type " << type; |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 2750 | LocationSummary* locations = |
| 2751 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2752 | switch (neg->GetResultType()) { |
| 2753 | case Primitive::kPrimInt: |
| 2754 | case Primitive::kPrimLong: |
| 2755 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2756 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2757 | break; |
| 2758 | |
| 2759 | case Primitive::kPrimFloat: |
| 2760 | case Primitive::kPrimDouble: |
| 2761 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2762 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2763 | break; |
| 2764 | |
| 2765 | default: |
| 2766 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
| 2771 | Primitive::Type type = instruction->GetType(); |
| 2772 | LocationSummary* locations = instruction->GetLocations(); |
| 2773 | |
| 2774 | switch (type) { |
| 2775 | case Primitive::kPrimInt: |
| 2776 | case Primitive::kPrimLong: { |
| 2777 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2778 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2779 | if (type == Primitive::kPrimInt) |
| 2780 | __ Subu(dst, ZERO, src); |
| 2781 | else |
| 2782 | __ Dsubu(dst, ZERO, src); |
| 2783 | break; |
| 2784 | } |
| 2785 | case Primitive::kPrimFloat: |
| 2786 | case Primitive::kPrimDouble: { |
| 2787 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 2788 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2789 | if (type == Primitive::kPrimFloat) |
| 2790 | __ NegS(dst, src); |
| 2791 | else |
| 2792 | __ NegD(dst, src); |
| 2793 | break; |
| 2794 | } |
| 2795 | default: |
| 2796 | LOG(FATAL) << "Unexpected neg type " << type; |
| 2797 | } |
| 2798 | } |
| 2799 | |
| 2800 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
| 2801 | LocationSummary* locations = |
| 2802 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2803 | InvokeRuntimeCallingConvention calling_convention; |
| 2804 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2805 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 2806 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2807 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2808 | } |
| 2809 | |
| 2810 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
| 2811 | LocationSummary* locations = instruction->GetLocations(); |
| 2812 | // Move an uint16_t value to a register. |
| 2813 | __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex()); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2814 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 2815 | instruction, |
| 2816 | instruction->GetDexPc(), |
| 2817 | nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2818 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
| 2819 | } |
| 2820 | |
| 2821 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
| 2822 | LocationSummary* locations = |
| 2823 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2824 | InvokeRuntimeCallingConvention calling_convention; |
| 2825 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2826 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2827 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 2828 | } |
| 2829 | |
| 2830 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
| 2831 | LocationSummary* locations = instruction->GetLocations(); |
| 2832 | // Move an uint16_t value to a register. |
| 2833 | __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex()); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2834 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 2835 | instruction, |
| 2836 | instruction->GetDexPc(), |
| 2837 | nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2838 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 2839 | } |
| 2840 | |
| 2841 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
| 2842 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2843 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2844 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2845 | } |
| 2846 | |
| 2847 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
| 2848 | Primitive::Type type = instruction->GetType(); |
| 2849 | LocationSummary* locations = instruction->GetLocations(); |
| 2850 | |
| 2851 | switch (type) { |
| 2852 | case Primitive::kPrimInt: |
| 2853 | case Primitive::kPrimLong: { |
| 2854 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2855 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2856 | __ Nor(dst, src, ZERO); |
| 2857 | break; |
| 2858 | } |
| 2859 | |
| 2860 | default: |
| 2861 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 2866 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2867 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2868 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2869 | } |
| 2870 | |
| 2871 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 2872 | LocationSummary* locations = instruction->GetLocations(); |
| 2873 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 2874 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 2875 | 1); |
| 2876 | } |
| 2877 | |
| 2878 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2879 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2880 | ? LocationSummary::kCallOnSlowPath |
| 2881 | : LocationSummary::kNoCall; |
| 2882 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2883 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2884 | if (instruction->HasUses()) { |
| 2885 | locations->SetOut(Location::SameAsFirstInput()); |
| 2886 | } |
| 2887 | } |
| 2888 | |
| 2889 | void InstructionCodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 2890 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 2891 | return; |
| 2892 | } |
| 2893 | Location obj = instruction->GetLocations()->InAt(0); |
| 2894 | |
| 2895 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
| 2896 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2897 | } |
| 2898 | |
| 2899 | void InstructionCodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 2900 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction); |
| 2901 | codegen_->AddSlowPath(slow_path); |
| 2902 | |
| 2903 | Location obj = instruction->GetLocations()->InAt(0); |
| 2904 | |
| 2905 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 2906 | } |
| 2907 | |
| 2908 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2909 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2910 | GenerateImplicitNullCheck(instruction); |
| 2911 | } else { |
| 2912 | GenerateExplicitNullCheck(instruction); |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 2917 | HandleBinaryOp(instruction); |
| 2918 | } |
| 2919 | |
| 2920 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 2921 | HandleBinaryOp(instruction); |
| 2922 | } |
| 2923 | |
| 2924 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 2925 | LOG(FATAL) << "Unreachable"; |
| 2926 | } |
| 2927 | |
| 2928 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
| 2929 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2930 | } |
| 2931 | |
| 2932 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
| 2933 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2934 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2935 | if (location.IsStackSlot()) { |
| 2936 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2937 | } else if (location.IsDoubleStackSlot()) { |
| 2938 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2939 | } |
| 2940 | locations->SetOut(location); |
| 2941 | } |
| 2942 | |
| 2943 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 2944 | ATTRIBUTE_UNUSED) { |
| 2945 | // Nothing to do, the parameter is already at its location. |
| 2946 | } |
| 2947 | |
| 2948 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 2949 | LocationSummary* locations = |
| 2950 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2951 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 2952 | } |
| 2953 | |
| 2954 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 2955 | ATTRIBUTE_UNUSED) { |
| 2956 | // Nothing to do, the method is already at its location. |
| 2957 | } |
| 2958 | |
| 2959 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
| 2960 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2961 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 2962 | locations->SetInAt(i, Location::Any()); |
| 2963 | } |
| 2964 | locations->SetOut(Location::Any()); |
| 2965 | } |
| 2966 | |
| 2967 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 2968 | LOG(FATAL) << "Unreachable"; |
| 2969 | } |
| 2970 | |
| 2971 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
| 2972 | Primitive::Type type = rem->GetResultType(); |
| 2973 | LocationSummary::CallKind call_kind = |
| 2974 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall; |
| 2975 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2976 | |
| 2977 | switch (type) { |
| 2978 | case Primitive::kPrimInt: |
| 2979 | case Primitive::kPrimLong: |
| 2980 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2981 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2982 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2983 | break; |
| 2984 | |
| 2985 | case Primitive::kPrimFloat: |
| 2986 | case Primitive::kPrimDouble: { |
| 2987 | InvokeRuntimeCallingConvention calling_convention; |
| 2988 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 2989 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 2990 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 2991 | break; |
| 2992 | } |
| 2993 | |
| 2994 | default: |
| 2995 | LOG(FATAL) << "Unexpected rem type " << type; |
| 2996 | } |
| 2997 | } |
| 2998 | |
| 2999 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
| 3000 | Primitive::Type type = instruction->GetType(); |
| 3001 | LocationSummary* locations = instruction->GetLocations(); |
| 3002 | |
| 3003 | switch (type) { |
| 3004 | case Primitive::kPrimInt: |
| 3005 | case Primitive::kPrimLong: { |
| 3006 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3007 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3008 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 3009 | if (type == Primitive::kPrimInt) |
| 3010 | __ ModR6(dst, lhs, rhs); |
| 3011 | else |
| 3012 | __ Dmod(dst, lhs, rhs); |
| 3013 | break; |
| 3014 | } |
| 3015 | |
| 3016 | case Primitive::kPrimFloat: |
| 3017 | case Primitive::kPrimDouble: { |
| 3018 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) |
| 3019 | : QUICK_ENTRY_POINT(pFmod); |
| 3020 | codegen_->InvokeRuntime(entry_offset, instruction, instruction->GetDexPc(), nullptr); |
| 3021 | break; |
| 3022 | } |
| 3023 | default: |
| 3024 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3025 | } |
| 3026 | } |
| 3027 | |
| 3028 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3029 | memory_barrier->SetLocations(nullptr); |
| 3030 | } |
| 3031 | |
| 3032 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3033 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3034 | } |
| 3035 | |
| 3036 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
| 3037 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 3038 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 3039 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 3040 | } |
| 3041 | |
| 3042 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3043 | codegen_->GenerateFrameExit(); |
| 3044 | } |
| 3045 | |
| 3046 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 3047 | ret->SetLocations(nullptr); |
| 3048 | } |
| 3049 | |
| 3050 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3051 | codegen_->GenerateFrameExit(); |
| 3052 | } |
| 3053 | |
| 3054 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 3055 | HandleShift(shl); |
| 3056 | } |
| 3057 | |
| 3058 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 3059 | HandleShift(shl); |
| 3060 | } |
| 3061 | |
| 3062 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 3063 | HandleShift(shr); |
| 3064 | } |
| 3065 | |
| 3066 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 3067 | HandleShift(shr); |
| 3068 | } |
| 3069 | |
| 3070 | void LocationsBuilderMIPS64::VisitStoreLocal(HStoreLocal* store) { |
| 3071 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 3072 | Primitive::Type field_type = store->InputAt(1)->GetType(); |
| 3073 | switch (field_type) { |
| 3074 | case Primitive::kPrimNot: |
| 3075 | case Primitive::kPrimBoolean: |
| 3076 | case Primitive::kPrimByte: |
| 3077 | case Primitive::kPrimChar: |
| 3078 | case Primitive::kPrimShort: |
| 3079 | case Primitive::kPrimInt: |
| 3080 | case Primitive::kPrimFloat: |
| 3081 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 3082 | break; |
| 3083 | |
| 3084 | case Primitive::kPrimLong: |
| 3085 | case Primitive::kPrimDouble: |
| 3086 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 3087 | break; |
| 3088 | |
| 3089 | default: |
| 3090 | LOG(FATAL) << "Unimplemented local type " << field_type; |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | void InstructionCodeGeneratorMIPS64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
| 3095 | } |
| 3096 | |
| 3097 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 3098 | HandleBinaryOp(instruction); |
| 3099 | } |
| 3100 | |
| 3101 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 3102 | HandleBinaryOp(instruction); |
| 3103 | } |
| 3104 | |
| 3105 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3106 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3107 | } |
| 3108 | |
| 3109 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3110 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3111 | } |
| 3112 | |
| 3113 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3114 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3115 | } |
| 3116 | |
| 3117 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3118 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3119 | } |
| 3120 | |
| 3121 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3122 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 3123 | } |
| 3124 | |
| 3125 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3126 | HBasicBlock* block = instruction->GetBlock(); |
| 3127 | if (block->GetLoopInformation() != nullptr) { |
| 3128 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 3129 | // The back edge will generate the suspend check. |
| 3130 | return; |
| 3131 | } |
| 3132 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 3133 | // The goto will generate the suspend check. |
| 3134 | return; |
| 3135 | } |
| 3136 | GenerateSuspendCheck(instruction, nullptr); |
| 3137 | } |
| 3138 | |
| 3139 | void LocationsBuilderMIPS64::VisitTemporary(HTemporary* temp) { |
| 3140 | temp->SetLocations(nullptr); |
| 3141 | } |
| 3142 | |
| 3143 | void InstructionCodeGeneratorMIPS64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
| 3144 | // Nothing to do, this is driven by the code generator. |
| 3145 | } |
| 3146 | |
| 3147 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
| 3148 | LocationSummary* locations = |
| 3149 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3150 | InvokeRuntimeCallingConvention calling_convention; |
| 3151 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3152 | } |
| 3153 | |
| 3154 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
| 3155 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 3156 | instruction, |
| 3157 | instruction->GetDexPc(), |
| 3158 | nullptr); |
| 3159 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 3160 | } |
| 3161 | |
| 3162 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 3163 | Primitive::Type input_type = conversion->GetInputType(); |
| 3164 | Primitive::Type result_type = conversion->GetResultType(); |
| 3165 | DCHECK_NE(input_type, result_type); |
| 3166 | |
| 3167 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 3168 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 3169 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 3170 | } |
| 3171 | |
| 3172 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3173 | if ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) || |
| 3174 | (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type))) { |
| 3175 | call_kind = LocationSummary::kCall; |
| 3176 | } |
| 3177 | |
| 3178 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3179 | |
| 3180 | if (call_kind == LocationSummary::kNoCall) { |
| 3181 | if (Primitive::IsFloatingPointType(input_type)) { |
| 3182 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3183 | } else { |
| 3184 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3185 | } |
| 3186 | |
| 3187 | if (Primitive::IsFloatingPointType(result_type)) { |
| 3188 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3189 | } else { |
| 3190 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3191 | } |
| 3192 | } else { |
| 3193 | InvokeRuntimeCallingConvention calling_convention; |
| 3194 | |
| 3195 | if (Primitive::IsFloatingPointType(input_type)) { |
| 3196 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3197 | } else { |
| 3198 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3199 | } |
| 3200 | |
| 3201 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 3206 | LocationSummary* locations = conversion->GetLocations(); |
| 3207 | Primitive::Type result_type = conversion->GetResultType(); |
| 3208 | Primitive::Type input_type = conversion->GetInputType(); |
| 3209 | |
| 3210 | DCHECK_NE(input_type, result_type); |
| 3211 | |
| 3212 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 3213 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3214 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3215 | |
| 3216 | switch (result_type) { |
| 3217 | case Primitive::kPrimChar: |
| 3218 | __ Andi(dst, src, 0xFFFF); |
| 3219 | break; |
| 3220 | case Primitive::kPrimByte: |
| 3221 | // long is never converted into types narrower than int directly, |
| 3222 | // so SEB and SEH can be used without ever causing unpredictable results |
| 3223 | // on 64-bit inputs |
| 3224 | DCHECK(input_type != Primitive::kPrimLong); |
| 3225 | __ Seb(dst, src); |
| 3226 | break; |
| 3227 | case Primitive::kPrimShort: |
| 3228 | // long is never converted into types narrower than int directly, |
| 3229 | // so SEB and SEH can be used without ever causing unpredictable results |
| 3230 | // on 64-bit inputs |
| 3231 | DCHECK(input_type != Primitive::kPrimLong); |
| 3232 | __ Seh(dst, src); |
| 3233 | break; |
| 3234 | case Primitive::kPrimInt: |
| 3235 | case Primitive::kPrimLong: |
| 3236 | // Sign-extend 32-bit int into bits 32 through 63 for |
| 3237 | // int-to-long and long-to-int conversions |
| 3238 | __ Sll(dst, src, 0); |
| 3239 | break; |
| 3240 | |
| 3241 | default: |
| 3242 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3243 | << " to " << result_type; |
| 3244 | } |
| 3245 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 3246 | if (input_type != Primitive::kPrimLong) { |
| 3247 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3248 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3249 | __ Mtc1(src, FTMP); |
| 3250 | if (result_type == Primitive::kPrimFloat) { |
| 3251 | __ Cvtsw(dst, FTMP); |
| 3252 | } else { |
| 3253 | __ Cvtdw(dst, FTMP); |
| 3254 | } |
| 3255 | } else { |
| 3256 | int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f) |
| 3257 | : QUICK_ENTRY_POINT(pL2d); |
| 3258 | codegen_->InvokeRuntime(entry_offset, |
| 3259 | conversion, |
| 3260 | conversion->GetDexPc(), |
| 3261 | nullptr); |
| 3262 | } |
| 3263 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 3264 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 3265 | int32_t entry_offset; |
| 3266 | if (result_type != Primitive::kPrimLong) { |
| 3267 | entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2iz) |
| 3268 | : QUICK_ENTRY_POINT(pD2iz); |
| 3269 | } else { |
| 3270 | entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l) |
| 3271 | : QUICK_ENTRY_POINT(pD2l); |
| 3272 | } |
| 3273 | codegen_->InvokeRuntime(entry_offset, |
| 3274 | conversion, |
| 3275 | conversion->GetDexPc(), |
| 3276 | nullptr); |
| 3277 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 3278 | Primitive::IsFloatingPointType(input_type)) { |
| 3279 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3280 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3281 | if (result_type == Primitive::kPrimFloat) { |
| 3282 | __ Cvtsd(dst, src); |
| 3283 | } else { |
| 3284 | __ Cvtds(dst, src); |
| 3285 | } |
| 3286 | } else { |
| 3287 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 3288 | << " to " << result_type; |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 3293 | HandleShift(ushr); |
| 3294 | } |
| 3295 | |
| 3296 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 3297 | HandleShift(ushr); |
| 3298 | } |
| 3299 | |
| 3300 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 3301 | HandleBinaryOp(instruction); |
| 3302 | } |
| 3303 | |
| 3304 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 3305 | HandleBinaryOp(instruction); |
| 3306 | } |
| 3307 | |
| 3308 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 3309 | // Nothing to do, this should be removed during prepare for register allocator. |
| 3310 | LOG(FATAL) << "Unreachable"; |
| 3311 | } |
| 3312 | |
| 3313 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 3314 | // Nothing to do, this should be removed during prepare for register allocator. |
| 3315 | LOG(FATAL) << "Unreachable"; |
| 3316 | } |
| 3317 | |
| 3318 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
| 3319 | VisitCondition(comp); |
| 3320 | } |
| 3321 | |
| 3322 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
| 3323 | VisitCondition(comp); |
| 3324 | } |
| 3325 | |
| 3326 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
| 3327 | VisitCondition(comp); |
| 3328 | } |
| 3329 | |
| 3330 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
| 3331 | VisitCondition(comp); |
| 3332 | } |
| 3333 | |
| 3334 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
| 3335 | VisitCondition(comp); |
| 3336 | } |
| 3337 | |
| 3338 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
| 3339 | VisitCondition(comp); |
| 3340 | } |
| 3341 | |
| 3342 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3343 | VisitCondition(comp); |
| 3344 | } |
| 3345 | |
| 3346 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3347 | VisitCondition(comp); |
| 3348 | } |
| 3349 | |
| 3350 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
| 3351 | VisitCondition(comp); |
| 3352 | } |
| 3353 | |
| 3354 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
| 3355 | VisitCondition(comp); |
| 3356 | } |
| 3357 | |
| 3358 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3359 | VisitCondition(comp); |
| 3360 | } |
| 3361 | |
| 3362 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3363 | VisitCondition(comp); |
| 3364 | } |
| 3365 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3366 | void LocationsBuilderMIPS64::VisitFakeString(HFakeString* instruction) { |
| 3367 | DCHECK(codegen_->IsBaseline()); |
| 3368 | LocationSummary* locations = |
| 3369 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3370 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 3371 | } |
| 3372 | |
| 3373 | void InstructionCodeGeneratorMIPS64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 3374 | DCHECK(codegen_->IsBaseline()); |
| 3375 | // Will be generated at use site. |
| 3376 | } |
| 3377 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3378 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 3379 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 3380 | LocationSummary* locations = |
| 3381 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 3382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3383 | } |
| 3384 | |
| 3385 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 3386 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 3387 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 3388 | LocationSummary* locations = switch_instr->GetLocations(); |
| 3389 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3390 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 3391 | |
| 3392 | // Create a series of compare/jumps. |
| 3393 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 3394 | for (int32_t i = 0; i < num_entries; i++) { |
| 3395 | int32_t case_value = lower_bound + i; |
| 3396 | Label* succ = codegen_->GetLabelOf(successors.at(i)); |
| 3397 | if (case_value == 0) { |
| 3398 | __ Beqzc(value_reg, succ); |
| 3399 | } else { |
| 3400 | __ LoadConst32(TMP, case_value); |
| 3401 | __ Beqc(value_reg, TMP, succ); |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | // And the default for any other value. |
| 3406 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 3407 | __ B(codegen_->GetLabelOf(default_block)); |
| 3408 | } |
| 3409 | } |
| 3410 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3411 | } // namespace mips64 |
| 3412 | } // namespace art |