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