| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/arm64/frames-arm64.h" | |
| 6 #include "src/arm64/lithium-codegen-arm64.h" | |
| 7 #include "src/arm64/lithium-gap-resolver-arm64.h" | |
| 8 #include "src/base/bits.h" | |
| 9 #include "src/code-factory.h" | |
| 10 #include "src/code-stubs.h" | |
| 11 #include "src/hydrogen-osr.h" | |
| 12 #include "src/ic/ic.h" | |
| 13 #include "src/ic/stub-cache.h" | |
| 14 #include "src/profiler/cpu-profiler.h" | |
| 15 | |
| 16 namespace v8 { | |
| 17 namespace internal { | |
| 18 | |
| 19 | |
| 20 class SafepointGenerator final : public CallWrapper { | |
| 21 public: | |
| 22 SafepointGenerator(LCodeGen* codegen, | |
| 23 LPointerMap* pointers, | |
| 24 Safepoint::DeoptMode mode) | |
| 25 : codegen_(codegen), | |
| 26 pointers_(pointers), | |
| 27 deopt_mode_(mode) { } | |
| 28 virtual ~SafepointGenerator() { } | |
| 29 | |
| 30 virtual void BeforeCall(int call_size) const { } | |
| 31 | |
| 32 virtual void AfterCall() const { | |
| 33 codegen_->RecordSafepoint(pointers_, deopt_mode_); | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 LCodeGen* codegen_; | |
| 38 LPointerMap* pointers_; | |
| 39 Safepoint::DeoptMode deopt_mode_; | |
| 40 }; | |
| 41 | |
| 42 | |
| 43 #define __ masm()-> | |
| 44 | |
| 45 // Emit code to branch if the given condition holds. | |
| 46 // The code generated here doesn't modify the flags and they must have | |
| 47 // been set by some prior instructions. | |
| 48 // | |
| 49 // The EmitInverted function simply inverts the condition. | |
| 50 class BranchOnCondition : public BranchGenerator { | |
| 51 public: | |
| 52 BranchOnCondition(LCodeGen* codegen, Condition cond) | |
| 53 : BranchGenerator(codegen), | |
| 54 cond_(cond) { } | |
| 55 | |
| 56 virtual void Emit(Label* label) const { | |
| 57 __ B(cond_, label); | |
| 58 } | |
| 59 | |
| 60 virtual void EmitInverted(Label* label) const { | |
| 61 if (cond_ != al) { | |
| 62 __ B(NegateCondition(cond_), label); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 private: | |
| 67 Condition cond_; | |
| 68 }; | |
| 69 | |
| 70 | |
| 71 // Emit code to compare lhs and rhs and branch if the condition holds. | |
| 72 // This uses MacroAssembler's CompareAndBranch function so it will handle | |
| 73 // converting the comparison to Cbz/Cbnz if the right-hand side is 0. | |
| 74 // | |
| 75 // EmitInverted still compares the two operands but inverts the condition. | |
| 76 class CompareAndBranch : public BranchGenerator { | |
| 77 public: | |
| 78 CompareAndBranch(LCodeGen* codegen, | |
| 79 Condition cond, | |
| 80 const Register& lhs, | |
| 81 const Operand& rhs) | |
| 82 : BranchGenerator(codegen), | |
| 83 cond_(cond), | |
| 84 lhs_(lhs), | |
| 85 rhs_(rhs) { } | |
| 86 | |
| 87 virtual void Emit(Label* label) const { | |
| 88 __ CompareAndBranch(lhs_, rhs_, cond_, label); | |
| 89 } | |
| 90 | |
| 91 virtual void EmitInverted(Label* label) const { | |
| 92 __ CompareAndBranch(lhs_, rhs_, NegateCondition(cond_), label); | |
| 93 } | |
| 94 | |
| 95 private: | |
| 96 Condition cond_; | |
| 97 const Register& lhs_; | |
| 98 const Operand& rhs_; | |
| 99 }; | |
| 100 | |
| 101 | |
| 102 // Test the input with the given mask and branch if the condition holds. | |
| 103 // If the condition is 'eq' or 'ne' this will use MacroAssembler's | |
| 104 // TestAndBranchIfAllClear and TestAndBranchIfAnySet so it will handle the | |
| 105 // conversion to Tbz/Tbnz when possible. | |
| 106 class TestAndBranch : public BranchGenerator { | |
| 107 public: | |
| 108 TestAndBranch(LCodeGen* codegen, | |
| 109 Condition cond, | |
| 110 const Register& value, | |
| 111 uint64_t mask) | |
| 112 : BranchGenerator(codegen), | |
| 113 cond_(cond), | |
| 114 value_(value), | |
| 115 mask_(mask) { } | |
| 116 | |
| 117 virtual void Emit(Label* label) const { | |
| 118 switch (cond_) { | |
| 119 case eq: | |
| 120 __ TestAndBranchIfAllClear(value_, mask_, label); | |
| 121 break; | |
| 122 case ne: | |
| 123 __ TestAndBranchIfAnySet(value_, mask_, label); | |
| 124 break; | |
| 125 default: | |
| 126 __ Tst(value_, mask_); | |
| 127 __ B(cond_, label); | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 virtual void EmitInverted(Label* label) const { | |
| 132 // The inverse of "all clear" is "any set" and vice versa. | |
| 133 switch (cond_) { | |
| 134 case eq: | |
| 135 __ TestAndBranchIfAnySet(value_, mask_, label); | |
| 136 break; | |
| 137 case ne: | |
| 138 __ TestAndBranchIfAllClear(value_, mask_, label); | |
| 139 break; | |
| 140 default: | |
| 141 __ Tst(value_, mask_); | |
| 142 __ B(NegateCondition(cond_), label); | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 private: | |
| 147 Condition cond_; | |
| 148 const Register& value_; | |
| 149 uint64_t mask_; | |
| 150 }; | |
| 151 | |
| 152 | |
| 153 // Test the input and branch if it is non-zero and not a NaN. | |
| 154 class BranchIfNonZeroNumber : public BranchGenerator { | |
| 155 public: | |
| 156 BranchIfNonZeroNumber(LCodeGen* codegen, const FPRegister& value, | |
| 157 const FPRegister& scratch) | |
| 158 : BranchGenerator(codegen), value_(value), scratch_(scratch) { } | |
| 159 | |
| 160 virtual void Emit(Label* label) const { | |
| 161 __ Fabs(scratch_, value_); | |
| 162 // Compare with 0.0. Because scratch_ is positive, the result can be one of | |
| 163 // nZCv (equal), nzCv (greater) or nzCV (unordered). | |
| 164 __ Fcmp(scratch_, 0.0); | |
| 165 __ B(gt, label); | |
| 166 } | |
| 167 | |
| 168 virtual void EmitInverted(Label* label) const { | |
| 169 __ Fabs(scratch_, value_); | |
| 170 __ Fcmp(scratch_, 0.0); | |
| 171 __ B(le, label); | |
| 172 } | |
| 173 | |
| 174 private: | |
| 175 const FPRegister& value_; | |
| 176 const FPRegister& scratch_; | |
| 177 }; | |
| 178 | |
| 179 | |
| 180 // Test the input and branch if it is a heap number. | |
| 181 class BranchIfHeapNumber : public BranchGenerator { | |
| 182 public: | |
| 183 BranchIfHeapNumber(LCodeGen* codegen, const Register& value) | |
| 184 : BranchGenerator(codegen), value_(value) { } | |
| 185 | |
| 186 virtual void Emit(Label* label) const { | |
| 187 __ JumpIfHeapNumber(value_, label); | |
| 188 } | |
| 189 | |
| 190 virtual void EmitInverted(Label* label) const { | |
| 191 __ JumpIfNotHeapNumber(value_, label); | |
| 192 } | |
| 193 | |
| 194 private: | |
| 195 const Register& value_; | |
| 196 }; | |
| 197 | |
| 198 | |
| 199 // Test the input and branch if it is the specified root value. | |
| 200 class BranchIfRoot : public BranchGenerator { | |
| 201 public: | |
| 202 BranchIfRoot(LCodeGen* codegen, const Register& value, | |
| 203 Heap::RootListIndex index) | |
| 204 : BranchGenerator(codegen), value_(value), index_(index) { } | |
| 205 | |
| 206 virtual void Emit(Label* label) const { | |
| 207 __ JumpIfRoot(value_, index_, label); | |
| 208 } | |
| 209 | |
| 210 virtual void EmitInverted(Label* label) const { | |
| 211 __ JumpIfNotRoot(value_, index_, label); | |
| 212 } | |
| 213 | |
| 214 private: | |
| 215 const Register& value_; | |
| 216 const Heap::RootListIndex index_; | |
| 217 }; | |
| 218 | |
| 219 | |
| 220 void LCodeGen::WriteTranslation(LEnvironment* environment, | |
| 221 Translation* translation) { | |
| 222 if (environment == NULL) return; | |
| 223 | |
| 224 // The translation includes one command per value in the environment. | |
| 225 int translation_size = environment->translation_size(); | |
| 226 | |
| 227 WriteTranslation(environment->outer(), translation); | |
| 228 WriteTranslationFrame(environment, translation); | |
| 229 | |
| 230 int object_index = 0; | |
| 231 int dematerialized_index = 0; | |
| 232 for (int i = 0; i < translation_size; ++i) { | |
| 233 LOperand* value = environment->values()->at(i); | |
| 234 AddToTranslation( | |
| 235 environment, translation, value, environment->HasTaggedValueAt(i), | |
| 236 environment->HasUint32ValueAt(i), &object_index, &dematerialized_index); | |
| 237 } | |
| 238 } | |
| 239 | |
| 240 | |
| 241 void LCodeGen::AddToTranslation(LEnvironment* environment, | |
| 242 Translation* translation, | |
| 243 LOperand* op, | |
| 244 bool is_tagged, | |
| 245 bool is_uint32, | |
| 246 int* object_index_pointer, | |
| 247 int* dematerialized_index_pointer) { | |
| 248 if (op == LEnvironment::materialization_marker()) { | |
| 249 int object_index = (*object_index_pointer)++; | |
| 250 if (environment->ObjectIsDuplicateAt(object_index)) { | |
| 251 int dupe_of = environment->ObjectDuplicateOfAt(object_index); | |
| 252 translation->DuplicateObject(dupe_of); | |
| 253 return; | |
| 254 } | |
| 255 int object_length = environment->ObjectLengthAt(object_index); | |
| 256 if (environment->ObjectIsArgumentsAt(object_index)) { | |
| 257 translation->BeginArgumentsObject(object_length); | |
| 258 } else { | |
| 259 translation->BeginCapturedObject(object_length); | |
| 260 } | |
| 261 int dematerialized_index = *dematerialized_index_pointer; | |
| 262 int env_offset = environment->translation_size() + dematerialized_index; | |
| 263 *dematerialized_index_pointer += object_length; | |
| 264 for (int i = 0; i < object_length; ++i) { | |
| 265 LOperand* value = environment->values()->at(env_offset + i); | |
| 266 AddToTranslation(environment, | |
| 267 translation, | |
| 268 value, | |
| 269 environment->HasTaggedValueAt(env_offset + i), | |
| 270 environment->HasUint32ValueAt(env_offset + i), | |
| 271 object_index_pointer, | |
| 272 dematerialized_index_pointer); | |
| 273 } | |
| 274 return; | |
| 275 } | |
| 276 | |
| 277 if (op->IsStackSlot()) { | |
| 278 int index = op->index(); | |
| 279 if (index >= 0) { | |
| 280 index += StandardFrameConstants::kFixedFrameSize / kPointerSize; | |
| 281 } | |
| 282 if (is_tagged) { | |
| 283 translation->StoreStackSlot(index); | |
| 284 } else if (is_uint32) { | |
| 285 translation->StoreUint32StackSlot(index); | |
| 286 } else { | |
| 287 translation->StoreInt32StackSlot(index); | |
| 288 } | |
| 289 } else if (op->IsDoubleStackSlot()) { | |
| 290 int index = op->index(); | |
| 291 if (index >= 0) { | |
| 292 index += StandardFrameConstants::kFixedFrameSize / kPointerSize; | |
| 293 } | |
| 294 translation->StoreDoubleStackSlot(index); | |
| 295 } else if (op->IsRegister()) { | |
| 296 Register reg = ToRegister(op); | |
| 297 if (is_tagged) { | |
| 298 translation->StoreRegister(reg); | |
| 299 } else if (is_uint32) { | |
| 300 translation->StoreUint32Register(reg); | |
| 301 } else { | |
| 302 translation->StoreInt32Register(reg); | |
| 303 } | |
| 304 } else if (op->IsDoubleRegister()) { | |
| 305 DoubleRegister reg = ToDoubleRegister(op); | |
| 306 translation->StoreDoubleRegister(reg); | |
| 307 } else if (op->IsConstantOperand()) { | |
| 308 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); | |
| 309 int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); | |
| 310 translation->StoreLiteral(src_index); | |
| 311 } else { | |
| 312 UNREACHABLE(); | |
| 313 } | |
| 314 } | |
| 315 | |
| 316 | |
| 317 void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, | |
| 318 Safepoint::DeoptMode mode) { | |
| 319 environment->set_has_been_used(); | |
| 320 if (!environment->HasBeenRegistered()) { | |
| 321 int frame_count = 0; | |
| 322 int jsframe_count = 0; | |
| 323 for (LEnvironment* e = environment; e != NULL; e = e->outer()) { | |
| 324 ++frame_count; | |
| 325 if (e->frame_type() == JS_FUNCTION) { | |
| 326 ++jsframe_count; | |
| 327 } | |
| 328 } | |
| 329 Translation translation(&translations_, frame_count, jsframe_count, zone()); | |
| 330 WriteTranslation(environment, &translation); | |
| 331 int deoptimization_index = deoptimizations_.length(); | |
| 332 int pc_offset = masm()->pc_offset(); | |
| 333 environment->Register(deoptimization_index, | |
| 334 translation.index(), | |
| 335 (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); | |
| 336 deoptimizations_.Add(environment, zone()); | |
| 337 } | |
| 338 } | |
| 339 | |
| 340 | |
| 341 void LCodeGen::CallCode(Handle<Code> code, | |
| 342 RelocInfo::Mode mode, | |
| 343 LInstruction* instr) { | |
| 344 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); | |
| 345 } | |
| 346 | |
| 347 | |
| 348 void LCodeGen::CallCodeGeneric(Handle<Code> code, | |
| 349 RelocInfo::Mode mode, | |
| 350 LInstruction* instr, | |
| 351 SafepointMode safepoint_mode) { | |
| 352 DCHECK(instr != NULL); | |
| 353 | |
| 354 Assembler::BlockPoolsScope scope(masm_); | |
| 355 __ Call(code, mode); | |
| 356 RecordSafepointWithLazyDeopt(instr, safepoint_mode); | |
| 357 | |
| 358 if ((code->kind() == Code::BINARY_OP_IC) || | |
| 359 (code->kind() == Code::COMPARE_IC)) { | |
| 360 // Signal that we don't inline smi code before these stubs in the | |
| 361 // optimizing code generator. | |
| 362 InlineSmiCheckInfo::EmitNotInlined(masm()); | |
| 363 } | |
| 364 } | |
| 365 | |
| 366 | |
| 367 void LCodeGen::DoCallFunction(LCallFunction* instr) { | |
| 368 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 369 DCHECK(ToRegister(instr->function()).Is(x1)); | |
| 370 DCHECK(ToRegister(instr->result()).Is(x0)); | |
| 371 | |
| 372 int arity = instr->arity(); | |
| 373 CallFunctionFlags flags = instr->hydrogen()->function_flags(); | |
| 374 if (instr->hydrogen()->HasVectorAndSlot()) { | |
| 375 Register slot_register = ToRegister(instr->temp_slot()); | |
| 376 Register vector_register = ToRegister(instr->temp_vector()); | |
| 377 DCHECK(slot_register.is(x3)); | |
| 378 DCHECK(vector_register.is(x2)); | |
| 379 | |
| 380 AllowDeferredHandleDereference vector_structure_check; | |
| 381 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector(); | |
| 382 int index = vector->GetIndex(instr->hydrogen()->slot()); | |
| 383 | |
| 384 __ Mov(vector_register, vector); | |
| 385 __ Mov(slot_register, Operand(Smi::FromInt(index))); | |
| 386 | |
| 387 CallICState::CallType call_type = | |
| 388 (flags & CALL_AS_METHOD) ? CallICState::METHOD : CallICState::FUNCTION; | |
| 389 | |
| 390 Handle<Code> ic = | |
| 391 CodeFactory::CallICInOptimizedCode(isolate(), arity, call_type).code(); | |
| 392 CallCode(ic, RelocInfo::CODE_TARGET, instr); | |
| 393 } else { | |
| 394 CallFunctionStub stub(isolate(), arity, flags); | |
| 395 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | |
| 396 } | |
| 397 RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta()); | |
| 398 } | |
| 399 | |
| 400 | |
| 401 void LCodeGen::DoCallNew(LCallNew* instr) { | |
| 402 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 403 DCHECK(instr->IsMarkedAsCall()); | |
| 404 DCHECK(ToRegister(instr->constructor()).is(x1)); | |
| 405 | |
| 406 __ Mov(x0, instr->arity()); | |
| 407 // No cell in x2 for construct type feedback in optimized code. | |
| 408 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex); | |
| 409 | |
| 410 CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS); | |
| 411 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | |
| 412 RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta()); | |
| 413 | |
| 414 DCHECK(ToRegister(instr->result()).is(x0)); | |
| 415 } | |
| 416 | |
| 417 | |
| 418 void LCodeGen::DoCallNewArray(LCallNewArray* instr) { | |
| 419 DCHECK(instr->IsMarkedAsCall()); | |
| 420 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 421 DCHECK(ToRegister(instr->constructor()).is(x1)); | |
| 422 | |
| 423 __ Mov(x0, Operand(instr->arity())); | |
| 424 if (instr->arity() == 1) { | |
| 425 // We only need the allocation site for the case we have a length argument. | |
| 426 // The case may bail out to the runtime, which will determine the correct | |
| 427 // elements kind with the site. | |
| 428 __ Mov(x2, instr->hydrogen()->site()); | |
| 429 } else { | |
| 430 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex); | |
| 431 } | |
| 432 | |
| 433 | |
| 434 ElementsKind kind = instr->hydrogen()->elements_kind(); | |
| 435 AllocationSiteOverrideMode override_mode = | |
| 436 (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) | |
| 437 ? DISABLE_ALLOCATION_SITES | |
| 438 : DONT_OVERRIDE; | |
| 439 | |
| 440 if (instr->arity() == 0) { | |
| 441 ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode); | |
| 442 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | |
| 443 } else if (instr->arity() == 1) { | |
| 444 Label done; | |
| 445 if (IsFastPackedElementsKind(kind)) { | |
| 446 Label packed_case; | |
| 447 | |
| 448 // We might need to create a holey array; look at the first argument. | |
| 449 __ Peek(x10, 0); | |
| 450 __ Cbz(x10, &packed_case); | |
| 451 | |
| 452 ElementsKind holey_kind = GetHoleyElementsKind(kind); | |
| 453 ArraySingleArgumentConstructorStub stub(isolate(), | |
| 454 holey_kind, | |
| 455 override_mode); | |
| 456 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | |
| 457 __ B(&done); | |
| 458 __ Bind(&packed_case); | |
| 459 } | |
| 460 | |
| 461 ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode); | |
| 462 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | |
| 463 __ Bind(&done); | |
| 464 } else { | |
| 465 ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode); | |
| 466 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | |
| 467 } | |
| 468 RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta()); | |
| 469 | |
| 470 DCHECK(ToRegister(instr->result()).is(x0)); | |
| 471 } | |
| 472 | |
| 473 | |
| 474 void LCodeGen::CallRuntime(const Runtime::Function* function, | |
| 475 int num_arguments, | |
| 476 LInstruction* instr, | |
| 477 SaveFPRegsMode save_doubles) { | |
| 478 DCHECK(instr != NULL); | |
| 479 | |
| 480 __ CallRuntime(function, num_arguments, save_doubles); | |
| 481 | |
| 482 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); | |
| 483 } | |
| 484 | |
| 485 | |
| 486 void LCodeGen::LoadContextFromDeferred(LOperand* context) { | |
| 487 if (context->IsRegister()) { | |
| 488 __ Mov(cp, ToRegister(context)); | |
| 489 } else if (context->IsStackSlot()) { | |
| 490 __ Ldr(cp, ToMemOperand(context, kMustUseFramePointer)); | |
| 491 } else if (context->IsConstantOperand()) { | |
| 492 HConstant* constant = | |
| 493 chunk_->LookupConstant(LConstantOperand::cast(context)); | |
| 494 __ LoadHeapObject(cp, | |
| 495 Handle<HeapObject>::cast(constant->handle(isolate()))); | |
| 496 } else { | |
| 497 UNREACHABLE(); | |
| 498 } | |
| 499 } | |
| 500 | |
| 501 | |
| 502 void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, | |
| 503 int argc, | |
| 504 LInstruction* instr, | |
| 505 LOperand* context) { | |
| 506 LoadContextFromDeferred(context); | |
| 507 __ CallRuntimeSaveDoubles(id); | |
| 508 RecordSafepointWithRegisters( | |
| 509 instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); | |
| 510 } | |
| 511 | |
| 512 | |
| 513 void LCodeGen::RecordAndWritePosition(int position) { | |
| 514 if (position == RelocInfo::kNoPosition) return; | |
| 515 masm()->positions_recorder()->RecordPosition(position); | |
| 516 masm()->positions_recorder()->WriteRecordedPositions(); | |
| 517 } | |
| 518 | |
| 519 | |
| 520 void LCodeGen::RecordSafepointWithLazyDeopt(LInstruction* instr, | |
| 521 SafepointMode safepoint_mode) { | |
| 522 if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { | |
| 523 RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); | |
| 524 } else { | |
| 525 DCHECK(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); | |
| 526 RecordSafepointWithRegisters( | |
| 527 instr->pointer_map(), 0, Safepoint::kLazyDeopt); | |
| 528 } | |
| 529 } | |
| 530 | |
| 531 | |
| 532 void LCodeGen::RecordSafepoint(LPointerMap* pointers, | |
| 533 Safepoint::Kind kind, | |
| 534 int arguments, | |
| 535 Safepoint::DeoptMode deopt_mode) { | |
| 536 DCHECK(expected_safepoint_kind_ == kind); | |
| 537 | |
| 538 const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); | |
| 539 Safepoint safepoint = safepoints_.DefineSafepoint( | |
| 540 masm(), kind, arguments, deopt_mode); | |
| 541 | |
| 542 for (int i = 0; i < operands->length(); i++) { | |
| 543 LOperand* pointer = operands->at(i); | |
| 544 if (pointer->IsStackSlot()) { | |
| 545 safepoint.DefinePointerSlot(pointer->index(), zone()); | |
| 546 } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { | |
| 547 safepoint.DefinePointerRegister(ToRegister(pointer), zone()); | |
| 548 } | |
| 549 } | |
| 550 } | |
| 551 | |
| 552 void LCodeGen::RecordSafepoint(LPointerMap* pointers, | |
| 553 Safepoint::DeoptMode deopt_mode) { | |
| 554 RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); | |
| 555 } | |
| 556 | |
| 557 | |
| 558 void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { | |
| 559 LPointerMap empty_pointers(zone()); | |
| 560 RecordSafepoint(&empty_pointers, deopt_mode); | |
| 561 } | |
| 562 | |
| 563 | |
| 564 void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, | |
| 565 int arguments, | |
| 566 Safepoint::DeoptMode deopt_mode) { | |
| 567 RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, deopt_mode); | |
| 568 } | |
| 569 | |
| 570 | |
| 571 bool LCodeGen::GenerateCode() { | |
| 572 LPhase phase("Z_Code generation", chunk()); | |
| 573 DCHECK(is_unused()); | |
| 574 status_ = GENERATING; | |
| 575 | |
| 576 // Open a frame scope to indicate that there is a frame on the stack. The | |
| 577 // NONE indicates that the scope shouldn't actually generate code to set up | |
| 578 // the frame (that is done in GeneratePrologue). | |
| 579 FrameScope frame_scope(masm_, StackFrame::NONE); | |
| 580 | |
| 581 return GeneratePrologue() && GenerateBody() && GenerateDeferredCode() && | |
| 582 GenerateJumpTable() && GenerateSafepointTable(); | |
| 583 } | |
| 584 | |
| 585 | |
| 586 void LCodeGen::SaveCallerDoubles() { | |
| 587 DCHECK(info()->saves_caller_doubles()); | |
| 588 DCHECK(NeedsEagerFrame()); | |
| 589 Comment(";;; Save clobbered callee double registers"); | |
| 590 BitVector* doubles = chunk()->allocated_double_registers(); | |
| 591 BitVector::Iterator iterator(doubles); | |
| 592 int count = 0; | |
| 593 while (!iterator.Done()) { | |
| 594 // TODO(all): Is this supposed to save just the callee-saved doubles? It | |
| 595 // looks like it's saving all of them. | |
| 596 FPRegister value = FPRegister::from_code(iterator.Current()); | |
| 597 __ Poke(value, count * kDoubleSize); | |
| 598 iterator.Advance(); | |
| 599 count++; | |
| 600 } | |
| 601 } | |
| 602 | |
| 603 | |
| 604 void LCodeGen::RestoreCallerDoubles() { | |
| 605 DCHECK(info()->saves_caller_doubles()); | |
| 606 DCHECK(NeedsEagerFrame()); | |
| 607 Comment(";;; Restore clobbered callee double registers"); | |
| 608 BitVector* doubles = chunk()->allocated_double_registers(); | |
| 609 BitVector::Iterator iterator(doubles); | |
| 610 int count = 0; | |
| 611 while (!iterator.Done()) { | |
| 612 // TODO(all): Is this supposed to restore just the callee-saved doubles? It | |
| 613 // looks like it's restoring all of them. | |
| 614 FPRegister value = FPRegister::from_code(iterator.Current()); | |
| 615 __ Peek(value, count * kDoubleSize); | |
| 616 iterator.Advance(); | |
| 617 count++; | |
| 618 } | |
| 619 } | |
| 620 | |
| 621 | |
| 622 bool LCodeGen::GeneratePrologue() { | |
| 623 DCHECK(is_generating()); | |
| 624 | |
| 625 if (info()->IsOptimizing()) { | |
| 626 ProfileEntryHookStub::MaybeCallEntryHook(masm_); | |
| 627 | |
| 628 #ifdef DEBUG | |
| 629 if (strlen(FLAG_stop_at) > 0 && | |
| 630 info()->literal()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { | |
| 631 __ Debug("stop-at", __LINE__, BREAK); | |
| 632 } | |
| 633 #endif | |
| 634 | |
| 635 // Sloppy mode functions and builtins need to replace the receiver with the | |
| 636 // global proxy when called as functions (without an explicit receiver | |
| 637 // object). | |
| 638 if (info()->MustReplaceUndefinedReceiverWithGlobalProxy()) { | |
| 639 Label ok; | |
| 640 int receiver_offset = info_->scope()->num_parameters() * kXRegSize; | |
| 641 __ Peek(x10, receiver_offset); | |
| 642 __ JumpIfNotRoot(x10, Heap::kUndefinedValueRootIndex, &ok); | |
| 643 | |
| 644 __ Ldr(x10, GlobalObjectMemOperand()); | |
| 645 __ Ldr(x10, FieldMemOperand(x10, GlobalObject::kGlobalProxyOffset)); | |
| 646 __ Poke(x10, receiver_offset); | |
| 647 | |
| 648 __ Bind(&ok); | |
| 649 } | |
| 650 } | |
| 651 | |
| 652 DCHECK(__ StackPointer().Is(jssp)); | |
| 653 info()->set_prologue_offset(masm_->pc_offset()); | |
| 654 if (NeedsEagerFrame()) { | |
| 655 if (info()->IsStub()) { | |
| 656 __ StubPrologue(); | |
| 657 } else { | |
| 658 __ Prologue(info()->IsCodePreAgingActive()); | |
| 659 } | |
| 660 frame_is_built_ = true; | |
| 661 } | |
| 662 | |
| 663 // Reserve space for the stack slots needed by the code. | |
| 664 int slots = GetStackSlotCount(); | |
| 665 if (slots > 0) { | |
| 666 __ Claim(slots, kPointerSize); | |
| 667 } | |
| 668 | |
| 669 if (info()->saves_caller_doubles()) { | |
| 670 SaveCallerDoubles(); | |
| 671 } | |
| 672 return !is_aborted(); | |
| 673 } | |
| 674 | |
| 675 | |
| 676 void LCodeGen::DoPrologue(LPrologue* instr) { | |
| 677 Comment(";;; Prologue begin"); | |
| 678 | |
| 679 // Allocate a local context if needed. | |
| 680 if (info()->num_heap_slots() > 0) { | |
| 681 Comment(";;; Allocate local context"); | |
| 682 bool need_write_barrier = true; | |
| 683 // Argument to NewContext is the function, which is in x1. | |
| 684 int slots = info()->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | |
| 685 Safepoint::DeoptMode deopt_mode = Safepoint::kNoLazyDeopt; | |
| 686 if (info()->scope()->is_script_scope()) { | |
| 687 __ Mov(x10, Operand(info()->scope()->GetScopeInfo(info()->isolate()))); | |
| 688 __ Push(x1, x10); | |
| 689 __ CallRuntime(Runtime::kNewScriptContext, 2); | |
| 690 deopt_mode = Safepoint::kLazyDeopt; | |
| 691 } else if (slots <= FastNewContextStub::kMaximumSlots) { | |
| 692 FastNewContextStub stub(isolate(), slots); | |
| 693 __ CallStub(&stub); | |
| 694 // Result of FastNewContextStub is always in new space. | |
| 695 need_write_barrier = false; | |
| 696 } else { | |
| 697 __ Push(x1); | |
| 698 __ CallRuntime(Runtime::kNewFunctionContext, 1); | |
| 699 } | |
| 700 RecordSafepoint(deopt_mode); | |
| 701 // Context is returned in x0. It replaces the context passed to us. It's | |
| 702 // saved in the stack and kept live in cp. | |
| 703 __ Mov(cp, x0); | |
| 704 __ Str(x0, MemOperand(fp, StandardFrameConstants::kContextOffset)); | |
| 705 // Copy any necessary parameters into the context. | |
| 706 int num_parameters = scope()->num_parameters(); | |
| 707 int first_parameter = scope()->has_this_declaration() ? -1 : 0; | |
| 708 for (int i = first_parameter; i < num_parameters; i++) { | |
| 709 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i); | |
| 710 if (var->IsContextSlot()) { | |
| 711 Register value = x0; | |
| 712 Register scratch = x3; | |
| 713 | |
| 714 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | |
| 715 (num_parameters - 1 - i) * kPointerSize; | |
| 716 // Load parameter from stack. | |
| 717 __ Ldr(value, MemOperand(fp, parameter_offset)); | |
| 718 // Store it in the context. | |
| 719 MemOperand target = ContextMemOperand(cp, var->index()); | |
| 720 __ Str(value, target); | |
| 721 // Update the write barrier. This clobbers value and scratch. | |
| 722 if (need_write_barrier) { | |
| 723 __ RecordWriteContextSlot(cp, static_cast<int>(target.offset()), | |
| 724 value, scratch, GetLinkRegisterState(), | |
| 725 kSaveFPRegs); | |
| 726 } else if (FLAG_debug_code) { | |
| 727 Label done; | |
| 728 __ JumpIfInNewSpace(cp, &done); | |
| 729 __ Abort(kExpectedNewSpaceObject); | |
| 730 __ bind(&done); | |
| 731 } | |
| 732 } | |
| 733 } | |
| 734 Comment(";;; End allocate local context"); | |
| 735 } | |
| 736 | |
| 737 Comment(";;; Prologue end"); | |
| 738 } | |
| 739 | |
| 740 | |
| 741 void LCodeGen::GenerateOsrPrologue() { | |
| 742 // Generate the OSR entry prologue at the first unknown OSR value, or if there | |
| 743 // are none, at the OSR entrypoint instruction. | |
| 744 if (osr_pc_offset_ >= 0) return; | |
| 745 | |
| 746 osr_pc_offset_ = masm()->pc_offset(); | |
| 747 | |
| 748 // Adjust the frame size, subsuming the unoptimized frame into the | |
| 749 // optimized frame. | |
| 750 int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); | |
| 751 DCHECK(slots >= 0); | |
| 752 __ Claim(slots); | |
| 753 } | |
| 754 | |
| 755 | |
| 756 void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { | |
| 757 if (instr->IsCall()) { | |
| 758 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); | |
| 759 } | |
| 760 if (!instr->IsLazyBailout() && !instr->IsGap()) { | |
| 761 safepoints_.BumpLastLazySafepointIndex(); | |
| 762 } | |
| 763 } | |
| 764 | |
| 765 | |
| 766 bool LCodeGen::GenerateDeferredCode() { | |
| 767 DCHECK(is_generating()); | |
| 768 if (deferred_.length() > 0) { | |
| 769 for (int i = 0; !is_aborted() && (i < deferred_.length()); i++) { | |
| 770 LDeferredCode* code = deferred_[i]; | |
| 771 | |
| 772 HValue* value = | |
| 773 instructions_->at(code->instruction_index())->hydrogen_value(); | |
| 774 RecordAndWritePosition( | |
| 775 chunk()->graph()->SourcePositionToScriptPosition(value->position())); | |
| 776 | |
| 777 Comment(";;; <@%d,#%d> " | |
| 778 "-------------------- Deferred %s --------------------", | |
| 779 code->instruction_index(), | |
| 780 code->instr()->hydrogen_value()->id(), | |
| 781 code->instr()->Mnemonic()); | |
| 782 | |
| 783 __ Bind(code->entry()); | |
| 784 | |
| 785 if (NeedsDeferredFrame()) { | |
| 786 Comment(";;; Build frame"); | |
| 787 DCHECK(!frame_is_built_); | |
| 788 DCHECK(info()->IsStub()); | |
| 789 frame_is_built_ = true; | |
| 790 __ Push(lr, fp, cp); | |
| 791 __ Mov(fp, Smi::FromInt(StackFrame::STUB)); | |
| 792 __ Push(fp); | |
| 793 __ Add(fp, __ StackPointer(), | |
| 794 StandardFrameConstants::kFixedFrameSizeFromFp); | |
| 795 Comment(";;; Deferred code"); | |
| 796 } | |
| 797 | |
| 798 code->Generate(); | |
| 799 | |
| 800 if (NeedsDeferredFrame()) { | |
| 801 Comment(";;; Destroy frame"); | |
| 802 DCHECK(frame_is_built_); | |
| 803 __ Pop(xzr, cp, fp, lr); | |
| 804 frame_is_built_ = false; | |
| 805 } | |
| 806 | |
| 807 __ B(code->exit()); | |
| 808 } | |
| 809 } | |
| 810 | |
| 811 // Force constant pool emission at the end of the deferred code to make | |
| 812 // sure that no constant pools are emitted after deferred code because | |
| 813 // deferred code generation is the last step which generates code. The two | |
| 814 // following steps will only output data used by crakshaft. | |
| 815 masm()->CheckConstPool(true, false); | |
| 816 | |
| 817 return !is_aborted(); | |
| 818 } | |
| 819 | |
| 820 | |
| 821 bool LCodeGen::GenerateJumpTable() { | |
| 822 Label needs_frame, call_deopt_entry; | |
| 823 | |
| 824 if (jump_table_.length() > 0) { | |
| 825 Comment(";;; -------------------- Jump table --------------------"); | |
| 826 Address base = jump_table_[0]->address; | |
| 827 | |
| 828 UseScratchRegisterScope temps(masm()); | |
| 829 Register entry_offset = temps.AcquireX(); | |
| 830 | |
| 831 int length = jump_table_.length(); | |
| 832 for (int i = 0; i < length; i++) { | |
| 833 Deoptimizer::JumpTableEntry* table_entry = jump_table_[i]; | |
| 834 __ Bind(&table_entry->label); | |
| 835 | |
| 836 Address entry = table_entry->address; | |
| 837 DeoptComment(table_entry->deopt_info); | |
| 838 | |
| 839 // Second-level deopt table entries are contiguous and small, so instead | |
| 840 // of loading the full, absolute address of each one, load the base | |
| 841 // address and add an immediate offset. | |
| 842 __ Mov(entry_offset, entry - base); | |
| 843 | |
| 844 if (table_entry->needs_frame) { | |
| 845 DCHECK(!info()->saves_caller_doubles()); | |
| 846 Comment(";;; call deopt with frame"); | |
| 847 // Save lr before Bl, fp will be adjusted in the needs_frame code. | |
| 848 __ Push(lr, fp); | |
| 849 // Reuse the existing needs_frame code. | |
| 850 __ Bl(&needs_frame); | |
| 851 } else { | |
| 852 // There is nothing special to do, so just continue to the second-level | |
| 853 // table. | |
| 854 __ Bl(&call_deopt_entry); | |
| 855 } | |
| 856 info()->LogDeoptCallPosition(masm()->pc_offset(), | |
| 857 table_entry->deopt_info.inlining_id); | |
| 858 | |
| 859 masm()->CheckConstPool(false, false); | |
| 860 } | |
| 861 | |
| 862 if (needs_frame.is_linked()) { | |
| 863 // This variant of deopt can only be used with stubs. Since we don't | |
| 864 // have a function pointer to install in the stack frame that we're | |
| 865 // building, install a special marker there instead. | |
| 866 DCHECK(info()->IsStub()); | |
| 867 | |
| 868 Comment(";;; needs_frame common code"); | |
| 869 UseScratchRegisterScope temps(masm()); | |
| 870 Register stub_marker = temps.AcquireX(); | |
| 871 __ Bind(&needs_frame); | |
| 872 __ Mov(stub_marker, Smi::FromInt(StackFrame::STUB)); | |
| 873 __ Push(cp, stub_marker); | |
| 874 __ Add(fp, __ StackPointer(), 2 * kPointerSize); | |
| 875 } | |
| 876 | |
| 877 // Generate common code for calling the second-level deopt table. | |
| 878 __ Bind(&call_deopt_entry); | |
| 879 | |
| 880 if (info()->saves_caller_doubles()) { | |
| 881 DCHECK(info()->IsStub()); | |
| 882 RestoreCallerDoubles(); | |
| 883 } | |
| 884 | |
| 885 Register deopt_entry = temps.AcquireX(); | |
| 886 __ Mov(deopt_entry, Operand(reinterpret_cast<uint64_t>(base), | |
| 887 RelocInfo::RUNTIME_ENTRY)); | |
| 888 __ Add(deopt_entry, deopt_entry, entry_offset); | |
| 889 __ Br(deopt_entry); | |
| 890 } | |
| 891 | |
| 892 // Force constant pool emission at the end of the deopt jump table to make | |
| 893 // sure that no constant pools are emitted after. | |
| 894 masm()->CheckConstPool(true, false); | |
| 895 | |
| 896 // The deoptimization jump table is the last part of the instruction | |
| 897 // sequence. Mark the generated code as done unless we bailed out. | |
| 898 if (!is_aborted()) status_ = DONE; | |
| 899 return !is_aborted(); | |
| 900 } | |
| 901 | |
| 902 | |
| 903 bool LCodeGen::GenerateSafepointTable() { | |
| 904 DCHECK(is_done()); | |
| 905 // We do not know how much data will be emitted for the safepoint table, so | |
| 906 // force emission of the veneer pool. | |
| 907 masm()->CheckVeneerPool(true, true); | |
| 908 safepoints_.Emit(masm(), GetStackSlotCount()); | |
| 909 return !is_aborted(); | |
| 910 } | |
| 911 | |
| 912 | |
| 913 void LCodeGen::FinishCode(Handle<Code> code) { | |
| 914 DCHECK(is_done()); | |
| 915 code->set_stack_slots(GetStackSlotCount()); | |
| 916 code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); | |
| 917 PopulateDeoptimizationData(code); | |
| 918 } | |
| 919 | |
| 920 | |
| 921 void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { | |
| 922 int length = deoptimizations_.length(); | |
| 923 if (length == 0) return; | |
| 924 | |
| 925 Handle<DeoptimizationInputData> data = | |
| 926 DeoptimizationInputData::New(isolate(), length, TENURED); | |
| 927 | |
| 928 Handle<ByteArray> translations = | |
| 929 translations_.CreateByteArray(isolate()->factory()); | |
| 930 data->SetTranslationByteArray(*translations); | |
| 931 data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); | |
| 932 data->SetOptimizationId(Smi::FromInt(info_->optimization_id())); | |
| 933 if (info_->IsOptimizing()) { | |
| 934 // Reference to shared function info does not change between phases. | |
| 935 AllowDeferredHandleDereference allow_handle_dereference; | |
| 936 data->SetSharedFunctionInfo(*info_->shared_info()); | |
| 937 } else { | |
| 938 data->SetSharedFunctionInfo(Smi::FromInt(0)); | |
| 939 } | |
| 940 data->SetWeakCellCache(Smi::FromInt(0)); | |
| 941 | |
| 942 Handle<FixedArray> literals = | |
| 943 factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); | |
| 944 { AllowDeferredHandleDereference copy_handles; | |
| 945 for (int i = 0; i < deoptimization_literals_.length(); i++) { | |
| 946 literals->set(i, *deoptimization_literals_[i]); | |
| 947 } | |
| 948 data->SetLiteralArray(*literals); | |
| 949 } | |
| 950 | |
| 951 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); | |
| 952 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); | |
| 953 | |
| 954 // Populate the deoptimization entries. | |
| 955 for (int i = 0; i < length; i++) { | |
| 956 LEnvironment* env = deoptimizations_[i]; | |
| 957 data->SetAstId(i, env->ast_id()); | |
| 958 data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); | |
| 959 data->SetArgumentsStackHeight(i, | |
| 960 Smi::FromInt(env->arguments_stack_height())); | |
| 961 data->SetPc(i, Smi::FromInt(env->pc_offset())); | |
| 962 } | |
| 963 | |
| 964 code->set_deoptimization_data(*data); | |
| 965 } | |
| 966 | |
| 967 | |
| 968 void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { | |
| 969 DCHECK_EQ(0, deoptimization_literals_.length()); | |
| 970 for (auto function : chunk()->inlined_functions()) { | |
| 971 DefineDeoptimizationLiteral(function); | |
| 972 } | |
| 973 inlined_function_count_ = deoptimization_literals_.length(); | |
| 974 } | |
| 975 | |
| 976 | |
| 977 void LCodeGen::DeoptimizeBranch( | |
| 978 LInstruction* instr, Deoptimizer::DeoptReason deopt_reason, | |
| 979 BranchType branch_type, Register reg, int bit, | |
| 980 Deoptimizer::BailoutType* override_bailout_type) { | |
| 981 LEnvironment* environment = instr->environment(); | |
| 982 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | |
| 983 Deoptimizer::BailoutType bailout_type = | |
| 984 info()->IsStub() ? Deoptimizer::LAZY : Deoptimizer::EAGER; | |
| 985 | |
| 986 if (override_bailout_type != NULL) { | |
| 987 bailout_type = *override_bailout_type; | |
| 988 } | |
| 989 | |
| 990 DCHECK(environment->HasBeenRegistered()); | |
| 991 int id = environment->deoptimization_index(); | |
| 992 Address entry = | |
| 993 Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); | |
| 994 | |
| 995 if (entry == NULL) { | |
| 996 Abort(kBailoutWasNotPrepared); | |
| 997 } | |
| 998 | |
| 999 if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) { | |
| 1000 Label not_zero; | |
| 1001 ExternalReference count = ExternalReference::stress_deopt_count(isolate()); | |
| 1002 | |
| 1003 __ Push(x0, x1, x2); | |
| 1004 __ Mrs(x2, NZCV); | |
| 1005 __ Mov(x0, count); | |
| 1006 __ Ldr(w1, MemOperand(x0)); | |
| 1007 __ Subs(x1, x1, 1); | |
| 1008 __ B(gt, ¬_zero); | |
| 1009 __ Mov(w1, FLAG_deopt_every_n_times); | |
| 1010 __ Str(w1, MemOperand(x0)); | |
| 1011 __ Pop(x2, x1, x0); | |
| 1012 DCHECK(frame_is_built_); | |
| 1013 __ Call(entry, RelocInfo::RUNTIME_ENTRY); | |
| 1014 __ Unreachable(); | |
| 1015 | |
| 1016 __ Bind(¬_zero); | |
| 1017 __ Str(w1, MemOperand(x0)); | |
| 1018 __ Msr(NZCV, x2); | |
| 1019 __ Pop(x2, x1, x0); | |
| 1020 } | |
| 1021 | |
| 1022 if (info()->ShouldTrapOnDeopt()) { | |
| 1023 Label dont_trap; | |
| 1024 __ B(&dont_trap, InvertBranchType(branch_type), reg, bit); | |
| 1025 __ Debug("trap_on_deopt", __LINE__, BREAK); | |
| 1026 __ Bind(&dont_trap); | |
| 1027 } | |
| 1028 | |
| 1029 Deoptimizer::DeoptInfo deopt_info = MakeDeoptInfo(instr, deopt_reason); | |
| 1030 | |
| 1031 DCHECK(info()->IsStub() || frame_is_built_); | |
| 1032 // Go through jump table if we need to build frame, or restore caller doubles. | |
| 1033 if (branch_type == always && | |
| 1034 frame_is_built_ && !info()->saves_caller_doubles()) { | |
| 1035 DeoptComment(deopt_info); | |
| 1036 __ Call(entry, RelocInfo::RUNTIME_ENTRY); | |
| 1037 info()->LogDeoptCallPosition(masm()->pc_offset(), deopt_info.inlining_id); | |
| 1038 } else { | |
| 1039 Deoptimizer::JumpTableEntry* table_entry = | |
| 1040 new (zone()) Deoptimizer::JumpTableEntry( | |
| 1041 entry, deopt_info, bailout_type, !frame_is_built_); | |
| 1042 // We often have several deopts to the same entry, reuse the last | |
| 1043 // jump entry if this is the case. | |
| 1044 if (FLAG_trace_deopt || isolate()->cpu_profiler()->is_profiling() || | |
| 1045 jump_table_.is_empty() || | |
| 1046 !table_entry->IsEquivalentTo(*jump_table_.last())) { | |
| 1047 jump_table_.Add(table_entry, zone()); | |
| 1048 } | |
| 1049 __ B(&jump_table_.last()->label, branch_type, reg, bit); | |
| 1050 } | |
| 1051 } | |
| 1052 | |
| 1053 | |
| 1054 void LCodeGen::Deoptimize(LInstruction* instr, | |
| 1055 Deoptimizer::DeoptReason deopt_reason, | |
| 1056 Deoptimizer::BailoutType* override_bailout_type) { | |
| 1057 DeoptimizeBranch(instr, deopt_reason, always, NoReg, -1, | |
| 1058 override_bailout_type); | |
| 1059 } | |
| 1060 | |
| 1061 | |
| 1062 void LCodeGen::DeoptimizeIf(Condition cond, LInstruction* instr, | |
| 1063 Deoptimizer::DeoptReason deopt_reason) { | |
| 1064 DeoptimizeBranch(instr, deopt_reason, static_cast<BranchType>(cond)); | |
| 1065 } | |
| 1066 | |
| 1067 | |
| 1068 void LCodeGen::DeoptimizeIfZero(Register rt, LInstruction* instr, | |
| 1069 Deoptimizer::DeoptReason deopt_reason) { | |
| 1070 DeoptimizeBranch(instr, deopt_reason, reg_zero, rt); | |
| 1071 } | |
| 1072 | |
| 1073 | |
| 1074 void LCodeGen::DeoptimizeIfNotZero(Register rt, LInstruction* instr, | |
| 1075 Deoptimizer::DeoptReason deopt_reason) { | |
| 1076 DeoptimizeBranch(instr, deopt_reason, reg_not_zero, rt); | |
| 1077 } | |
| 1078 | |
| 1079 | |
| 1080 void LCodeGen::DeoptimizeIfNegative(Register rt, LInstruction* instr, | |
| 1081 Deoptimizer::DeoptReason deopt_reason) { | |
| 1082 int sign_bit = rt.Is64Bits() ? kXSignBit : kWSignBit; | |
| 1083 DeoptimizeIfBitSet(rt, sign_bit, instr, deopt_reason); | |
| 1084 } | |
| 1085 | |
| 1086 | |
| 1087 void LCodeGen::DeoptimizeIfSmi(Register rt, LInstruction* instr, | |
| 1088 Deoptimizer::DeoptReason deopt_reason) { | |
| 1089 DeoptimizeIfBitClear(rt, MaskToBit(kSmiTagMask), instr, deopt_reason); | |
| 1090 } | |
| 1091 | |
| 1092 | |
| 1093 void LCodeGen::DeoptimizeIfNotSmi(Register rt, LInstruction* instr, | |
| 1094 Deoptimizer::DeoptReason deopt_reason) { | |
| 1095 DeoptimizeIfBitSet(rt, MaskToBit(kSmiTagMask), instr, deopt_reason); | |
| 1096 } | |
| 1097 | |
| 1098 | |
| 1099 void LCodeGen::DeoptimizeIfRoot(Register rt, Heap::RootListIndex index, | |
| 1100 LInstruction* instr, | |
| 1101 Deoptimizer::DeoptReason deopt_reason) { | |
| 1102 __ CompareRoot(rt, index); | |
| 1103 DeoptimizeIf(eq, instr, deopt_reason); | |
| 1104 } | |
| 1105 | |
| 1106 | |
| 1107 void LCodeGen::DeoptimizeIfNotRoot(Register rt, Heap::RootListIndex index, | |
| 1108 LInstruction* instr, | |
| 1109 Deoptimizer::DeoptReason deopt_reason) { | |
| 1110 __ CompareRoot(rt, index); | |
| 1111 DeoptimizeIf(ne, instr, deopt_reason); | |
| 1112 } | |
| 1113 | |
| 1114 | |
| 1115 void LCodeGen::DeoptimizeIfMinusZero(DoubleRegister input, LInstruction* instr, | |
| 1116 Deoptimizer::DeoptReason deopt_reason) { | |
| 1117 __ TestForMinusZero(input); | |
| 1118 DeoptimizeIf(vs, instr, deopt_reason); | |
| 1119 } | |
| 1120 | |
| 1121 | |
| 1122 void LCodeGen::DeoptimizeIfNotHeapNumber(Register object, LInstruction* instr) { | |
| 1123 __ CompareObjectMap(object, Heap::kHeapNumberMapRootIndex); | |
| 1124 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber); | |
| 1125 } | |
| 1126 | |
| 1127 | |
| 1128 void LCodeGen::DeoptimizeIfBitSet(Register rt, int bit, LInstruction* instr, | |
| 1129 Deoptimizer::DeoptReason deopt_reason) { | |
| 1130 DeoptimizeBranch(instr, deopt_reason, reg_bit_set, rt, bit); | |
| 1131 } | |
| 1132 | |
| 1133 | |
| 1134 void LCodeGen::DeoptimizeIfBitClear(Register rt, int bit, LInstruction* instr, | |
| 1135 Deoptimizer::DeoptReason deopt_reason) { | |
| 1136 DeoptimizeBranch(instr, deopt_reason, reg_bit_clear, rt, bit); | |
| 1137 } | |
| 1138 | |
| 1139 | |
| 1140 void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { | |
| 1141 if (info()->ShouldEnsureSpaceForLazyDeopt()) { | |
| 1142 // Ensure that we have enough space after the previous lazy-bailout | |
| 1143 // instruction for patching the code here. | |
| 1144 intptr_t current_pc = masm()->pc_offset(); | |
| 1145 | |
| 1146 if (current_pc < (last_lazy_deopt_pc_ + space_needed)) { | |
| 1147 ptrdiff_t padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | |
| 1148 DCHECK((padding_size % kInstructionSize) == 0); | |
| 1149 InstructionAccurateScope instruction_accurate( | |
| 1150 masm(), padding_size / kInstructionSize); | |
| 1151 | |
| 1152 while (padding_size > 0) { | |
| 1153 __ nop(); | |
| 1154 padding_size -= kInstructionSize; | |
| 1155 } | |
| 1156 } | |
| 1157 } | |
| 1158 last_lazy_deopt_pc_ = masm()->pc_offset(); | |
| 1159 } | |
| 1160 | |
| 1161 | |
| 1162 Register LCodeGen::ToRegister(LOperand* op) const { | |
| 1163 // TODO(all): support zero register results, as ToRegister32. | |
| 1164 DCHECK((op != NULL) && op->IsRegister()); | |
| 1165 return Register::from_code(op->index()); | |
| 1166 } | |
| 1167 | |
| 1168 | |
| 1169 Register LCodeGen::ToRegister32(LOperand* op) const { | |
| 1170 DCHECK(op != NULL); | |
| 1171 if (op->IsConstantOperand()) { | |
| 1172 // If this is a constant operand, the result must be the zero register. | |
| 1173 DCHECK(ToInteger32(LConstantOperand::cast(op)) == 0); | |
| 1174 return wzr; | |
| 1175 } else { | |
| 1176 return ToRegister(op).W(); | |
| 1177 } | |
| 1178 } | |
| 1179 | |
| 1180 | |
| 1181 Smi* LCodeGen::ToSmi(LConstantOperand* op) const { | |
| 1182 HConstant* constant = chunk_->LookupConstant(op); | |
| 1183 return Smi::FromInt(constant->Integer32Value()); | |
| 1184 } | |
| 1185 | |
| 1186 | |
| 1187 DoubleRegister LCodeGen::ToDoubleRegister(LOperand* op) const { | |
| 1188 DCHECK((op != NULL) && op->IsDoubleRegister()); | |
| 1189 return DoubleRegister::from_code(op->index()); | |
| 1190 } | |
| 1191 | |
| 1192 | |
| 1193 Operand LCodeGen::ToOperand(LOperand* op) { | |
| 1194 DCHECK(op != NULL); | |
| 1195 if (op->IsConstantOperand()) { | |
| 1196 LConstantOperand* const_op = LConstantOperand::cast(op); | |
| 1197 HConstant* constant = chunk()->LookupConstant(const_op); | |
| 1198 Representation r = chunk_->LookupLiteralRepresentation(const_op); | |
| 1199 if (r.IsSmi()) { | |
| 1200 DCHECK(constant->HasSmiValue()); | |
| 1201 return Operand(Smi::FromInt(constant->Integer32Value())); | |
| 1202 } else if (r.IsInteger32()) { | |
| 1203 DCHECK(constant->HasInteger32Value()); | |
| 1204 return Operand(constant->Integer32Value()); | |
| 1205 } else if (r.IsDouble()) { | |
| 1206 Abort(kToOperandUnsupportedDoubleImmediate); | |
| 1207 } | |
| 1208 DCHECK(r.IsTagged()); | |
| 1209 return Operand(constant->handle(isolate())); | |
| 1210 } else if (op->IsRegister()) { | |
| 1211 return Operand(ToRegister(op)); | |
| 1212 } else if (op->IsDoubleRegister()) { | |
| 1213 Abort(kToOperandIsDoubleRegisterUnimplemented); | |
| 1214 return Operand(0); | |
| 1215 } | |
| 1216 // Stack slots not implemented, use ToMemOperand instead. | |
| 1217 UNREACHABLE(); | |
| 1218 return Operand(0); | |
| 1219 } | |
| 1220 | |
| 1221 | |
| 1222 Operand LCodeGen::ToOperand32(LOperand* op) { | |
| 1223 DCHECK(op != NULL); | |
| 1224 if (op->IsRegister()) { | |
| 1225 return Operand(ToRegister32(op)); | |
| 1226 } else if (op->IsConstantOperand()) { | |
| 1227 LConstantOperand* const_op = LConstantOperand::cast(op); | |
| 1228 HConstant* constant = chunk()->LookupConstant(const_op); | |
| 1229 Representation r = chunk_->LookupLiteralRepresentation(const_op); | |
| 1230 if (r.IsInteger32()) { | |
| 1231 return Operand(constant->Integer32Value()); | |
| 1232 } else { | |
| 1233 // Other constants not implemented. | |
| 1234 Abort(kToOperand32UnsupportedImmediate); | |
| 1235 } | |
| 1236 } | |
| 1237 // Other cases are not implemented. | |
| 1238 UNREACHABLE(); | |
| 1239 return Operand(0); | |
| 1240 } | |
| 1241 | |
| 1242 | |
| 1243 static int64_t ArgumentsOffsetWithoutFrame(int index) { | |
| 1244 DCHECK(index < 0); | |
| 1245 return -(index + 1) * kPointerSize; | |
| 1246 } | |
| 1247 | |
| 1248 | |
| 1249 MemOperand LCodeGen::ToMemOperand(LOperand* op, StackMode stack_mode) const { | |
| 1250 DCHECK(op != NULL); | |
| 1251 DCHECK(!op->IsRegister()); | |
| 1252 DCHECK(!op->IsDoubleRegister()); | |
| 1253 DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot()); | |
| 1254 if (NeedsEagerFrame()) { | |
| 1255 int fp_offset = StackSlotOffset(op->index()); | |
| 1256 // Loads and stores have a bigger reach in positive offset than negative. | |
| 1257 // We try to access using jssp (positive offset) first, then fall back to | |
| 1258 // fp (negative offset) if that fails. | |
| 1259 // | |
| 1260 // We can reference a stack slot from jssp only if we know how much we've | |
| 1261 // put on the stack. We don't know this in the following cases: | |
| 1262 // - stack_mode != kCanUseStackPointer: this is the case when deferred | |
| 1263 // code has saved the registers. | |
| 1264 // - saves_caller_doubles(): some double registers have been pushed, jssp | |
| 1265 // references the end of the double registers and not the end of the stack | |
| 1266 // slots. | |
| 1267 // In both of the cases above, we _could_ add the tracking information | |
| 1268 // required so that we can use jssp here, but in practice it isn't worth it. | |
| 1269 if ((stack_mode == kCanUseStackPointer) && | |
| 1270 !info()->saves_caller_doubles()) { | |
| 1271 int jssp_offset_to_fp = | |
| 1272 StandardFrameConstants::kFixedFrameSizeFromFp + | |
| 1273 (pushed_arguments_ + GetStackSlotCount()) * kPointerSize; | |
| 1274 int jssp_offset = fp_offset + jssp_offset_to_fp; | |
| 1275 if (masm()->IsImmLSScaled(jssp_offset, LSDoubleWord)) { | |
| 1276 return MemOperand(masm()->StackPointer(), jssp_offset); | |
| 1277 } | |
| 1278 } | |
| 1279 return MemOperand(fp, fp_offset); | |
| 1280 } else { | |
| 1281 // Retrieve parameter without eager stack-frame relative to the | |
| 1282 // stack-pointer. | |
| 1283 return MemOperand(masm()->StackPointer(), | |
| 1284 ArgumentsOffsetWithoutFrame(op->index())); | |
| 1285 } | |
| 1286 } | |
| 1287 | |
| 1288 | |
| 1289 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { | |
| 1290 HConstant* constant = chunk_->LookupConstant(op); | |
| 1291 DCHECK(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); | |
| 1292 return constant->handle(isolate()); | |
| 1293 } | |
| 1294 | |
| 1295 | |
| 1296 template <class LI> | |
| 1297 Operand LCodeGen::ToShiftedRightOperand32(LOperand* right, LI* shift_info) { | |
| 1298 if (shift_info->shift() == NO_SHIFT) { | |
| 1299 return ToOperand32(right); | |
| 1300 } else { | |
| 1301 return Operand( | |
| 1302 ToRegister32(right), | |
| 1303 shift_info->shift(), | |
| 1304 JSShiftAmountFromLConstant(shift_info->shift_amount())); | |
| 1305 } | |
| 1306 } | |
| 1307 | |
| 1308 | |
| 1309 bool LCodeGen::IsSmi(LConstantOperand* op) const { | |
| 1310 return chunk_->LookupLiteralRepresentation(op).IsSmi(); | |
| 1311 } | |
| 1312 | |
| 1313 | |
| 1314 bool LCodeGen::IsInteger32Constant(LConstantOperand* op) const { | |
| 1315 return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); | |
| 1316 } | |
| 1317 | |
| 1318 | |
| 1319 int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { | |
| 1320 HConstant* constant = chunk_->LookupConstant(op); | |
| 1321 return constant->Integer32Value(); | |
| 1322 } | |
| 1323 | |
| 1324 | |
| 1325 double LCodeGen::ToDouble(LConstantOperand* op) const { | |
| 1326 HConstant* constant = chunk_->LookupConstant(op); | |
| 1327 DCHECK(constant->HasDoubleValue()); | |
| 1328 return constant->DoubleValue(); | |
| 1329 } | |
| 1330 | |
| 1331 | |
| 1332 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { | |
| 1333 Condition cond = nv; | |
| 1334 switch (op) { | |
| 1335 case Token::EQ: | |
| 1336 case Token::EQ_STRICT: | |
| 1337 cond = eq; | |
| 1338 break; | |
| 1339 case Token::NE: | |
| 1340 case Token::NE_STRICT: | |
| 1341 cond = ne; | |
| 1342 break; | |
| 1343 case Token::LT: | |
| 1344 cond = is_unsigned ? lo : lt; | |
| 1345 break; | |
| 1346 case Token::GT: | |
| 1347 cond = is_unsigned ? hi : gt; | |
| 1348 break; | |
| 1349 case Token::LTE: | |
| 1350 cond = is_unsigned ? ls : le; | |
| 1351 break; | |
| 1352 case Token::GTE: | |
| 1353 cond = is_unsigned ? hs : ge; | |
| 1354 break; | |
| 1355 case Token::IN: | |
| 1356 case Token::INSTANCEOF: | |
| 1357 default: | |
| 1358 UNREACHABLE(); | |
| 1359 } | |
| 1360 return cond; | |
| 1361 } | |
| 1362 | |
| 1363 | |
| 1364 template<class InstrType> | |
| 1365 void LCodeGen::EmitBranchGeneric(InstrType instr, | |
| 1366 const BranchGenerator& branch) { | |
| 1367 int left_block = instr->TrueDestination(chunk_); | |
| 1368 int right_block = instr->FalseDestination(chunk_); | |
| 1369 | |
| 1370 int next_block = GetNextEmittedBlock(); | |
| 1371 | |
| 1372 if (right_block == left_block) { | |
| 1373 EmitGoto(left_block); | |
| 1374 } else if (left_block == next_block) { | |
| 1375 branch.EmitInverted(chunk_->GetAssemblyLabel(right_block)); | |
| 1376 } else { | |
| 1377 branch.Emit(chunk_->GetAssemblyLabel(left_block)); | |
| 1378 if (right_block != next_block) { | |
| 1379 __ B(chunk_->GetAssemblyLabel(right_block)); | |
| 1380 } | |
| 1381 } | |
| 1382 } | |
| 1383 | |
| 1384 | |
| 1385 template<class InstrType> | |
| 1386 void LCodeGen::EmitBranch(InstrType instr, Condition condition) { | |
| 1387 DCHECK((condition != al) && (condition != nv)); | |
| 1388 BranchOnCondition branch(this, condition); | |
| 1389 EmitBranchGeneric(instr, branch); | |
| 1390 } | |
| 1391 | |
| 1392 | |
| 1393 template<class InstrType> | |
| 1394 void LCodeGen::EmitCompareAndBranch(InstrType instr, | |
| 1395 Condition condition, | |
| 1396 const Register& lhs, | |
| 1397 const Operand& rhs) { | |
| 1398 DCHECK((condition != al) && (condition != nv)); | |
| 1399 CompareAndBranch branch(this, condition, lhs, rhs); | |
| 1400 EmitBranchGeneric(instr, branch); | |
| 1401 } | |
| 1402 | |
| 1403 | |
| 1404 template<class InstrType> | |
| 1405 void LCodeGen::EmitTestAndBranch(InstrType instr, | |
| 1406 Condition condition, | |
| 1407 const Register& value, | |
| 1408 uint64_t mask) { | |
| 1409 DCHECK((condition != al) && (condition != nv)); | |
| 1410 TestAndBranch branch(this, condition, value, mask); | |
| 1411 EmitBranchGeneric(instr, branch); | |
| 1412 } | |
| 1413 | |
| 1414 | |
| 1415 template<class InstrType> | |
| 1416 void LCodeGen::EmitBranchIfNonZeroNumber(InstrType instr, | |
| 1417 const FPRegister& value, | |
| 1418 const FPRegister& scratch) { | |
| 1419 BranchIfNonZeroNumber branch(this, value, scratch); | |
| 1420 EmitBranchGeneric(instr, branch); | |
| 1421 } | |
| 1422 | |
| 1423 | |
| 1424 template<class InstrType> | |
| 1425 void LCodeGen::EmitBranchIfHeapNumber(InstrType instr, | |
| 1426 const Register& value) { | |
| 1427 BranchIfHeapNumber branch(this, value); | |
| 1428 EmitBranchGeneric(instr, branch); | |
| 1429 } | |
| 1430 | |
| 1431 | |
| 1432 template<class InstrType> | |
| 1433 void LCodeGen::EmitBranchIfRoot(InstrType instr, | |
| 1434 const Register& value, | |
| 1435 Heap::RootListIndex index) { | |
| 1436 BranchIfRoot branch(this, value, index); | |
| 1437 EmitBranchGeneric(instr, branch); | |
| 1438 } | |
| 1439 | |
| 1440 | |
| 1441 void LCodeGen::DoGap(LGap* gap) { | |
| 1442 for (int i = LGap::FIRST_INNER_POSITION; | |
| 1443 i <= LGap::LAST_INNER_POSITION; | |
| 1444 i++) { | |
| 1445 LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); | |
| 1446 LParallelMove* move = gap->GetParallelMove(inner_pos); | |
| 1447 if (move != NULL) { | |
| 1448 resolver_.Resolve(move); | |
| 1449 } | |
| 1450 } | |
| 1451 } | |
| 1452 | |
| 1453 | |
| 1454 void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { | |
| 1455 Register arguments = ToRegister(instr->arguments()); | |
| 1456 Register result = ToRegister(instr->result()); | |
| 1457 | |
| 1458 // The pointer to the arguments array come from DoArgumentsElements. | |
| 1459 // It does not point directly to the arguments and there is an offest of | |
| 1460 // two words that we must take into account when accessing an argument. | |
| 1461 // Subtracting the index from length accounts for one, so we add one more. | |
| 1462 | |
| 1463 if (instr->length()->IsConstantOperand() && | |
| 1464 instr->index()->IsConstantOperand()) { | |
| 1465 int index = ToInteger32(LConstantOperand::cast(instr->index())); | |
| 1466 int length = ToInteger32(LConstantOperand::cast(instr->length())); | |
| 1467 int offset = ((length - index) + 1) * kPointerSize; | |
| 1468 __ Ldr(result, MemOperand(arguments, offset)); | |
| 1469 } else if (instr->index()->IsConstantOperand()) { | |
| 1470 Register length = ToRegister32(instr->length()); | |
| 1471 int index = ToInteger32(LConstantOperand::cast(instr->index())); | |
| 1472 int loc = index - 1; | |
| 1473 if (loc != 0) { | |
| 1474 __ Sub(result.W(), length, loc); | |
| 1475 __ Ldr(result, MemOperand(arguments, result, UXTW, kPointerSizeLog2)); | |
| 1476 } else { | |
| 1477 __ Ldr(result, MemOperand(arguments, length, UXTW, kPointerSizeLog2)); | |
| 1478 } | |
| 1479 } else { | |
| 1480 Register length = ToRegister32(instr->length()); | |
| 1481 Operand index = ToOperand32(instr->index()); | |
| 1482 __ Sub(result.W(), length, index); | |
| 1483 __ Add(result.W(), result.W(), 1); | |
| 1484 __ Ldr(result, MemOperand(arguments, result, UXTW, kPointerSizeLog2)); | |
| 1485 } | |
| 1486 } | |
| 1487 | |
| 1488 | |
| 1489 void LCodeGen::DoAddE(LAddE* instr) { | |
| 1490 Register result = ToRegister(instr->result()); | |
| 1491 Register left = ToRegister(instr->left()); | |
| 1492 Operand right = Operand(x0); // Dummy initialization. | |
| 1493 if (instr->hydrogen()->external_add_type() == AddOfExternalAndTagged) { | |
| 1494 right = Operand(ToRegister(instr->right())); | |
| 1495 } else if (instr->right()->IsConstantOperand()) { | |
| 1496 right = ToInteger32(LConstantOperand::cast(instr->right())); | |
| 1497 } else { | |
| 1498 right = Operand(ToRegister32(instr->right()), SXTW); | |
| 1499 } | |
| 1500 | |
| 1501 DCHECK(!instr->hydrogen()->CheckFlag(HValue::kCanOverflow)); | |
| 1502 __ Add(result, left, right); | |
| 1503 } | |
| 1504 | |
| 1505 | |
| 1506 void LCodeGen::DoAddI(LAddI* instr) { | |
| 1507 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | |
| 1508 Register result = ToRegister32(instr->result()); | |
| 1509 Register left = ToRegister32(instr->left()); | |
| 1510 Operand right = ToShiftedRightOperand32(instr->right(), instr); | |
| 1511 | |
| 1512 if (can_overflow) { | |
| 1513 __ Adds(result, left, right); | |
| 1514 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 1515 } else { | |
| 1516 __ Add(result, left, right); | |
| 1517 } | |
| 1518 } | |
| 1519 | |
| 1520 | |
| 1521 void LCodeGen::DoAddS(LAddS* instr) { | |
| 1522 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | |
| 1523 Register result = ToRegister(instr->result()); | |
| 1524 Register left = ToRegister(instr->left()); | |
| 1525 Operand right = ToOperand(instr->right()); | |
| 1526 if (can_overflow) { | |
| 1527 __ Adds(result, left, right); | |
| 1528 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 1529 } else { | |
| 1530 __ Add(result, left, right); | |
| 1531 } | |
| 1532 } | |
| 1533 | |
| 1534 | |
| 1535 void LCodeGen::DoAllocate(LAllocate* instr) { | |
| 1536 class DeferredAllocate: public LDeferredCode { | |
| 1537 public: | |
| 1538 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) | |
| 1539 : LDeferredCode(codegen), instr_(instr) { } | |
| 1540 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } | |
| 1541 virtual LInstruction* instr() { return instr_; } | |
| 1542 private: | |
| 1543 LAllocate* instr_; | |
| 1544 }; | |
| 1545 | |
| 1546 DeferredAllocate* deferred = new(zone()) DeferredAllocate(this, instr); | |
| 1547 | |
| 1548 Register result = ToRegister(instr->result()); | |
| 1549 Register temp1 = ToRegister(instr->temp1()); | |
| 1550 Register temp2 = ToRegister(instr->temp2()); | |
| 1551 | |
| 1552 // Allocate memory for the object. | |
| 1553 AllocationFlags flags = TAG_OBJECT; | |
| 1554 if (instr->hydrogen()->MustAllocateDoubleAligned()) { | |
| 1555 flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); | |
| 1556 } | |
| 1557 | |
| 1558 if (instr->hydrogen()->IsOldSpaceAllocation()) { | |
| 1559 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); | |
| 1560 flags = static_cast<AllocationFlags>(flags | PRETENURE); | |
| 1561 } | |
| 1562 | |
| 1563 if (instr->size()->IsConstantOperand()) { | |
| 1564 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); | |
| 1565 CHECK(size <= Page::kMaxRegularHeapObjectSize); | |
| 1566 __ Allocate(size, result, temp1, temp2, deferred->entry(), flags); | |
| 1567 } else { | |
| 1568 Register size = ToRegister32(instr->size()); | |
| 1569 __ Sxtw(size.X(), size); | |
| 1570 __ Allocate(size.X(), result, temp1, temp2, deferred->entry(), flags); | |
| 1571 } | |
| 1572 | |
| 1573 __ Bind(deferred->exit()); | |
| 1574 | |
| 1575 if (instr->hydrogen()->MustPrefillWithFiller()) { | |
| 1576 Register filler_count = temp1; | |
| 1577 Register filler = temp2; | |
| 1578 Register untagged_result = ToRegister(instr->temp3()); | |
| 1579 | |
| 1580 if (instr->size()->IsConstantOperand()) { | |
| 1581 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); | |
| 1582 __ Mov(filler_count, size / kPointerSize); | |
| 1583 } else { | |
| 1584 __ Lsr(filler_count.W(), ToRegister32(instr->size()), kPointerSizeLog2); | |
| 1585 } | |
| 1586 | |
| 1587 __ Sub(untagged_result, result, kHeapObjectTag); | |
| 1588 __ Mov(filler, Operand(isolate()->factory()->one_pointer_filler_map())); | |
| 1589 __ FillFields(untagged_result, filler_count, filler); | |
| 1590 } else { | |
| 1591 DCHECK(instr->temp3() == NULL); | |
| 1592 } | |
| 1593 } | |
| 1594 | |
| 1595 | |
| 1596 void LCodeGen::DoDeferredAllocate(LAllocate* instr) { | |
| 1597 // TODO(3095996): Get rid of this. For now, we need to make the | |
| 1598 // result register contain a valid pointer because it is already | |
| 1599 // contained in the register pointer map. | |
| 1600 __ Mov(ToRegister(instr->result()), Smi::FromInt(0)); | |
| 1601 | |
| 1602 PushSafepointRegistersScope scope(this); | |
| 1603 // We're in a SafepointRegistersScope so we can use any scratch registers. | |
| 1604 Register size = x0; | |
| 1605 if (instr->size()->IsConstantOperand()) { | |
| 1606 __ Mov(size, ToSmi(LConstantOperand::cast(instr->size()))); | |
| 1607 } else { | |
| 1608 __ SmiTag(size, ToRegister32(instr->size()).X()); | |
| 1609 } | |
| 1610 int flags = AllocateDoubleAlignFlag::encode( | |
| 1611 instr->hydrogen()->MustAllocateDoubleAligned()); | |
| 1612 if (instr->hydrogen()->IsOldSpaceAllocation()) { | |
| 1613 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); | |
| 1614 flags = AllocateTargetSpace::update(flags, OLD_SPACE); | |
| 1615 } else { | |
| 1616 flags = AllocateTargetSpace::update(flags, NEW_SPACE); | |
| 1617 } | |
| 1618 __ Mov(x10, Smi::FromInt(flags)); | |
| 1619 __ Push(size, x10); | |
| 1620 | |
| 1621 CallRuntimeFromDeferred( | |
| 1622 Runtime::kAllocateInTargetSpace, 2, instr, instr->context()); | |
| 1623 __ StoreToSafepointRegisterSlot(x0, ToRegister(instr->result())); | |
| 1624 } | |
| 1625 | |
| 1626 | |
| 1627 void LCodeGen::DoApplyArguments(LApplyArguments* instr) { | |
| 1628 Register receiver = ToRegister(instr->receiver()); | |
| 1629 Register function = ToRegister(instr->function()); | |
| 1630 Register length = ToRegister32(instr->length()); | |
| 1631 | |
| 1632 Register elements = ToRegister(instr->elements()); | |
| 1633 Register scratch = x5; | |
| 1634 DCHECK(receiver.Is(x0)); // Used for parameter count. | |
| 1635 DCHECK(function.Is(x1)); // Required by InvokeFunction. | |
| 1636 DCHECK(ToRegister(instr->result()).Is(x0)); | |
| 1637 DCHECK(instr->IsMarkedAsCall()); | |
| 1638 | |
| 1639 // Copy the arguments to this function possibly from the | |
| 1640 // adaptor frame below it. | |
| 1641 const uint32_t kArgumentsLimit = 1 * KB; | |
| 1642 __ Cmp(length, kArgumentsLimit); | |
| 1643 DeoptimizeIf(hi, instr, Deoptimizer::kTooManyArguments); | |
| 1644 | |
| 1645 // Push the receiver and use the register to keep the original | |
| 1646 // number of arguments. | |
| 1647 __ Push(receiver); | |
| 1648 Register argc = receiver; | |
| 1649 receiver = NoReg; | |
| 1650 __ Sxtw(argc, length); | |
| 1651 // The arguments are at a one pointer size offset from elements. | |
| 1652 __ Add(elements, elements, 1 * kPointerSize); | |
| 1653 | |
| 1654 // Loop through the arguments pushing them onto the execution | |
| 1655 // stack. | |
| 1656 Label invoke, loop; | |
| 1657 // length is a small non-negative integer, due to the test above. | |
| 1658 __ Cbz(length, &invoke); | |
| 1659 __ Bind(&loop); | |
| 1660 __ Ldr(scratch, MemOperand(elements, length, SXTW, kPointerSizeLog2)); | |
| 1661 __ Push(scratch); | |
| 1662 __ Subs(length, length, 1); | |
| 1663 __ B(ne, &loop); | |
| 1664 | |
| 1665 __ Bind(&invoke); | |
| 1666 DCHECK(instr->HasPointerMap()); | |
| 1667 LPointerMap* pointers = instr->pointer_map(); | |
| 1668 SafepointGenerator safepoint_generator(this, pointers, Safepoint::kLazyDeopt); | |
| 1669 // The number of arguments is stored in argc (receiver) which is x0, as | |
| 1670 // expected by InvokeFunction. | |
| 1671 ParameterCount actual(argc); | |
| 1672 __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator); | |
| 1673 } | |
| 1674 | |
| 1675 | |
| 1676 void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { | |
| 1677 Register result = ToRegister(instr->result()); | |
| 1678 | |
| 1679 if (instr->hydrogen()->from_inlined()) { | |
| 1680 // When we are inside an inlined function, the arguments are the last things | |
| 1681 // that have been pushed on the stack. Therefore the arguments array can be | |
| 1682 // accessed directly from jssp. | |
| 1683 // However in the normal case, it is accessed via fp but there are two words | |
| 1684 // on the stack between fp and the arguments (the saved lr and fp) and the | |
| 1685 // LAccessArgumentsAt implementation take that into account. | |
| 1686 // In the inlined case we need to subtract the size of 2 words to jssp to | |
| 1687 // get a pointer which will work well with LAccessArgumentsAt. | |
| 1688 DCHECK(masm()->StackPointer().Is(jssp)); | |
| 1689 __ Sub(result, jssp, 2 * kPointerSize); | |
| 1690 } else { | |
| 1691 DCHECK(instr->temp() != NULL); | |
| 1692 Register previous_fp = ToRegister(instr->temp()); | |
| 1693 | |
| 1694 __ Ldr(previous_fp, | |
| 1695 MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | |
| 1696 __ Ldr(result, | |
| 1697 MemOperand(previous_fp, StandardFrameConstants::kContextOffset)); | |
| 1698 __ Cmp(result, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); | |
| 1699 __ Csel(result, fp, previous_fp, ne); | |
| 1700 } | |
| 1701 } | |
| 1702 | |
| 1703 | |
| 1704 void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { | |
| 1705 Register elements = ToRegister(instr->elements()); | |
| 1706 Register result = ToRegister32(instr->result()); | |
| 1707 Label done; | |
| 1708 | |
| 1709 // If no arguments adaptor frame the number of arguments is fixed. | |
| 1710 __ Cmp(fp, elements); | |
| 1711 __ Mov(result, scope()->num_parameters()); | |
| 1712 __ B(eq, &done); | |
| 1713 | |
| 1714 // Arguments adaptor frame present. Get argument length from there. | |
| 1715 __ Ldr(result.X(), MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | |
| 1716 __ Ldr(result, | |
| 1717 UntagSmiMemOperand(result.X(), | |
| 1718 ArgumentsAdaptorFrameConstants::kLengthOffset)); | |
| 1719 | |
| 1720 // Argument length is in result register. | |
| 1721 __ Bind(&done); | |
| 1722 } | |
| 1723 | |
| 1724 | |
| 1725 void LCodeGen::DoArithmeticD(LArithmeticD* instr) { | |
| 1726 DoubleRegister left = ToDoubleRegister(instr->left()); | |
| 1727 DoubleRegister right = ToDoubleRegister(instr->right()); | |
| 1728 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 1729 | |
| 1730 switch (instr->op()) { | |
| 1731 case Token::ADD: __ Fadd(result, left, right); break; | |
| 1732 case Token::SUB: __ Fsub(result, left, right); break; | |
| 1733 case Token::MUL: __ Fmul(result, left, right); break; | |
| 1734 case Token::DIV: __ Fdiv(result, left, right); break; | |
| 1735 case Token::MOD: { | |
| 1736 // The ECMA-262 remainder operator is the remainder from a truncating | |
| 1737 // (round-towards-zero) division. Note that this differs from IEEE-754. | |
| 1738 // | |
| 1739 // TODO(jbramley): See if it's possible to do this inline, rather than by | |
| 1740 // calling a helper function. With frintz (to produce the intermediate | |
| 1741 // quotient) and fmsub (to calculate the remainder without loss of | |
| 1742 // precision), it should be possible. However, we would need support for | |
| 1743 // fdiv in round-towards-zero mode, and the ARM64 simulator doesn't | |
| 1744 // support that yet. | |
| 1745 DCHECK(left.Is(d0)); | |
| 1746 DCHECK(right.Is(d1)); | |
| 1747 __ CallCFunction( | |
| 1748 ExternalReference::mod_two_doubles_operation(isolate()), | |
| 1749 0, 2); | |
| 1750 DCHECK(result.Is(d0)); | |
| 1751 break; | |
| 1752 } | |
| 1753 default: | |
| 1754 UNREACHABLE(); | |
| 1755 break; | |
| 1756 } | |
| 1757 } | |
| 1758 | |
| 1759 | |
| 1760 void LCodeGen::DoArithmeticT(LArithmeticT* instr) { | |
| 1761 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 1762 DCHECK(ToRegister(instr->left()).is(x1)); | |
| 1763 DCHECK(ToRegister(instr->right()).is(x0)); | |
| 1764 DCHECK(ToRegister(instr->result()).is(x0)); | |
| 1765 | |
| 1766 Handle<Code> code = | |
| 1767 CodeFactory::BinaryOpIC(isolate(), instr->op(), instr->strength()).code(); | |
| 1768 CallCode(code, RelocInfo::CODE_TARGET, instr); | |
| 1769 } | |
| 1770 | |
| 1771 | |
| 1772 void LCodeGen::DoBitI(LBitI* instr) { | |
| 1773 Register result = ToRegister32(instr->result()); | |
| 1774 Register left = ToRegister32(instr->left()); | |
| 1775 Operand right = ToShiftedRightOperand32(instr->right(), instr); | |
| 1776 | |
| 1777 switch (instr->op()) { | |
| 1778 case Token::BIT_AND: __ And(result, left, right); break; | |
| 1779 case Token::BIT_OR: __ Orr(result, left, right); break; | |
| 1780 case Token::BIT_XOR: __ Eor(result, left, right); break; | |
| 1781 default: | |
| 1782 UNREACHABLE(); | |
| 1783 break; | |
| 1784 } | |
| 1785 } | |
| 1786 | |
| 1787 | |
| 1788 void LCodeGen::DoBitS(LBitS* instr) { | |
| 1789 Register result = ToRegister(instr->result()); | |
| 1790 Register left = ToRegister(instr->left()); | |
| 1791 Operand right = ToOperand(instr->right()); | |
| 1792 | |
| 1793 switch (instr->op()) { | |
| 1794 case Token::BIT_AND: __ And(result, left, right); break; | |
| 1795 case Token::BIT_OR: __ Orr(result, left, right); break; | |
| 1796 case Token::BIT_XOR: __ Eor(result, left, right); break; | |
| 1797 default: | |
| 1798 UNREACHABLE(); | |
| 1799 break; | |
| 1800 } | |
| 1801 } | |
| 1802 | |
| 1803 | |
| 1804 void LCodeGen::DoBoundsCheck(LBoundsCheck *instr) { | |
| 1805 Condition cond = instr->hydrogen()->allow_equality() ? hi : hs; | |
| 1806 DCHECK(instr->hydrogen()->index()->representation().IsInteger32()); | |
| 1807 DCHECK(instr->hydrogen()->length()->representation().IsInteger32()); | |
| 1808 if (instr->index()->IsConstantOperand()) { | |
| 1809 Operand index = ToOperand32(instr->index()); | |
| 1810 Register length = ToRegister32(instr->length()); | |
| 1811 __ Cmp(length, index); | |
| 1812 cond = CommuteCondition(cond); | |
| 1813 } else { | |
| 1814 Register index = ToRegister32(instr->index()); | |
| 1815 Operand length = ToOperand32(instr->length()); | |
| 1816 __ Cmp(index, length); | |
| 1817 } | |
| 1818 if (FLAG_debug_code && instr->hydrogen()->skip_check()) { | |
| 1819 __ Assert(NegateCondition(cond), kEliminatedBoundsCheckFailed); | |
| 1820 } else { | |
| 1821 DeoptimizeIf(cond, instr, Deoptimizer::kOutOfBounds); | |
| 1822 } | |
| 1823 } | |
| 1824 | |
| 1825 | |
| 1826 void LCodeGen::DoBranch(LBranch* instr) { | |
| 1827 Representation r = instr->hydrogen()->value()->representation(); | |
| 1828 Label* true_label = instr->TrueLabel(chunk_); | |
| 1829 Label* false_label = instr->FalseLabel(chunk_); | |
| 1830 | |
| 1831 if (r.IsInteger32()) { | |
| 1832 DCHECK(!info()->IsStub()); | |
| 1833 EmitCompareAndBranch(instr, ne, ToRegister32(instr->value()), 0); | |
| 1834 } else if (r.IsSmi()) { | |
| 1835 DCHECK(!info()->IsStub()); | |
| 1836 STATIC_ASSERT(kSmiTag == 0); | |
| 1837 EmitCompareAndBranch(instr, ne, ToRegister(instr->value()), 0); | |
| 1838 } else if (r.IsDouble()) { | |
| 1839 DoubleRegister value = ToDoubleRegister(instr->value()); | |
| 1840 // Test the double value. Zero and NaN are false. | |
| 1841 EmitBranchIfNonZeroNumber(instr, value, double_scratch()); | |
| 1842 } else { | |
| 1843 DCHECK(r.IsTagged()); | |
| 1844 Register value = ToRegister(instr->value()); | |
| 1845 HType type = instr->hydrogen()->value()->type(); | |
| 1846 | |
| 1847 if (type.IsBoolean()) { | |
| 1848 DCHECK(!info()->IsStub()); | |
| 1849 __ CompareRoot(value, Heap::kTrueValueRootIndex); | |
| 1850 EmitBranch(instr, eq); | |
| 1851 } else if (type.IsSmi()) { | |
| 1852 DCHECK(!info()->IsStub()); | |
| 1853 EmitCompareAndBranch(instr, ne, value, Smi::FromInt(0)); | |
| 1854 } else if (type.IsJSArray()) { | |
| 1855 DCHECK(!info()->IsStub()); | |
| 1856 EmitGoto(instr->TrueDestination(chunk())); | |
| 1857 } else if (type.IsHeapNumber()) { | |
| 1858 DCHECK(!info()->IsStub()); | |
| 1859 __ Ldr(double_scratch(), FieldMemOperand(value, | |
| 1860 HeapNumber::kValueOffset)); | |
| 1861 // Test the double value. Zero and NaN are false. | |
| 1862 EmitBranchIfNonZeroNumber(instr, double_scratch(), double_scratch()); | |
| 1863 } else if (type.IsString()) { | |
| 1864 DCHECK(!info()->IsStub()); | |
| 1865 Register temp = ToRegister(instr->temp1()); | |
| 1866 __ Ldr(temp, FieldMemOperand(value, String::kLengthOffset)); | |
| 1867 EmitCompareAndBranch(instr, ne, temp, 0); | |
| 1868 } else { | |
| 1869 ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); | |
| 1870 // Avoid deopts in the case where we've never executed this path before. | |
| 1871 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); | |
| 1872 | |
| 1873 if (expected.Contains(ToBooleanStub::UNDEFINED)) { | |
| 1874 // undefined -> false. | |
| 1875 __ JumpIfRoot( | |
| 1876 value, Heap::kUndefinedValueRootIndex, false_label); | |
| 1877 } | |
| 1878 | |
| 1879 if (expected.Contains(ToBooleanStub::BOOLEAN)) { | |
| 1880 // Boolean -> its value. | |
| 1881 __ JumpIfRoot( | |
| 1882 value, Heap::kTrueValueRootIndex, true_label); | |
| 1883 __ JumpIfRoot( | |
| 1884 value, Heap::kFalseValueRootIndex, false_label); | |
| 1885 } | |
| 1886 | |
| 1887 if (expected.Contains(ToBooleanStub::NULL_TYPE)) { | |
| 1888 // 'null' -> false. | |
| 1889 __ JumpIfRoot( | |
| 1890 value, Heap::kNullValueRootIndex, false_label); | |
| 1891 } | |
| 1892 | |
| 1893 if (expected.Contains(ToBooleanStub::SMI)) { | |
| 1894 // Smis: 0 -> false, all other -> true. | |
| 1895 DCHECK(Smi::FromInt(0) == 0); | |
| 1896 __ Cbz(value, false_label); | |
| 1897 __ JumpIfSmi(value, true_label); | |
| 1898 } else if (expected.NeedsMap()) { | |
| 1899 // If we need a map later and have a smi, deopt. | |
| 1900 DeoptimizeIfSmi(value, instr, Deoptimizer::kSmi); | |
| 1901 } | |
| 1902 | |
| 1903 Register map = NoReg; | |
| 1904 Register scratch = NoReg; | |
| 1905 | |
| 1906 if (expected.NeedsMap()) { | |
| 1907 DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL)); | |
| 1908 map = ToRegister(instr->temp1()); | |
| 1909 scratch = ToRegister(instr->temp2()); | |
| 1910 | |
| 1911 __ Ldr(map, FieldMemOperand(value, HeapObject::kMapOffset)); | |
| 1912 | |
| 1913 if (expected.CanBeUndetectable()) { | |
| 1914 // Undetectable -> false. | |
| 1915 __ Ldrb(scratch, FieldMemOperand(map, Map::kBitFieldOffset)); | |
| 1916 __ TestAndBranchIfAnySet( | |
| 1917 scratch, 1 << Map::kIsUndetectable, false_label); | |
| 1918 } | |
| 1919 } | |
| 1920 | |
| 1921 if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { | |
| 1922 // spec object -> true. | |
| 1923 __ CompareInstanceType(map, scratch, FIRST_SPEC_OBJECT_TYPE); | |
| 1924 __ B(ge, true_label); | |
| 1925 } | |
| 1926 | |
| 1927 if (expected.Contains(ToBooleanStub::STRING)) { | |
| 1928 // String value -> false iff empty. | |
| 1929 Label not_string; | |
| 1930 __ CompareInstanceType(map, scratch, FIRST_NONSTRING_TYPE); | |
| 1931 __ B(ge, ¬_string); | |
| 1932 __ Ldr(scratch, FieldMemOperand(value, String::kLengthOffset)); | |
| 1933 __ Cbz(scratch, false_label); | |
| 1934 __ B(true_label); | |
| 1935 __ Bind(¬_string); | |
| 1936 } | |
| 1937 | |
| 1938 if (expected.Contains(ToBooleanStub::SYMBOL)) { | |
| 1939 // Symbol value -> true. | |
| 1940 __ CompareInstanceType(map, scratch, SYMBOL_TYPE); | |
| 1941 __ B(eq, true_label); | |
| 1942 } | |
| 1943 | |
| 1944 if (expected.Contains(ToBooleanStub::SIMD_VALUE)) { | |
| 1945 // SIMD value -> true. | |
| 1946 __ CompareInstanceType(map, scratch, SIMD128_VALUE_TYPE); | |
| 1947 __ B(eq, true_label); | |
| 1948 } | |
| 1949 | |
| 1950 if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { | |
| 1951 Label not_heap_number; | |
| 1952 __ JumpIfNotRoot(map, Heap::kHeapNumberMapRootIndex, ¬_heap_number); | |
| 1953 | |
| 1954 __ Ldr(double_scratch(), | |
| 1955 FieldMemOperand(value, HeapNumber::kValueOffset)); | |
| 1956 __ Fcmp(double_scratch(), 0.0); | |
| 1957 // If we got a NaN (overflow bit is set), jump to the false branch. | |
| 1958 __ B(vs, false_label); | |
| 1959 __ B(eq, false_label); | |
| 1960 __ B(true_label); | |
| 1961 __ Bind(¬_heap_number); | |
| 1962 } | |
| 1963 | |
| 1964 if (!expected.IsGeneric()) { | |
| 1965 // We've seen something for the first time -> deopt. | |
| 1966 // This can only happen if we are not generic already. | |
| 1967 Deoptimize(instr, Deoptimizer::kUnexpectedObject); | |
| 1968 } | |
| 1969 } | |
| 1970 } | |
| 1971 } | |
| 1972 | |
| 1973 | |
| 1974 void LCodeGen::CallKnownFunction(Handle<JSFunction> function, | |
| 1975 int formal_parameter_count, int arity, | |
| 1976 LInstruction* instr) { | |
| 1977 bool dont_adapt_arguments = | |
| 1978 formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; | |
| 1979 bool can_invoke_directly = | |
| 1980 dont_adapt_arguments || formal_parameter_count == arity; | |
| 1981 | |
| 1982 // The function interface relies on the following register assignments. | |
| 1983 Register function_reg = x1; | |
| 1984 Register arity_reg = x0; | |
| 1985 | |
| 1986 LPointerMap* pointers = instr->pointer_map(); | |
| 1987 | |
| 1988 if (FLAG_debug_code) { | |
| 1989 Label is_not_smi; | |
| 1990 // Try to confirm that function_reg (x1) is a tagged pointer. | |
| 1991 __ JumpIfNotSmi(function_reg, &is_not_smi); | |
| 1992 __ Abort(kExpectedFunctionObject); | |
| 1993 __ Bind(&is_not_smi); | |
| 1994 } | |
| 1995 | |
| 1996 if (can_invoke_directly) { | |
| 1997 // Change context. | |
| 1998 __ Ldr(cp, FieldMemOperand(function_reg, JSFunction::kContextOffset)); | |
| 1999 | |
| 2000 // Always initialize x0 to the number of actual arguments. | |
| 2001 __ Mov(arity_reg, arity); | |
| 2002 | |
| 2003 // Invoke function. | |
| 2004 __ Ldr(x10, FieldMemOperand(function_reg, JSFunction::kCodeEntryOffset)); | |
| 2005 __ Call(x10); | |
| 2006 | |
| 2007 // Set up deoptimization. | |
| 2008 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); | |
| 2009 } else { | |
| 2010 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); | |
| 2011 ParameterCount count(arity); | |
| 2012 ParameterCount expected(formal_parameter_count); | |
| 2013 __ InvokeFunction(function_reg, expected, count, CALL_FUNCTION, generator); | |
| 2014 } | |
| 2015 } | |
| 2016 | |
| 2017 | |
| 2018 void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) { | |
| 2019 DCHECK(instr->IsMarkedAsCall()); | |
| 2020 DCHECK(ToRegister(instr->result()).Is(x0)); | |
| 2021 | |
| 2022 if (instr->hydrogen()->IsTailCall()) { | |
| 2023 if (NeedsEagerFrame()) __ LeaveFrame(StackFrame::INTERNAL); | |
| 2024 | |
| 2025 if (instr->target()->IsConstantOperand()) { | |
| 2026 LConstantOperand* target = LConstantOperand::cast(instr->target()); | |
| 2027 Handle<Code> code = Handle<Code>::cast(ToHandle(target)); | |
| 2028 // TODO(all): on ARM we use a call descriptor to specify a storage mode | |
| 2029 // but on ARM64 we only have one storage mode so it isn't necessary. Check | |
| 2030 // this understanding is correct. | |
| 2031 __ Jump(code, RelocInfo::CODE_TARGET); | |
| 2032 } else { | |
| 2033 DCHECK(instr->target()->IsRegister()); | |
| 2034 Register target = ToRegister(instr->target()); | |
| 2035 __ Add(target, target, Code::kHeaderSize - kHeapObjectTag); | |
| 2036 __ Br(target); | |
| 2037 } | |
| 2038 } else { | |
| 2039 LPointerMap* pointers = instr->pointer_map(); | |
| 2040 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); | |
| 2041 | |
| 2042 if (instr->target()->IsConstantOperand()) { | |
| 2043 LConstantOperand* target = LConstantOperand::cast(instr->target()); | |
| 2044 Handle<Code> code = Handle<Code>::cast(ToHandle(target)); | |
| 2045 generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET)); | |
| 2046 // TODO(all): on ARM we use a call descriptor to specify a storage mode | |
| 2047 // but on ARM64 we only have one storage mode so it isn't necessary. Check | |
| 2048 // this understanding is correct. | |
| 2049 __ Call(code, RelocInfo::CODE_TARGET, TypeFeedbackId::None()); | |
| 2050 } else { | |
| 2051 DCHECK(instr->target()->IsRegister()); | |
| 2052 Register target = ToRegister(instr->target()); | |
| 2053 generator.BeforeCall(__ CallSize(target)); | |
| 2054 __ Add(target, target, Code::kHeaderSize - kHeapObjectTag); | |
| 2055 __ Call(target); | |
| 2056 } | |
| 2057 generator.AfterCall(); | |
| 2058 } | |
| 2059 | |
| 2060 RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta()); | |
| 2061 } | |
| 2062 | |
| 2063 | |
| 2064 void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) { | |
| 2065 DCHECK(instr->IsMarkedAsCall()); | |
| 2066 DCHECK(ToRegister(instr->function()).is(x1)); | |
| 2067 | |
| 2068 __ Mov(x0, Operand(instr->arity())); | |
| 2069 | |
| 2070 // Change context. | |
| 2071 __ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset)); | |
| 2072 | |
| 2073 // Load the code entry address | |
| 2074 __ Ldr(x10, FieldMemOperand(x1, JSFunction::kCodeEntryOffset)); | |
| 2075 __ Call(x10); | |
| 2076 | |
| 2077 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); | |
| 2078 RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta()); | |
| 2079 } | |
| 2080 | |
| 2081 | |
| 2082 void LCodeGen::DoCallRuntime(LCallRuntime* instr) { | |
| 2083 CallRuntime(instr->function(), instr->arity(), instr); | |
| 2084 RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta()); | |
| 2085 } | |
| 2086 | |
| 2087 | |
| 2088 void LCodeGen::DoCallStub(LCallStub* instr) { | |
| 2089 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 2090 DCHECK(ToRegister(instr->result()).is(x0)); | |
| 2091 switch (instr->hydrogen()->major_key()) { | |
| 2092 case CodeStub::RegExpExec: { | |
| 2093 RegExpExecStub stub(isolate()); | |
| 2094 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | |
| 2095 break; | |
| 2096 } | |
| 2097 case CodeStub::SubString: { | |
| 2098 SubStringStub stub(isolate()); | |
| 2099 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | |
| 2100 break; | |
| 2101 } | |
| 2102 default: | |
| 2103 UNREACHABLE(); | |
| 2104 } | |
| 2105 RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta()); | |
| 2106 } | |
| 2107 | |
| 2108 | |
| 2109 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { | |
| 2110 GenerateOsrPrologue(); | |
| 2111 } | |
| 2112 | |
| 2113 | |
| 2114 void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { | |
| 2115 Register temp = ToRegister(instr->temp()); | |
| 2116 { | |
| 2117 PushSafepointRegistersScope scope(this); | |
| 2118 __ Push(object); | |
| 2119 __ Mov(cp, 0); | |
| 2120 __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance); | |
| 2121 RecordSafepointWithRegisters( | |
| 2122 instr->pointer_map(), 1, Safepoint::kNoLazyDeopt); | |
| 2123 __ StoreToSafepointRegisterSlot(x0, temp); | |
| 2124 } | |
| 2125 DeoptimizeIfSmi(temp, instr, Deoptimizer::kInstanceMigrationFailed); | |
| 2126 } | |
| 2127 | |
| 2128 | |
| 2129 void LCodeGen::DoCheckMaps(LCheckMaps* instr) { | |
| 2130 class DeferredCheckMaps: public LDeferredCode { | |
| 2131 public: | |
| 2132 DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object) | |
| 2133 : LDeferredCode(codegen), instr_(instr), object_(object) { | |
| 2134 SetExit(check_maps()); | |
| 2135 } | |
| 2136 virtual void Generate() { | |
| 2137 codegen()->DoDeferredInstanceMigration(instr_, object_); | |
| 2138 } | |
| 2139 Label* check_maps() { return &check_maps_; } | |
| 2140 virtual LInstruction* instr() { return instr_; } | |
| 2141 private: | |
| 2142 LCheckMaps* instr_; | |
| 2143 Label check_maps_; | |
| 2144 Register object_; | |
| 2145 }; | |
| 2146 | |
| 2147 if (instr->hydrogen()->IsStabilityCheck()) { | |
| 2148 const UniqueSet<Map>* maps = instr->hydrogen()->maps(); | |
| 2149 for (int i = 0; i < maps->size(); ++i) { | |
| 2150 AddStabilityDependency(maps->at(i).handle()); | |
| 2151 } | |
| 2152 return; | |
| 2153 } | |
| 2154 | |
| 2155 Register object = ToRegister(instr->value()); | |
| 2156 Register map_reg = ToRegister(instr->temp()); | |
| 2157 | |
| 2158 __ Ldr(map_reg, FieldMemOperand(object, HeapObject::kMapOffset)); | |
| 2159 | |
| 2160 DeferredCheckMaps* deferred = NULL; | |
| 2161 if (instr->hydrogen()->HasMigrationTarget()) { | |
| 2162 deferred = new(zone()) DeferredCheckMaps(this, instr, object); | |
| 2163 __ Bind(deferred->check_maps()); | |
| 2164 } | |
| 2165 | |
| 2166 const UniqueSet<Map>* maps = instr->hydrogen()->maps(); | |
| 2167 Label success; | |
| 2168 for (int i = 0; i < maps->size() - 1; i++) { | |
| 2169 Handle<Map> map = maps->at(i).handle(); | |
| 2170 __ CompareMap(map_reg, map); | |
| 2171 __ B(eq, &success); | |
| 2172 } | |
| 2173 Handle<Map> map = maps->at(maps->size() - 1).handle(); | |
| 2174 __ CompareMap(map_reg, map); | |
| 2175 | |
| 2176 // We didn't match a map. | |
| 2177 if (instr->hydrogen()->HasMigrationTarget()) { | |
| 2178 __ B(ne, deferred->entry()); | |
| 2179 } else { | |
| 2180 DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap); | |
| 2181 } | |
| 2182 | |
| 2183 __ Bind(&success); | |
| 2184 } | |
| 2185 | |
| 2186 | |
| 2187 void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { | |
| 2188 if (!instr->hydrogen()->value()->type().IsHeapObject()) { | |
| 2189 DeoptimizeIfSmi(ToRegister(instr->value()), instr, Deoptimizer::kSmi); | |
| 2190 } | |
| 2191 } | |
| 2192 | |
| 2193 | |
| 2194 void LCodeGen::DoCheckSmi(LCheckSmi* instr) { | |
| 2195 Register value = ToRegister(instr->value()); | |
| 2196 DCHECK(!instr->result() || ToRegister(instr->result()).Is(value)); | |
| 2197 DeoptimizeIfNotSmi(value, instr, Deoptimizer::kNotASmi); | |
| 2198 } | |
| 2199 | |
| 2200 | |
| 2201 void LCodeGen::DoCheckArrayBufferNotNeutered( | |
| 2202 LCheckArrayBufferNotNeutered* instr) { | |
| 2203 UseScratchRegisterScope temps(masm()); | |
| 2204 Register view = ToRegister(instr->view()); | |
| 2205 Register scratch = temps.AcquireX(); | |
| 2206 | |
| 2207 __ Ldr(scratch, FieldMemOperand(view, JSArrayBufferView::kBufferOffset)); | |
| 2208 __ Ldr(scratch, FieldMemOperand(scratch, JSArrayBuffer::kBitFieldOffset)); | |
| 2209 __ Tst(scratch, Operand(1 << JSArrayBuffer::WasNeutered::kShift)); | |
| 2210 DeoptimizeIf(ne, instr, Deoptimizer::kOutOfBounds); | |
| 2211 } | |
| 2212 | |
| 2213 | |
| 2214 void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { | |
| 2215 Register input = ToRegister(instr->value()); | |
| 2216 Register scratch = ToRegister(instr->temp()); | |
| 2217 | |
| 2218 __ Ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | |
| 2219 __ Ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); | |
| 2220 | |
| 2221 if (instr->hydrogen()->is_interval_check()) { | |
| 2222 InstanceType first, last; | |
| 2223 instr->hydrogen()->GetCheckInterval(&first, &last); | |
| 2224 | |
| 2225 __ Cmp(scratch, first); | |
| 2226 if (first == last) { | |
| 2227 // If there is only one type in the interval check for equality. | |
| 2228 DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType); | |
| 2229 } else if (last == LAST_TYPE) { | |
| 2230 // We don't need to compare with the higher bound of the interval. | |
| 2231 DeoptimizeIf(lo, instr, Deoptimizer::kWrongInstanceType); | |
| 2232 } else { | |
| 2233 // If we are below the lower bound, set the C flag and clear the Z flag | |
| 2234 // to force a deopt. | |
| 2235 __ Ccmp(scratch, last, CFlag, hs); | |
| 2236 DeoptimizeIf(hi, instr, Deoptimizer::kWrongInstanceType); | |
| 2237 } | |
| 2238 } else { | |
| 2239 uint8_t mask; | |
| 2240 uint8_t tag; | |
| 2241 instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); | |
| 2242 | |
| 2243 if (base::bits::IsPowerOfTwo32(mask)) { | |
| 2244 DCHECK((tag == 0) || (tag == mask)); | |
| 2245 if (tag == 0) { | |
| 2246 DeoptimizeIfBitSet(scratch, MaskToBit(mask), instr, | |
| 2247 Deoptimizer::kWrongInstanceType); | |
| 2248 } else { | |
| 2249 DeoptimizeIfBitClear(scratch, MaskToBit(mask), instr, | |
| 2250 Deoptimizer::kWrongInstanceType); | |
| 2251 } | |
| 2252 } else { | |
| 2253 if (tag == 0) { | |
| 2254 __ Tst(scratch, mask); | |
| 2255 } else { | |
| 2256 __ And(scratch, scratch, mask); | |
| 2257 __ Cmp(scratch, tag); | |
| 2258 } | |
| 2259 DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType); | |
| 2260 } | |
| 2261 } | |
| 2262 } | |
| 2263 | |
| 2264 | |
| 2265 void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { | |
| 2266 DoubleRegister input = ToDoubleRegister(instr->unclamped()); | |
| 2267 Register result = ToRegister32(instr->result()); | |
| 2268 __ ClampDoubleToUint8(result, input, double_scratch()); | |
| 2269 } | |
| 2270 | |
| 2271 | |
| 2272 void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { | |
| 2273 Register input = ToRegister32(instr->unclamped()); | |
| 2274 Register result = ToRegister32(instr->result()); | |
| 2275 __ ClampInt32ToUint8(result, input); | |
| 2276 } | |
| 2277 | |
| 2278 | |
| 2279 void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { | |
| 2280 Register input = ToRegister(instr->unclamped()); | |
| 2281 Register result = ToRegister32(instr->result()); | |
| 2282 Label done; | |
| 2283 | |
| 2284 // Both smi and heap number cases are handled. | |
| 2285 Label is_not_smi; | |
| 2286 __ JumpIfNotSmi(input, &is_not_smi); | |
| 2287 __ SmiUntag(result.X(), input); | |
| 2288 __ ClampInt32ToUint8(result); | |
| 2289 __ B(&done); | |
| 2290 | |
| 2291 __ Bind(&is_not_smi); | |
| 2292 | |
| 2293 // Check for heap number. | |
| 2294 Label is_heap_number; | |
| 2295 __ JumpIfHeapNumber(input, &is_heap_number); | |
| 2296 | |
| 2297 // Check for undefined. Undefined is coverted to zero for clamping conversion. | |
| 2298 DeoptimizeIfNotRoot(input, Heap::kUndefinedValueRootIndex, instr, | |
| 2299 Deoptimizer::kNotAHeapNumberUndefined); | |
| 2300 __ Mov(result, 0); | |
| 2301 __ B(&done); | |
| 2302 | |
| 2303 // Heap number case. | |
| 2304 __ Bind(&is_heap_number); | |
| 2305 DoubleRegister dbl_scratch = double_scratch(); | |
| 2306 DoubleRegister dbl_scratch2 = ToDoubleRegister(instr->temp1()); | |
| 2307 __ Ldr(dbl_scratch, FieldMemOperand(input, HeapNumber::kValueOffset)); | |
| 2308 __ ClampDoubleToUint8(result, dbl_scratch, dbl_scratch2); | |
| 2309 | |
| 2310 __ Bind(&done); | |
| 2311 } | |
| 2312 | |
| 2313 | |
| 2314 void LCodeGen::DoDoubleBits(LDoubleBits* instr) { | |
| 2315 DoubleRegister value_reg = ToDoubleRegister(instr->value()); | |
| 2316 Register result_reg = ToRegister(instr->result()); | |
| 2317 if (instr->hydrogen()->bits() == HDoubleBits::HIGH) { | |
| 2318 __ Fmov(result_reg, value_reg); | |
| 2319 __ Lsr(result_reg, result_reg, 32); | |
| 2320 } else { | |
| 2321 __ Fmov(result_reg.W(), value_reg.S()); | |
| 2322 } | |
| 2323 } | |
| 2324 | |
| 2325 | |
| 2326 void LCodeGen::DoConstructDouble(LConstructDouble* instr) { | |
| 2327 Register hi_reg = ToRegister(instr->hi()); | |
| 2328 Register lo_reg = ToRegister(instr->lo()); | |
| 2329 DoubleRegister result_reg = ToDoubleRegister(instr->result()); | |
| 2330 | |
| 2331 // Insert the least significant 32 bits of hi_reg into the most significant | |
| 2332 // 32 bits of lo_reg, and move to a floating point register. | |
| 2333 __ Bfi(lo_reg, hi_reg, 32, 32); | |
| 2334 __ Fmov(result_reg, lo_reg); | |
| 2335 } | |
| 2336 | |
| 2337 | |
| 2338 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { | |
| 2339 Handle<String> class_name = instr->hydrogen()->class_name(); | |
| 2340 Label* true_label = instr->TrueLabel(chunk_); | |
| 2341 Label* false_label = instr->FalseLabel(chunk_); | |
| 2342 Register input = ToRegister(instr->value()); | |
| 2343 Register scratch1 = ToRegister(instr->temp1()); | |
| 2344 Register scratch2 = ToRegister(instr->temp2()); | |
| 2345 | |
| 2346 __ JumpIfSmi(input, false_label); | |
| 2347 | |
| 2348 Register map = scratch2; | |
| 2349 if (String::Equals(isolate()->factory()->Function_string(), class_name)) { | |
| 2350 // Assuming the following assertions, we can use the same compares to test | |
| 2351 // for both being a function type and being in the object type range. | |
| 2352 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); | |
| 2353 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == | |
| 2354 FIRST_SPEC_OBJECT_TYPE + 1); | |
| 2355 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == | |
| 2356 LAST_SPEC_OBJECT_TYPE - 1); | |
| 2357 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); | |
| 2358 | |
| 2359 // We expect CompareObjectType to load the object instance type in scratch1. | |
| 2360 __ CompareObjectType(input, map, scratch1, FIRST_SPEC_OBJECT_TYPE); | |
| 2361 __ B(lt, false_label); | |
| 2362 __ B(eq, true_label); | |
| 2363 __ Cmp(scratch1, LAST_SPEC_OBJECT_TYPE); | |
| 2364 __ B(eq, true_label); | |
| 2365 } else { | |
| 2366 __ IsObjectJSObjectType(input, map, scratch1, false_label); | |
| 2367 } | |
| 2368 | |
| 2369 // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. | |
| 2370 // Check if the constructor in the map is a function. | |
| 2371 { | |
| 2372 UseScratchRegisterScope temps(masm()); | |
| 2373 Register instance_type = temps.AcquireX(); | |
| 2374 __ GetMapConstructor(scratch1, map, scratch2, instance_type); | |
| 2375 __ Cmp(instance_type, JS_FUNCTION_TYPE); | |
| 2376 } | |
| 2377 // Objects with a non-function constructor have class 'Object'. | |
| 2378 if (String::Equals(class_name, isolate()->factory()->Object_string())) { | |
| 2379 __ B(ne, true_label); | |
| 2380 } else { | |
| 2381 __ B(ne, false_label); | |
| 2382 } | |
| 2383 | |
| 2384 // The constructor function is in scratch1. Get its instance class name. | |
| 2385 __ Ldr(scratch1, | |
| 2386 FieldMemOperand(scratch1, JSFunction::kSharedFunctionInfoOffset)); | |
| 2387 __ Ldr(scratch1, | |
| 2388 FieldMemOperand(scratch1, | |
| 2389 SharedFunctionInfo::kInstanceClassNameOffset)); | |
| 2390 | |
| 2391 // The class name we are testing against is internalized since it's a literal. | |
| 2392 // The name in the constructor is internalized because of the way the context | |
| 2393 // is booted. This routine isn't expected to work for random API-created | |
| 2394 // classes and it doesn't have to because you can't access it with natives | |
| 2395 // syntax. Since both sides are internalized it is sufficient to use an | |
| 2396 // identity comparison. | |
| 2397 EmitCompareAndBranch(instr, eq, scratch1, Operand(class_name)); | |
| 2398 } | |
| 2399 | |
| 2400 | |
| 2401 void LCodeGen::DoCmpHoleAndBranchD(LCmpHoleAndBranchD* instr) { | |
| 2402 DCHECK(instr->hydrogen()->representation().IsDouble()); | |
| 2403 FPRegister object = ToDoubleRegister(instr->object()); | |
| 2404 Register temp = ToRegister(instr->temp()); | |
| 2405 | |
| 2406 // If we don't have a NaN, we don't have the hole, so branch now to avoid the | |
| 2407 // (relatively expensive) hole-NaN check. | |
| 2408 __ Fcmp(object, object); | |
| 2409 __ B(vc, instr->FalseLabel(chunk_)); | |
| 2410 | |
| 2411 // We have a NaN, but is it the hole? | |
| 2412 __ Fmov(temp, object); | |
| 2413 EmitCompareAndBranch(instr, eq, temp, kHoleNanInt64); | |
| 2414 } | |
| 2415 | |
| 2416 | |
| 2417 void LCodeGen::DoCmpHoleAndBranchT(LCmpHoleAndBranchT* instr) { | |
| 2418 DCHECK(instr->hydrogen()->representation().IsTagged()); | |
| 2419 Register object = ToRegister(instr->object()); | |
| 2420 | |
| 2421 EmitBranchIfRoot(instr, object, Heap::kTheHoleValueRootIndex); | |
| 2422 } | |
| 2423 | |
| 2424 | |
| 2425 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { | |
| 2426 Register value = ToRegister(instr->value()); | |
| 2427 Register map = ToRegister(instr->temp()); | |
| 2428 | |
| 2429 __ Ldr(map, FieldMemOperand(value, HeapObject::kMapOffset)); | |
| 2430 EmitCompareAndBranch(instr, eq, map, Operand(instr->map())); | |
| 2431 } | |
| 2432 | |
| 2433 | |
| 2434 void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { | |
| 2435 Representation rep = instr->hydrogen()->value()->representation(); | |
| 2436 DCHECK(!rep.IsInteger32()); | |
| 2437 Register scratch = ToRegister(instr->temp()); | |
| 2438 | |
| 2439 if (rep.IsDouble()) { | |
| 2440 __ JumpIfMinusZero(ToDoubleRegister(instr->value()), | |
| 2441 instr->TrueLabel(chunk())); | |
| 2442 } else { | |
| 2443 Register value = ToRegister(instr->value()); | |
| 2444 __ JumpIfNotHeapNumber(value, instr->FalseLabel(chunk()), DO_SMI_CHECK); | |
| 2445 __ Ldr(scratch, FieldMemOperand(value, HeapNumber::kValueOffset)); | |
| 2446 __ JumpIfMinusZero(scratch, instr->TrueLabel(chunk())); | |
| 2447 } | |
| 2448 EmitGoto(instr->FalseDestination(chunk())); | |
| 2449 } | |
| 2450 | |
| 2451 | |
| 2452 void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { | |
| 2453 LOperand* left = instr->left(); | |
| 2454 LOperand* right = instr->right(); | |
| 2455 bool is_unsigned = | |
| 2456 instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) || | |
| 2457 instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32); | |
| 2458 Condition cond = TokenToCondition(instr->op(), is_unsigned); | |
| 2459 | |
| 2460 if (left->IsConstantOperand() && right->IsConstantOperand()) { | |
| 2461 // We can statically evaluate the comparison. | |
| 2462 double left_val = ToDouble(LConstantOperand::cast(left)); | |
| 2463 double right_val = ToDouble(LConstantOperand::cast(right)); | |
| 2464 int next_block = EvalComparison(instr->op(), left_val, right_val) ? | |
| 2465 instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); | |
| 2466 EmitGoto(next_block); | |
| 2467 } else { | |
| 2468 if (instr->is_double()) { | |
| 2469 __ Fcmp(ToDoubleRegister(left), ToDoubleRegister(right)); | |
| 2470 | |
| 2471 // If a NaN is involved, i.e. the result is unordered (V set), | |
| 2472 // jump to false block label. | |
| 2473 __ B(vs, instr->FalseLabel(chunk_)); | |
| 2474 EmitBranch(instr, cond); | |
| 2475 } else { | |
| 2476 if (instr->hydrogen_value()->representation().IsInteger32()) { | |
| 2477 if (right->IsConstantOperand()) { | |
| 2478 EmitCompareAndBranch(instr, cond, ToRegister32(left), | |
| 2479 ToOperand32(right)); | |
| 2480 } else { | |
| 2481 // Commute the operands and the condition. | |
| 2482 EmitCompareAndBranch(instr, CommuteCondition(cond), | |
| 2483 ToRegister32(right), ToOperand32(left)); | |
| 2484 } | |
| 2485 } else { | |
| 2486 DCHECK(instr->hydrogen_value()->representation().IsSmi()); | |
| 2487 if (right->IsConstantOperand()) { | |
| 2488 int32_t value = ToInteger32(LConstantOperand::cast(right)); | |
| 2489 EmitCompareAndBranch(instr, | |
| 2490 cond, | |
| 2491 ToRegister(left), | |
| 2492 Operand(Smi::FromInt(value))); | |
| 2493 } else if (left->IsConstantOperand()) { | |
| 2494 // Commute the operands and the condition. | |
| 2495 int32_t value = ToInteger32(LConstantOperand::cast(left)); | |
| 2496 EmitCompareAndBranch(instr, | |
| 2497 CommuteCondition(cond), | |
| 2498 ToRegister(right), | |
| 2499 Operand(Smi::FromInt(value))); | |
| 2500 } else { | |
| 2501 EmitCompareAndBranch(instr, | |
| 2502 cond, | |
| 2503 ToRegister(left), | |
| 2504 ToRegister(right)); | |
| 2505 } | |
| 2506 } | |
| 2507 } | |
| 2508 } | |
| 2509 } | |
| 2510 | |
| 2511 | |
| 2512 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { | |
| 2513 Register left = ToRegister(instr->left()); | |
| 2514 Register right = ToRegister(instr->right()); | |
| 2515 EmitCompareAndBranch(instr, eq, left, right); | |
| 2516 } | |
| 2517 | |
| 2518 | |
| 2519 void LCodeGen::DoCmpT(LCmpT* instr) { | |
| 2520 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 2521 Token::Value op = instr->op(); | |
| 2522 Condition cond = TokenToCondition(op, false); | |
| 2523 | |
| 2524 DCHECK(ToRegister(instr->left()).Is(x1)); | |
| 2525 DCHECK(ToRegister(instr->right()).Is(x0)); | |
| 2526 Handle<Code> ic = | |
| 2527 CodeFactory::CompareIC(isolate(), op, instr->strength()).code(); | |
| 2528 CallCode(ic, RelocInfo::CODE_TARGET, instr); | |
| 2529 // Signal that we don't inline smi code before this stub. | |
| 2530 InlineSmiCheckInfo::EmitNotInlined(masm()); | |
| 2531 | |
| 2532 // Return true or false depending on CompareIC result. | |
| 2533 // This instruction is marked as call. We can clobber any register. | |
| 2534 DCHECK(instr->IsMarkedAsCall()); | |
| 2535 __ LoadTrueFalseRoots(x1, x2); | |
| 2536 __ Cmp(x0, 0); | |
| 2537 __ Csel(ToRegister(instr->result()), x1, x2, cond); | |
| 2538 } | |
| 2539 | |
| 2540 | |
| 2541 void LCodeGen::DoConstantD(LConstantD* instr) { | |
| 2542 DCHECK(instr->result()->IsDoubleRegister()); | |
| 2543 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 2544 if (instr->value() == 0) { | |
| 2545 if (copysign(1.0, instr->value()) == 1.0) { | |
| 2546 __ Fmov(result, fp_zero); | |
| 2547 } else { | |
| 2548 __ Fneg(result, fp_zero); | |
| 2549 } | |
| 2550 } else { | |
| 2551 __ Fmov(result, instr->value()); | |
| 2552 } | |
| 2553 } | |
| 2554 | |
| 2555 | |
| 2556 void LCodeGen::DoConstantE(LConstantE* instr) { | |
| 2557 __ Mov(ToRegister(instr->result()), Operand(instr->value())); | |
| 2558 } | |
| 2559 | |
| 2560 | |
| 2561 void LCodeGen::DoConstantI(LConstantI* instr) { | |
| 2562 DCHECK(is_int32(instr->value())); | |
| 2563 // Cast the value here to ensure that the value isn't sign extended by the | |
| 2564 // implicit Operand constructor. | |
| 2565 __ Mov(ToRegister32(instr->result()), static_cast<uint32_t>(instr->value())); | |
| 2566 } | |
| 2567 | |
| 2568 | |
| 2569 void LCodeGen::DoConstantS(LConstantS* instr) { | |
| 2570 __ Mov(ToRegister(instr->result()), Operand(instr->value())); | |
| 2571 } | |
| 2572 | |
| 2573 | |
| 2574 void LCodeGen::DoConstantT(LConstantT* instr) { | |
| 2575 Handle<Object> object = instr->value(isolate()); | |
| 2576 AllowDeferredHandleDereference smi_check; | |
| 2577 __ LoadObject(ToRegister(instr->result()), object); | |
| 2578 } | |
| 2579 | |
| 2580 | |
| 2581 void LCodeGen::DoContext(LContext* instr) { | |
| 2582 // If there is a non-return use, the context must be moved to a register. | |
| 2583 Register result = ToRegister(instr->result()); | |
| 2584 if (info()->IsOptimizing()) { | |
| 2585 __ Ldr(result, MemOperand(fp, StandardFrameConstants::kContextOffset)); | |
| 2586 } else { | |
| 2587 // If there is no frame, the context must be in cp. | |
| 2588 DCHECK(result.is(cp)); | |
| 2589 } | |
| 2590 } | |
| 2591 | |
| 2592 | |
| 2593 void LCodeGen::DoCheckValue(LCheckValue* instr) { | |
| 2594 Register reg = ToRegister(instr->value()); | |
| 2595 Handle<HeapObject> object = instr->hydrogen()->object().handle(); | |
| 2596 AllowDeferredHandleDereference smi_check; | |
| 2597 if (isolate()->heap()->InNewSpace(*object)) { | |
| 2598 UseScratchRegisterScope temps(masm()); | |
| 2599 Register temp = temps.AcquireX(); | |
| 2600 Handle<Cell> cell = isolate()->factory()->NewCell(object); | |
| 2601 __ Mov(temp, Operand(cell)); | |
| 2602 __ Ldr(temp, FieldMemOperand(temp, Cell::kValueOffset)); | |
| 2603 __ Cmp(reg, temp); | |
| 2604 } else { | |
| 2605 __ Cmp(reg, Operand(object)); | |
| 2606 } | |
| 2607 DeoptimizeIf(ne, instr, Deoptimizer::kValueMismatch); | |
| 2608 } | |
| 2609 | |
| 2610 | |
| 2611 void LCodeGen::DoLazyBailout(LLazyBailout* instr) { | |
| 2612 last_lazy_deopt_pc_ = masm()->pc_offset(); | |
| 2613 DCHECK(instr->HasEnvironment()); | |
| 2614 LEnvironment* env = instr->environment(); | |
| 2615 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); | |
| 2616 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); | |
| 2617 } | |
| 2618 | |
| 2619 | |
| 2620 void LCodeGen::DoDateField(LDateField* instr) { | |
| 2621 Register object = ToRegister(instr->date()); | |
| 2622 Register result = ToRegister(instr->result()); | |
| 2623 Register temp1 = x10; | |
| 2624 Register temp2 = x11; | |
| 2625 Smi* index = instr->index(); | |
| 2626 | |
| 2627 DCHECK(object.is(result) && object.Is(x0)); | |
| 2628 DCHECK(instr->IsMarkedAsCall()); | |
| 2629 | |
| 2630 if (index->value() == 0) { | |
| 2631 __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset)); | |
| 2632 } else { | |
| 2633 Label runtime, done; | |
| 2634 if (index->value() < JSDate::kFirstUncachedField) { | |
| 2635 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); | |
| 2636 __ Mov(temp1, Operand(stamp)); | |
| 2637 __ Ldr(temp1, MemOperand(temp1)); | |
| 2638 __ Ldr(temp2, FieldMemOperand(object, JSDate::kCacheStampOffset)); | |
| 2639 __ Cmp(temp1, temp2); | |
| 2640 __ B(ne, &runtime); | |
| 2641 __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset + | |
| 2642 kPointerSize * index->value())); | |
| 2643 __ B(&done); | |
| 2644 } | |
| 2645 | |
| 2646 __ Bind(&runtime); | |
| 2647 __ Mov(x1, Operand(index)); | |
| 2648 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); | |
| 2649 __ Bind(&done); | |
| 2650 } | |
| 2651 } | |
| 2652 | |
| 2653 | |
| 2654 void LCodeGen::DoDeoptimize(LDeoptimize* instr) { | |
| 2655 Deoptimizer::BailoutType type = instr->hydrogen()->type(); | |
| 2656 // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the | |
| 2657 // needed return address), even though the implementation of LAZY and EAGER is | |
| 2658 // now identical. When LAZY is eventually completely folded into EAGER, remove | |
| 2659 // the special case below. | |
| 2660 if (info()->IsStub() && (type == Deoptimizer::EAGER)) { | |
| 2661 type = Deoptimizer::LAZY; | |
| 2662 } | |
| 2663 | |
| 2664 Deoptimize(instr, instr->hydrogen()->reason(), &type); | |
| 2665 } | |
| 2666 | |
| 2667 | |
| 2668 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { | |
| 2669 Register dividend = ToRegister32(instr->dividend()); | |
| 2670 int32_t divisor = instr->divisor(); | |
| 2671 Register result = ToRegister32(instr->result()); | |
| 2672 DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor))); | |
| 2673 DCHECK(!result.is(dividend)); | |
| 2674 | |
| 2675 // Check for (0 / -x) that will produce negative zero. | |
| 2676 HDiv* hdiv = instr->hydrogen(); | |
| 2677 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | |
| 2678 DeoptimizeIfZero(dividend, instr, Deoptimizer::kDivisionByZero); | |
| 2679 } | |
| 2680 // Check for (kMinInt / -1). | |
| 2681 if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) { | |
| 2682 // Test dividend for kMinInt by subtracting one (cmp) and checking for | |
| 2683 // overflow. | |
| 2684 __ Cmp(dividend, 1); | |
| 2685 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 2686 } | |
| 2687 // Deoptimize if remainder will not be 0. | |
| 2688 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && | |
| 2689 divisor != 1 && divisor != -1) { | |
| 2690 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); | |
| 2691 __ Tst(dividend, mask); | |
| 2692 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision); | |
| 2693 } | |
| 2694 | |
| 2695 if (divisor == -1) { // Nice shortcut, not needed for correctness. | |
| 2696 __ Neg(result, dividend); | |
| 2697 return; | |
| 2698 } | |
| 2699 int32_t shift = WhichPowerOf2Abs(divisor); | |
| 2700 if (shift == 0) { | |
| 2701 __ Mov(result, dividend); | |
| 2702 } else if (shift == 1) { | |
| 2703 __ Add(result, dividend, Operand(dividend, LSR, 31)); | |
| 2704 } else { | |
| 2705 __ Mov(result, Operand(dividend, ASR, 31)); | |
| 2706 __ Add(result, dividend, Operand(result, LSR, 32 - shift)); | |
| 2707 } | |
| 2708 if (shift > 0) __ Mov(result, Operand(result, ASR, shift)); | |
| 2709 if (divisor < 0) __ Neg(result, result); | |
| 2710 } | |
| 2711 | |
| 2712 | |
| 2713 void LCodeGen::DoDivByConstI(LDivByConstI* instr) { | |
| 2714 Register dividend = ToRegister32(instr->dividend()); | |
| 2715 int32_t divisor = instr->divisor(); | |
| 2716 Register result = ToRegister32(instr->result()); | |
| 2717 DCHECK(!AreAliased(dividend, result)); | |
| 2718 | |
| 2719 if (divisor == 0) { | |
| 2720 Deoptimize(instr, Deoptimizer::kDivisionByZero); | |
| 2721 return; | |
| 2722 } | |
| 2723 | |
| 2724 // Check for (0 / -x) that will produce negative zero. | |
| 2725 HDiv* hdiv = instr->hydrogen(); | |
| 2726 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | |
| 2727 DeoptimizeIfZero(dividend, instr, Deoptimizer::kMinusZero); | |
| 2728 } | |
| 2729 | |
| 2730 __ TruncatingDiv(result, dividend, Abs(divisor)); | |
| 2731 if (divisor < 0) __ Neg(result, result); | |
| 2732 | |
| 2733 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { | |
| 2734 Register temp = ToRegister32(instr->temp()); | |
| 2735 DCHECK(!AreAliased(dividend, result, temp)); | |
| 2736 __ Sxtw(dividend.X(), dividend); | |
| 2737 __ Mov(temp, divisor); | |
| 2738 __ Smsubl(temp.X(), result, temp, dividend.X()); | |
| 2739 DeoptimizeIfNotZero(temp, instr, Deoptimizer::kLostPrecision); | |
| 2740 } | |
| 2741 } | |
| 2742 | |
| 2743 | |
| 2744 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. | |
| 2745 void LCodeGen::DoDivI(LDivI* instr) { | |
| 2746 HBinaryOperation* hdiv = instr->hydrogen(); | |
| 2747 Register dividend = ToRegister32(instr->dividend()); | |
| 2748 Register divisor = ToRegister32(instr->divisor()); | |
| 2749 Register result = ToRegister32(instr->result()); | |
| 2750 | |
| 2751 // Issue the division first, and then check for any deopt cases whilst the | |
| 2752 // result is computed. | |
| 2753 __ Sdiv(result, dividend, divisor); | |
| 2754 | |
| 2755 if (hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { | |
| 2756 DCHECK(!instr->temp()); | |
| 2757 return; | |
| 2758 } | |
| 2759 | |
| 2760 // Check for x / 0. | |
| 2761 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { | |
| 2762 DeoptimizeIfZero(divisor, instr, Deoptimizer::kDivisionByZero); | |
| 2763 } | |
| 2764 | |
| 2765 // Check for (0 / -x) as that will produce negative zero. | |
| 2766 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 2767 __ Cmp(divisor, 0); | |
| 2768 | |
| 2769 // If the divisor < 0 (mi), compare the dividend, and deopt if it is | |
| 2770 // zero, ie. zero dividend with negative divisor deopts. | |
| 2771 // If the divisor >= 0 (pl, the opposite of mi) set the flags to | |
| 2772 // condition ne, so we don't deopt, ie. positive divisor doesn't deopt. | |
| 2773 __ Ccmp(dividend, 0, NoFlag, mi); | |
| 2774 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); | |
| 2775 } | |
| 2776 | |
| 2777 // Check for (kMinInt / -1). | |
| 2778 if (hdiv->CheckFlag(HValue::kCanOverflow)) { | |
| 2779 // Test dividend for kMinInt by subtracting one (cmp) and checking for | |
| 2780 // overflow. | |
| 2781 __ Cmp(dividend, 1); | |
| 2782 // If overflow is set, ie. dividend = kMinInt, compare the divisor with | |
| 2783 // -1. If overflow is clear, set the flags for condition ne, as the | |
| 2784 // dividend isn't -1, and thus we shouldn't deopt. | |
| 2785 __ Ccmp(divisor, -1, NoFlag, vs); | |
| 2786 DeoptimizeIf(eq, instr, Deoptimizer::kOverflow); | |
| 2787 } | |
| 2788 | |
| 2789 // Compute remainder and deopt if it's not zero. | |
| 2790 Register remainder = ToRegister32(instr->temp()); | |
| 2791 __ Msub(remainder, result, divisor, dividend); | |
| 2792 DeoptimizeIfNotZero(remainder, instr, Deoptimizer::kLostPrecision); | |
| 2793 } | |
| 2794 | |
| 2795 | |
| 2796 void LCodeGen::DoDoubleToIntOrSmi(LDoubleToIntOrSmi* instr) { | |
| 2797 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 2798 Register result = ToRegister32(instr->result()); | |
| 2799 | |
| 2800 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 2801 DeoptimizeIfMinusZero(input, instr, Deoptimizer::kMinusZero); | |
| 2802 } | |
| 2803 | |
| 2804 __ TryRepresentDoubleAsInt32(result, input, double_scratch()); | |
| 2805 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN); | |
| 2806 | |
| 2807 if (instr->tag_result()) { | |
| 2808 __ SmiTag(result.X()); | |
| 2809 } | |
| 2810 } | |
| 2811 | |
| 2812 | |
| 2813 void LCodeGen::DoDrop(LDrop* instr) { | |
| 2814 __ Drop(instr->count()); | |
| 2815 | |
| 2816 RecordPushedArgumentsDelta(instr->hydrogen_value()->argument_delta()); | |
| 2817 } | |
| 2818 | |
| 2819 | |
| 2820 void LCodeGen::DoDummy(LDummy* instr) { | |
| 2821 // Nothing to see here, move on! | |
| 2822 } | |
| 2823 | |
| 2824 | |
| 2825 void LCodeGen::DoDummyUse(LDummyUse* instr) { | |
| 2826 // Nothing to see here, move on! | |
| 2827 } | |
| 2828 | |
| 2829 | |
| 2830 void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { | |
| 2831 Register map = ToRegister(instr->map()); | |
| 2832 Register result = ToRegister(instr->result()); | |
| 2833 Label load_cache, done; | |
| 2834 | |
| 2835 __ EnumLengthUntagged(result, map); | |
| 2836 __ Cbnz(result, &load_cache); | |
| 2837 | |
| 2838 __ Mov(result, Operand(isolate()->factory()->empty_fixed_array())); | |
| 2839 __ B(&done); | |
| 2840 | |
| 2841 __ Bind(&load_cache); | |
| 2842 __ LoadInstanceDescriptors(map, result); | |
| 2843 __ Ldr(result, FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); | |
| 2844 __ Ldr(result, FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); | |
| 2845 DeoptimizeIfZero(result, instr, Deoptimizer::kNoCache); | |
| 2846 | |
| 2847 __ Bind(&done); | |
| 2848 } | |
| 2849 | |
| 2850 | |
| 2851 void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { | |
| 2852 Register object = ToRegister(instr->object()); | |
| 2853 Register null_value = x5; | |
| 2854 | |
| 2855 DCHECK(instr->IsMarkedAsCall()); | |
| 2856 DCHECK(object.Is(x0)); | |
| 2857 | |
| 2858 DeoptimizeIfSmi(object, instr, Deoptimizer::kSmi); | |
| 2859 | |
| 2860 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); | |
| 2861 __ CompareObjectType(object, x1, x1, LAST_JS_PROXY_TYPE); | |
| 2862 DeoptimizeIf(le, instr, Deoptimizer::kNotAJavaScriptObject); | |
| 2863 | |
| 2864 Label use_cache, call_runtime; | |
| 2865 __ LoadRoot(null_value, Heap::kNullValueRootIndex); | |
| 2866 __ CheckEnumCache(object, null_value, x1, x2, x3, x4, &call_runtime); | |
| 2867 | |
| 2868 __ Ldr(object, FieldMemOperand(object, HeapObject::kMapOffset)); | |
| 2869 __ B(&use_cache); | |
| 2870 | |
| 2871 // Get the set of properties to enumerate. | |
| 2872 __ Bind(&call_runtime); | |
| 2873 __ Push(object); | |
| 2874 CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); | |
| 2875 | |
| 2876 __ Ldr(x1, FieldMemOperand(object, HeapObject::kMapOffset)); | |
| 2877 DeoptimizeIfNotRoot(x1, Heap::kMetaMapRootIndex, instr, | |
| 2878 Deoptimizer::kWrongMap); | |
| 2879 | |
| 2880 __ Bind(&use_cache); | |
| 2881 } | |
| 2882 | |
| 2883 | |
| 2884 void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { | |
| 2885 Register input = ToRegister(instr->value()); | |
| 2886 Register result = ToRegister(instr->result()); | |
| 2887 | |
| 2888 __ AssertString(input); | |
| 2889 | |
| 2890 // Assert that we can use a W register load to get the hash. | |
| 2891 DCHECK((String::kHashShift + String::kArrayIndexValueBits) < kWRegSizeInBits); | |
| 2892 __ Ldr(result.W(), FieldMemOperand(input, String::kHashFieldOffset)); | |
| 2893 __ IndexFromHash(result, result); | |
| 2894 } | |
| 2895 | |
| 2896 | |
| 2897 void LCodeGen::EmitGoto(int block) { | |
| 2898 // Do not emit jump if we are emitting a goto to the next block. | |
| 2899 if (!IsNextEmittedBlock(block)) { | |
| 2900 __ B(chunk_->GetAssemblyLabel(LookupDestination(block))); | |
| 2901 } | |
| 2902 } | |
| 2903 | |
| 2904 | |
| 2905 void LCodeGen::DoGoto(LGoto* instr) { | |
| 2906 EmitGoto(instr->block_id()); | |
| 2907 } | |
| 2908 | |
| 2909 | |
| 2910 void LCodeGen::DoHasCachedArrayIndexAndBranch( | |
| 2911 LHasCachedArrayIndexAndBranch* instr) { | |
| 2912 Register input = ToRegister(instr->value()); | |
| 2913 Register temp = ToRegister32(instr->temp()); | |
| 2914 | |
| 2915 // Assert that the cache status bits fit in a W register. | |
| 2916 DCHECK(is_uint32(String::kContainsCachedArrayIndexMask)); | |
| 2917 __ Ldr(temp, FieldMemOperand(input, String::kHashFieldOffset)); | |
| 2918 __ Tst(temp, String::kContainsCachedArrayIndexMask); | |
| 2919 EmitBranch(instr, eq); | |
| 2920 } | |
| 2921 | |
| 2922 | |
| 2923 // HHasInstanceTypeAndBranch instruction is built with an interval of type | |
| 2924 // to test but is only used in very restricted ways. The only possible kinds | |
| 2925 // of intervals are: | |
| 2926 // - [ FIRST_TYPE, instr->to() ] | |
| 2927 // - [ instr->form(), LAST_TYPE ] | |
| 2928 // - instr->from() == instr->to() | |
| 2929 // | |
| 2930 // These kinds of intervals can be check with only one compare instruction | |
| 2931 // providing the correct value and test condition are used. | |
| 2932 // | |
| 2933 // TestType() will return the value to use in the compare instruction and | |
| 2934 // BranchCondition() will return the condition to use depending on the kind | |
| 2935 // of interval actually specified in the instruction. | |
| 2936 static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { | |
| 2937 InstanceType from = instr->from(); | |
| 2938 InstanceType to = instr->to(); | |
| 2939 if (from == FIRST_TYPE) return to; | |
| 2940 DCHECK((from == to) || (to == LAST_TYPE)); | |
| 2941 return from; | |
| 2942 } | |
| 2943 | |
| 2944 | |
| 2945 // See comment above TestType function for what this function does. | |
| 2946 static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { | |
| 2947 InstanceType from = instr->from(); | |
| 2948 InstanceType to = instr->to(); | |
| 2949 if (from == to) return eq; | |
| 2950 if (to == LAST_TYPE) return hs; | |
| 2951 if (from == FIRST_TYPE) return ls; | |
| 2952 UNREACHABLE(); | |
| 2953 return eq; | |
| 2954 } | |
| 2955 | |
| 2956 | |
| 2957 void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { | |
| 2958 Register input = ToRegister(instr->value()); | |
| 2959 Register scratch = ToRegister(instr->temp()); | |
| 2960 | |
| 2961 if (!instr->hydrogen()->value()->type().IsHeapObject()) { | |
| 2962 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); | |
| 2963 } | |
| 2964 __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); | |
| 2965 EmitBranch(instr, BranchCondition(instr->hydrogen())); | |
| 2966 } | |
| 2967 | |
| 2968 | |
| 2969 void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { | |
| 2970 Register result = ToRegister(instr->result()); | |
| 2971 Register base = ToRegister(instr->base_object()); | |
| 2972 if (instr->offset()->IsConstantOperand()) { | |
| 2973 __ Add(result, base, ToOperand32(instr->offset())); | |
| 2974 } else { | |
| 2975 __ Add(result, base, Operand(ToRegister32(instr->offset()), SXTW)); | |
| 2976 } | |
| 2977 } | |
| 2978 | |
| 2979 | |
| 2980 void LCodeGen::DoInstanceOf(LInstanceOf* instr) { | |
| 2981 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 2982 DCHECK(ToRegister(instr->left()).is(InstanceOfDescriptor::LeftRegister())); | |
| 2983 DCHECK(ToRegister(instr->right()).is(InstanceOfDescriptor::RightRegister())); | |
| 2984 DCHECK(ToRegister(instr->result()).is(x0)); | |
| 2985 InstanceOfStub stub(isolate()); | |
| 2986 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | |
| 2987 } | |
| 2988 | |
| 2989 | |
| 2990 void LCodeGen::DoHasInPrototypeChainAndBranch( | |
| 2991 LHasInPrototypeChainAndBranch* instr) { | |
| 2992 Register const object = ToRegister(instr->object()); | |
| 2993 Register const object_map = ToRegister(instr->scratch()); | |
| 2994 Register const object_prototype = object_map; | |
| 2995 Register const prototype = ToRegister(instr->prototype()); | |
| 2996 | |
| 2997 // The {object} must be a spec object. It's sufficient to know that {object} | |
| 2998 // is not a smi, since all other non-spec objects have {null} prototypes and | |
| 2999 // will be ruled out below. | |
| 3000 if (instr->hydrogen()->ObjectNeedsSmiCheck()) { | |
| 3001 __ JumpIfSmi(object, instr->FalseLabel(chunk_)); | |
| 3002 } | |
| 3003 | |
| 3004 // Loop through the {object}s prototype chain looking for the {prototype}. | |
| 3005 __ Ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); | |
| 3006 Label loop; | |
| 3007 __ Bind(&loop); | |
| 3008 __ Ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset)); | |
| 3009 __ Cmp(object_prototype, prototype); | |
| 3010 __ B(eq, instr->TrueLabel(chunk_)); | |
| 3011 __ CompareRoot(object_prototype, Heap::kNullValueRootIndex); | |
| 3012 __ B(eq, instr->FalseLabel(chunk_)); | |
| 3013 __ Ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset)); | |
| 3014 __ B(&loop); | |
| 3015 } | |
| 3016 | |
| 3017 | |
| 3018 void LCodeGen::DoInstructionGap(LInstructionGap* instr) { | |
| 3019 DoGap(instr); | |
| 3020 } | |
| 3021 | |
| 3022 | |
| 3023 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { | |
| 3024 Register value = ToRegister32(instr->value()); | |
| 3025 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 3026 __ Scvtf(result, value); | |
| 3027 } | |
| 3028 | |
| 3029 | |
| 3030 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { | |
| 3031 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 3032 // The function is required to be in x1. | |
| 3033 DCHECK(ToRegister(instr->function()).is(x1)); | |
| 3034 DCHECK(instr->HasPointerMap()); | |
| 3035 | |
| 3036 Handle<JSFunction> known_function = instr->hydrogen()->known_function(); | |
| 3037 if (known_function.is_null()) { | |
| 3038 LPointerMap* pointers = instr->pointer_map(); | |
| 3039 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); | |
| 3040 ParameterCount count(instr->arity()); | |
| 3041 __ InvokeFunction(x1, count, CALL_FUNCTION, generator); | |
| 3042 } else { | |
| 3043 CallKnownFunction(known_function, | |
| 3044 instr->hydrogen()->formal_parameter_count(), | |
| 3045 instr->arity(), instr); | |
| 3046 } | |
| 3047 RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta()); | |
| 3048 } | |
| 3049 | |
| 3050 | |
| 3051 void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { | |
| 3052 Register temp1 = ToRegister(instr->temp1()); | |
| 3053 Register temp2 = ToRegister(instr->temp2()); | |
| 3054 | |
| 3055 // Get the frame pointer for the calling frame. | |
| 3056 __ Ldr(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | |
| 3057 | |
| 3058 // Skip the arguments adaptor frame if it exists. | |
| 3059 Label check_frame_marker; | |
| 3060 __ Ldr(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); | |
| 3061 __ Cmp(temp2, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); | |
| 3062 __ B(ne, &check_frame_marker); | |
| 3063 __ Ldr(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset)); | |
| 3064 | |
| 3065 // Check the marker in the calling frame. | |
| 3066 __ Bind(&check_frame_marker); | |
| 3067 __ Ldr(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); | |
| 3068 | |
| 3069 EmitCompareAndBranch( | |
| 3070 instr, eq, temp1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); | |
| 3071 } | |
| 3072 | |
| 3073 | |
| 3074 Condition LCodeGen::EmitIsString(Register input, | |
| 3075 Register temp1, | |
| 3076 Label* is_not_string, | |
| 3077 SmiCheck check_needed = INLINE_SMI_CHECK) { | |
| 3078 if (check_needed == INLINE_SMI_CHECK) { | |
| 3079 __ JumpIfSmi(input, is_not_string); | |
| 3080 } | |
| 3081 __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE); | |
| 3082 | |
| 3083 return lt; | |
| 3084 } | |
| 3085 | |
| 3086 | |
| 3087 void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { | |
| 3088 Register val = ToRegister(instr->value()); | |
| 3089 Register scratch = ToRegister(instr->temp()); | |
| 3090 | |
| 3091 SmiCheck check_needed = | |
| 3092 instr->hydrogen()->value()->type().IsHeapObject() | |
| 3093 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; | |
| 3094 Condition true_cond = | |
| 3095 EmitIsString(val, scratch, instr->FalseLabel(chunk_), check_needed); | |
| 3096 | |
| 3097 EmitBranch(instr, true_cond); | |
| 3098 } | |
| 3099 | |
| 3100 | |
| 3101 void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { | |
| 3102 Register value = ToRegister(instr->value()); | |
| 3103 STATIC_ASSERT(kSmiTag == 0); | |
| 3104 EmitTestAndBranch(instr, eq, value, kSmiTagMask); | |
| 3105 } | |
| 3106 | |
| 3107 | |
| 3108 void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { | |
| 3109 Register input = ToRegister(instr->value()); | |
| 3110 Register temp = ToRegister(instr->temp()); | |
| 3111 | |
| 3112 if (!instr->hydrogen()->value()->type().IsHeapObject()) { | |
| 3113 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); | |
| 3114 } | |
| 3115 __ Ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); | |
| 3116 __ Ldrb(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); | |
| 3117 | |
| 3118 EmitTestAndBranch(instr, ne, temp, 1 << Map::kIsUndetectable); | |
| 3119 } | |
| 3120 | |
| 3121 | |
| 3122 static const char* LabelType(LLabel* label) { | |
| 3123 if (label->is_loop_header()) return " (loop header)"; | |
| 3124 if (label->is_osr_entry()) return " (OSR entry)"; | |
| 3125 return ""; | |
| 3126 } | |
| 3127 | |
| 3128 | |
| 3129 void LCodeGen::DoLabel(LLabel* label) { | |
| 3130 Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", | |
| 3131 current_instruction_, | |
| 3132 label->hydrogen_value()->id(), | |
| 3133 label->block_id(), | |
| 3134 LabelType(label)); | |
| 3135 | |
| 3136 // Inherit pushed_arguments_ from the predecessor's argument count. | |
| 3137 if (label->block()->HasPredecessor()) { | |
| 3138 pushed_arguments_ = label->block()->predecessors()->at(0)->argument_count(); | |
| 3139 #ifdef DEBUG | |
| 3140 for (auto p : *label->block()->predecessors()) { | |
| 3141 DCHECK_EQ(p->argument_count(), pushed_arguments_); | |
| 3142 } | |
| 3143 #endif | |
| 3144 } | |
| 3145 | |
| 3146 __ Bind(label->label()); | |
| 3147 current_block_ = label->block_id(); | |
| 3148 DoGap(label); | |
| 3149 } | |
| 3150 | |
| 3151 | |
| 3152 void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { | |
| 3153 Register context = ToRegister(instr->context()); | |
| 3154 Register result = ToRegister(instr->result()); | |
| 3155 __ Ldr(result, ContextMemOperand(context, instr->slot_index())); | |
| 3156 if (instr->hydrogen()->RequiresHoleCheck()) { | |
| 3157 if (instr->hydrogen()->DeoptimizesOnHole()) { | |
| 3158 DeoptimizeIfRoot(result, Heap::kTheHoleValueRootIndex, instr, | |
| 3159 Deoptimizer::kHole); | |
| 3160 } else { | |
| 3161 Label not_the_hole; | |
| 3162 __ JumpIfNotRoot(result, Heap::kTheHoleValueRootIndex, ¬_the_hole); | |
| 3163 __ LoadRoot(result, Heap::kUndefinedValueRootIndex); | |
| 3164 __ Bind(¬_the_hole); | |
| 3165 } | |
| 3166 } | |
| 3167 } | |
| 3168 | |
| 3169 | |
| 3170 void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { | |
| 3171 Register function = ToRegister(instr->function()); | |
| 3172 Register result = ToRegister(instr->result()); | |
| 3173 Register temp = ToRegister(instr->temp()); | |
| 3174 | |
| 3175 // Get the prototype or initial map from the function. | |
| 3176 __ Ldr(result, FieldMemOperand(function, | |
| 3177 JSFunction::kPrototypeOrInitialMapOffset)); | |
| 3178 | |
| 3179 // Check that the function has a prototype or an initial map. | |
| 3180 DeoptimizeIfRoot(result, Heap::kTheHoleValueRootIndex, instr, | |
| 3181 Deoptimizer::kHole); | |
| 3182 | |
| 3183 // If the function does not have an initial map, we're done. | |
| 3184 Label done; | |
| 3185 __ CompareObjectType(result, temp, temp, MAP_TYPE); | |
| 3186 __ B(ne, &done); | |
| 3187 | |
| 3188 // Get the prototype from the initial map. | |
| 3189 __ Ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); | |
| 3190 | |
| 3191 // All done. | |
| 3192 __ Bind(&done); | |
| 3193 } | |
| 3194 | |
| 3195 | |
| 3196 template <class T> | |
| 3197 void LCodeGen::EmitVectorLoadICRegisters(T* instr) { | |
| 3198 Register vector_register = ToRegister(instr->temp_vector()); | |
| 3199 Register slot_register = LoadWithVectorDescriptor::SlotRegister(); | |
| 3200 DCHECK(vector_register.is(LoadWithVectorDescriptor::VectorRegister())); | |
| 3201 DCHECK(slot_register.is(x0)); | |
| 3202 | |
| 3203 AllowDeferredHandleDereference vector_structure_check; | |
| 3204 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector(); | |
| 3205 __ Mov(vector_register, vector); | |
| 3206 // No need to allocate this register. | |
| 3207 FeedbackVectorSlot slot = instr->hydrogen()->slot(); | |
| 3208 int index = vector->GetIndex(slot); | |
| 3209 __ Mov(slot_register, Smi::FromInt(index)); | |
| 3210 } | |
| 3211 | |
| 3212 | |
| 3213 template <class T> | |
| 3214 void LCodeGen::EmitVectorStoreICRegisters(T* instr) { | |
| 3215 Register vector_register = ToRegister(instr->temp_vector()); | |
| 3216 Register slot_register = ToRegister(instr->temp_slot()); | |
| 3217 | |
| 3218 AllowDeferredHandleDereference vector_structure_check; | |
| 3219 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector(); | |
| 3220 __ Mov(vector_register, vector); | |
| 3221 FeedbackVectorSlot slot = instr->hydrogen()->slot(); | |
| 3222 int index = vector->GetIndex(slot); | |
| 3223 __ Mov(slot_register, Smi::FromInt(index)); | |
| 3224 } | |
| 3225 | |
| 3226 | |
| 3227 void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { | |
| 3228 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 3229 DCHECK(ToRegister(instr->global_object()) | |
| 3230 .is(LoadDescriptor::ReceiverRegister())); | |
| 3231 DCHECK(ToRegister(instr->result()).Is(x0)); | |
| 3232 __ Mov(LoadDescriptor::NameRegister(), Operand(instr->name())); | |
| 3233 EmitVectorLoadICRegisters<LLoadGlobalGeneric>(instr); | |
| 3234 Handle<Code> ic = | |
| 3235 CodeFactory::LoadICInOptimizedCode(isolate(), instr->typeof_mode(), | |
| 3236 SLOPPY, PREMONOMORPHIC).code(); | |
| 3237 CallCode(ic, RelocInfo::CODE_TARGET, instr); | |
| 3238 } | |
| 3239 | |
| 3240 | |
| 3241 void LCodeGen::DoLoadGlobalViaContext(LLoadGlobalViaContext* instr) { | |
| 3242 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 3243 DCHECK(ToRegister(instr->result()).is(x0)); | |
| 3244 | |
| 3245 int const slot = instr->slot_index(); | |
| 3246 int const depth = instr->depth(); | |
| 3247 if (depth <= LoadGlobalViaContextStub::kMaximumDepth) { | |
| 3248 __ Mov(LoadGlobalViaContextDescriptor::SlotRegister(), Operand(slot)); | |
| 3249 Handle<Code> stub = | |
| 3250 CodeFactory::LoadGlobalViaContext(isolate(), depth).code(); | |
| 3251 CallCode(stub, RelocInfo::CODE_TARGET, instr); | |
| 3252 } else { | |
| 3253 __ Push(Smi::FromInt(slot)); | |
| 3254 __ CallRuntime(Runtime::kLoadGlobalViaContext, 1); | |
| 3255 } | |
| 3256 } | |
| 3257 | |
| 3258 | |
| 3259 MemOperand LCodeGen::PrepareKeyedExternalArrayOperand( | |
| 3260 Register key, | |
| 3261 Register base, | |
| 3262 Register scratch, | |
| 3263 bool key_is_smi, | |
| 3264 bool key_is_constant, | |
| 3265 int constant_key, | |
| 3266 ElementsKind elements_kind, | |
| 3267 int base_offset) { | |
| 3268 int element_size_shift = ElementsKindToShiftSize(elements_kind); | |
| 3269 | |
| 3270 if (key_is_constant) { | |
| 3271 int key_offset = constant_key << element_size_shift; | |
| 3272 return MemOperand(base, key_offset + base_offset); | |
| 3273 } | |
| 3274 | |
| 3275 if (key_is_smi) { | |
| 3276 __ Add(scratch, base, Operand::UntagSmiAndScale(key, element_size_shift)); | |
| 3277 return MemOperand(scratch, base_offset); | |
| 3278 } | |
| 3279 | |
| 3280 if (base_offset == 0) { | |
| 3281 return MemOperand(base, key, SXTW, element_size_shift); | |
| 3282 } | |
| 3283 | |
| 3284 DCHECK(!AreAliased(scratch, key)); | |
| 3285 __ Add(scratch, base, base_offset); | |
| 3286 return MemOperand(scratch, key, SXTW, element_size_shift); | |
| 3287 } | |
| 3288 | |
| 3289 | |
| 3290 void LCodeGen::DoLoadKeyedExternal(LLoadKeyedExternal* instr) { | |
| 3291 Register ext_ptr = ToRegister(instr->elements()); | |
| 3292 Register scratch; | |
| 3293 ElementsKind elements_kind = instr->elements_kind(); | |
| 3294 | |
| 3295 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); | |
| 3296 bool key_is_constant = instr->key()->IsConstantOperand(); | |
| 3297 Register key = no_reg; | |
| 3298 int constant_key = 0; | |
| 3299 if (key_is_constant) { | |
| 3300 DCHECK(instr->temp() == NULL); | |
| 3301 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | |
| 3302 if (constant_key & 0xf0000000) { | |
| 3303 Abort(kArrayIndexConstantValueTooBig); | |
| 3304 } | |
| 3305 } else { | |
| 3306 scratch = ToRegister(instr->temp()); | |
| 3307 key = ToRegister(instr->key()); | |
| 3308 } | |
| 3309 | |
| 3310 MemOperand mem_op = | |
| 3311 PrepareKeyedExternalArrayOperand(key, ext_ptr, scratch, key_is_smi, | |
| 3312 key_is_constant, constant_key, | |
| 3313 elements_kind, | |
| 3314 instr->base_offset()); | |
| 3315 | |
| 3316 if (elements_kind == FLOAT32_ELEMENTS) { | |
| 3317 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 3318 __ Ldr(result.S(), mem_op); | |
| 3319 __ Fcvt(result, result.S()); | |
| 3320 } else if (elements_kind == FLOAT64_ELEMENTS) { | |
| 3321 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 3322 __ Ldr(result, mem_op); | |
| 3323 } else { | |
| 3324 Register result = ToRegister(instr->result()); | |
| 3325 | |
| 3326 switch (elements_kind) { | |
| 3327 case INT8_ELEMENTS: | |
| 3328 __ Ldrsb(result, mem_op); | |
| 3329 break; | |
| 3330 case UINT8_ELEMENTS: | |
| 3331 case UINT8_CLAMPED_ELEMENTS: | |
| 3332 __ Ldrb(result, mem_op); | |
| 3333 break; | |
| 3334 case INT16_ELEMENTS: | |
| 3335 __ Ldrsh(result, mem_op); | |
| 3336 break; | |
| 3337 case UINT16_ELEMENTS: | |
| 3338 __ Ldrh(result, mem_op); | |
| 3339 break; | |
| 3340 case INT32_ELEMENTS: | |
| 3341 __ Ldrsw(result, mem_op); | |
| 3342 break; | |
| 3343 case UINT32_ELEMENTS: | |
| 3344 __ Ldr(result.W(), mem_op); | |
| 3345 if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { | |
| 3346 // Deopt if value > 0x80000000. | |
| 3347 __ Tst(result, 0xFFFFFFFF80000000); | |
| 3348 DeoptimizeIf(ne, instr, Deoptimizer::kNegativeValue); | |
| 3349 } | |
| 3350 break; | |
| 3351 case FLOAT32_ELEMENTS: | |
| 3352 case FLOAT64_ELEMENTS: | |
| 3353 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
| 3354 case FAST_HOLEY_ELEMENTS: | |
| 3355 case FAST_HOLEY_SMI_ELEMENTS: | |
| 3356 case FAST_DOUBLE_ELEMENTS: | |
| 3357 case FAST_ELEMENTS: | |
| 3358 case FAST_SMI_ELEMENTS: | |
| 3359 case DICTIONARY_ELEMENTS: | |
| 3360 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: | |
| 3361 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: | |
| 3362 UNREACHABLE(); | |
| 3363 break; | |
| 3364 } | |
| 3365 } | |
| 3366 } | |
| 3367 | |
| 3368 | |
| 3369 MemOperand LCodeGen::PrepareKeyedArrayOperand(Register base, | |
| 3370 Register elements, | |
| 3371 Register key, | |
| 3372 bool key_is_tagged, | |
| 3373 ElementsKind elements_kind, | |
| 3374 Representation representation, | |
| 3375 int base_offset) { | |
| 3376 STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits); | |
| 3377 STATIC_ASSERT(kSmiTag == 0); | |
| 3378 int element_size_shift = ElementsKindToShiftSize(elements_kind); | |
| 3379 | |
| 3380 // Even though the HLoad/StoreKeyed instructions force the input | |
| 3381 // representation for the key to be an integer, the input gets replaced during | |
| 3382 // bounds check elimination with the index argument to the bounds check, which | |
| 3383 // can be tagged, so that case must be handled here, too. | |
| 3384 if (key_is_tagged) { | |
| 3385 __ Add(base, elements, Operand::UntagSmiAndScale(key, element_size_shift)); | |
| 3386 if (representation.IsInteger32()) { | |
| 3387 DCHECK(elements_kind == FAST_SMI_ELEMENTS); | |
| 3388 // Read or write only the smi payload in the case of fast smi arrays. | |
| 3389 return UntagSmiMemOperand(base, base_offset); | |
| 3390 } else { | |
| 3391 return MemOperand(base, base_offset); | |
| 3392 } | |
| 3393 } else { | |
| 3394 // Sign extend key because it could be a 32-bit negative value or contain | |
| 3395 // garbage in the top 32-bits. The address computation happens in 64-bit. | |
| 3396 DCHECK((element_size_shift >= 0) && (element_size_shift <= 4)); | |
| 3397 if (representation.IsInteger32()) { | |
| 3398 DCHECK(elements_kind == FAST_SMI_ELEMENTS); | |
| 3399 // Read or write only the smi payload in the case of fast smi arrays. | |
| 3400 __ Add(base, elements, Operand(key, SXTW, element_size_shift)); | |
| 3401 return UntagSmiMemOperand(base, base_offset); | |
| 3402 } else { | |
| 3403 __ Add(base, elements, base_offset); | |
| 3404 return MemOperand(base, key, SXTW, element_size_shift); | |
| 3405 } | |
| 3406 } | |
| 3407 } | |
| 3408 | |
| 3409 | |
| 3410 void LCodeGen::DoLoadKeyedFixedDouble(LLoadKeyedFixedDouble* instr) { | |
| 3411 Register elements = ToRegister(instr->elements()); | |
| 3412 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 3413 MemOperand mem_op; | |
| 3414 | |
| 3415 if (instr->key()->IsConstantOperand()) { | |
| 3416 DCHECK(instr->hydrogen()->RequiresHoleCheck() || | |
| 3417 (instr->temp() == NULL)); | |
| 3418 | |
| 3419 int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | |
| 3420 if (constant_key & 0xf0000000) { | |
| 3421 Abort(kArrayIndexConstantValueTooBig); | |
| 3422 } | |
| 3423 int offset = instr->base_offset() + constant_key * kDoubleSize; | |
| 3424 mem_op = MemOperand(elements, offset); | |
| 3425 } else { | |
| 3426 Register load_base = ToRegister(instr->temp()); | |
| 3427 Register key = ToRegister(instr->key()); | |
| 3428 bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi(); | |
| 3429 mem_op = PrepareKeyedArrayOperand(load_base, elements, key, key_is_tagged, | |
| 3430 instr->hydrogen()->elements_kind(), | |
| 3431 instr->hydrogen()->representation(), | |
| 3432 instr->base_offset()); | |
| 3433 } | |
| 3434 | |
| 3435 __ Ldr(result, mem_op); | |
| 3436 | |
| 3437 if (instr->hydrogen()->RequiresHoleCheck()) { | |
| 3438 Register scratch = ToRegister(instr->temp()); | |
| 3439 __ Fmov(scratch, result); | |
| 3440 __ Eor(scratch, scratch, kHoleNanInt64); | |
| 3441 DeoptimizeIfZero(scratch, instr, Deoptimizer::kHole); | |
| 3442 } | |
| 3443 } | |
| 3444 | |
| 3445 | |
| 3446 void LCodeGen::DoLoadKeyedFixed(LLoadKeyedFixed* instr) { | |
| 3447 Register elements = ToRegister(instr->elements()); | |
| 3448 Register result = ToRegister(instr->result()); | |
| 3449 MemOperand mem_op; | |
| 3450 | |
| 3451 Representation representation = instr->hydrogen()->representation(); | |
| 3452 if (instr->key()->IsConstantOperand()) { | |
| 3453 DCHECK(instr->temp() == NULL); | |
| 3454 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); | |
| 3455 int offset = instr->base_offset() + | |
| 3456 ToInteger32(const_operand) * kPointerSize; | |
| 3457 if (representation.IsInteger32()) { | |
| 3458 DCHECK(instr->hydrogen()->elements_kind() == FAST_SMI_ELEMENTS); | |
| 3459 STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits); | |
| 3460 STATIC_ASSERT(kSmiTag == 0); | |
| 3461 mem_op = UntagSmiMemOperand(elements, offset); | |
| 3462 } else { | |
| 3463 mem_op = MemOperand(elements, offset); | |
| 3464 } | |
| 3465 } else { | |
| 3466 Register load_base = ToRegister(instr->temp()); | |
| 3467 Register key = ToRegister(instr->key()); | |
| 3468 bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi(); | |
| 3469 | |
| 3470 mem_op = PrepareKeyedArrayOperand(load_base, elements, key, key_is_tagged, | |
| 3471 instr->hydrogen()->elements_kind(), | |
| 3472 representation, instr->base_offset()); | |
| 3473 } | |
| 3474 | |
| 3475 __ Load(result, mem_op, representation); | |
| 3476 | |
| 3477 if (instr->hydrogen()->RequiresHoleCheck()) { | |
| 3478 if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) { | |
| 3479 DeoptimizeIfNotSmi(result, instr, Deoptimizer::kNotASmi); | |
| 3480 } else { | |
| 3481 DeoptimizeIfRoot(result, Heap::kTheHoleValueRootIndex, instr, | |
| 3482 Deoptimizer::kHole); | |
| 3483 } | |
| 3484 } else if (instr->hydrogen()->hole_mode() == CONVERT_HOLE_TO_UNDEFINED) { | |
| 3485 DCHECK(instr->hydrogen()->elements_kind() == FAST_HOLEY_ELEMENTS); | |
| 3486 Label done; | |
| 3487 __ CompareRoot(result, Heap::kTheHoleValueRootIndex); | |
| 3488 __ B(ne, &done); | |
| 3489 if (info()->IsStub()) { | |
| 3490 // A stub can safely convert the hole to undefined only if the array | |
| 3491 // protector cell contains (Smi) Isolate::kArrayProtectorValid. Otherwise | |
| 3492 // it needs to bail out. | |
| 3493 __ LoadRoot(result, Heap::kArrayProtectorRootIndex); | |
| 3494 __ Ldr(result, FieldMemOperand(result, Cell::kValueOffset)); | |
| 3495 __ Cmp(result, Operand(Smi::FromInt(Isolate::kArrayProtectorValid))); | |
| 3496 DeoptimizeIf(ne, instr, Deoptimizer::kHole); | |
| 3497 } | |
| 3498 __ LoadRoot(result, Heap::kUndefinedValueRootIndex); | |
| 3499 __ Bind(&done); | |
| 3500 } | |
| 3501 } | |
| 3502 | |
| 3503 | |
| 3504 void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { | |
| 3505 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 3506 DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister())); | |
| 3507 DCHECK(ToRegister(instr->key()).is(LoadDescriptor::NameRegister())); | |
| 3508 | |
| 3509 if (instr->hydrogen()->HasVectorAndSlot()) { | |
| 3510 EmitVectorLoadICRegisters<LLoadKeyedGeneric>(instr); | |
| 3511 } | |
| 3512 | |
| 3513 Handle<Code> ic = CodeFactory::KeyedLoadICInOptimizedCode( | |
| 3514 isolate(), instr->hydrogen()->language_mode(), | |
| 3515 instr->hydrogen()->initialization_state()).code(); | |
| 3516 CallCode(ic, RelocInfo::CODE_TARGET, instr); | |
| 3517 | |
| 3518 DCHECK(ToRegister(instr->result()).Is(x0)); | |
| 3519 } | |
| 3520 | |
| 3521 | |
| 3522 void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { | |
| 3523 HObjectAccess access = instr->hydrogen()->access(); | |
| 3524 int offset = access.offset(); | |
| 3525 Register object = ToRegister(instr->object()); | |
| 3526 | |
| 3527 if (access.IsExternalMemory()) { | |
| 3528 Register result = ToRegister(instr->result()); | |
| 3529 __ Load(result, MemOperand(object, offset), access.representation()); | |
| 3530 return; | |
| 3531 } | |
| 3532 | |
| 3533 if (instr->hydrogen()->representation().IsDouble()) { | |
| 3534 DCHECK(access.IsInobject()); | |
| 3535 FPRegister result = ToDoubleRegister(instr->result()); | |
| 3536 __ Ldr(result, FieldMemOperand(object, offset)); | |
| 3537 return; | |
| 3538 } | |
| 3539 | |
| 3540 Register result = ToRegister(instr->result()); | |
| 3541 Register source; | |
| 3542 if (access.IsInobject()) { | |
| 3543 source = object; | |
| 3544 } else { | |
| 3545 // Load the properties array, using result as a scratch register. | |
| 3546 __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | |
| 3547 source = result; | |
| 3548 } | |
| 3549 | |
| 3550 if (access.representation().IsSmi() && | |
| 3551 instr->hydrogen()->representation().IsInteger32()) { | |
| 3552 // Read int value directly from upper half of the smi. | |
| 3553 STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits); | |
| 3554 STATIC_ASSERT(kSmiTag == 0); | |
| 3555 __ Load(result, UntagSmiFieldMemOperand(source, offset), | |
| 3556 Representation::Integer32()); | |
| 3557 } else { | |
| 3558 __ Load(result, FieldMemOperand(source, offset), access.representation()); | |
| 3559 } | |
| 3560 } | |
| 3561 | |
| 3562 | |
| 3563 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { | |
| 3564 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 3565 // LoadIC expects name and receiver in registers. | |
| 3566 DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister())); | |
| 3567 __ Mov(LoadDescriptor::NameRegister(), Operand(instr->name())); | |
| 3568 EmitVectorLoadICRegisters<LLoadNamedGeneric>(instr); | |
| 3569 Handle<Code> ic = | |
| 3570 CodeFactory::LoadICInOptimizedCode( | |
| 3571 isolate(), NOT_INSIDE_TYPEOF, instr->hydrogen()->language_mode(), | |
| 3572 instr->hydrogen()->initialization_state()).code(); | |
| 3573 CallCode(ic, RelocInfo::CODE_TARGET, instr); | |
| 3574 | |
| 3575 DCHECK(ToRegister(instr->result()).is(x0)); | |
| 3576 } | |
| 3577 | |
| 3578 | |
| 3579 void LCodeGen::DoLoadRoot(LLoadRoot* instr) { | |
| 3580 Register result = ToRegister(instr->result()); | |
| 3581 __ LoadRoot(result, instr->index()); | |
| 3582 } | |
| 3583 | |
| 3584 | |
| 3585 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { | |
| 3586 Register result = ToRegister(instr->result()); | |
| 3587 Register map = ToRegister(instr->value()); | |
| 3588 __ EnumLengthSmi(result, map); | |
| 3589 } | |
| 3590 | |
| 3591 | |
| 3592 void LCodeGen::DoMathAbs(LMathAbs* instr) { | |
| 3593 Representation r = instr->hydrogen()->value()->representation(); | |
| 3594 if (r.IsDouble()) { | |
| 3595 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 3596 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 3597 __ Fabs(result, input); | |
| 3598 } else if (r.IsSmi() || r.IsInteger32()) { | |
| 3599 Register input = r.IsSmi() ? ToRegister(instr->value()) | |
| 3600 : ToRegister32(instr->value()); | |
| 3601 Register result = r.IsSmi() ? ToRegister(instr->result()) | |
| 3602 : ToRegister32(instr->result()); | |
| 3603 __ Abs(result, input); | |
| 3604 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 3605 } | |
| 3606 } | |
| 3607 | |
| 3608 | |
| 3609 void LCodeGen::DoDeferredMathAbsTagged(LMathAbsTagged* instr, | |
| 3610 Label* exit, | |
| 3611 Label* allocation_entry) { | |
| 3612 // Handle the tricky cases of MathAbsTagged: | |
| 3613 // - HeapNumber inputs. | |
| 3614 // - Negative inputs produce a positive result, so a new HeapNumber is | |
| 3615 // allocated to hold it. | |
| 3616 // - Positive inputs are returned as-is, since there is no need to allocate | |
| 3617 // a new HeapNumber for the result. | |
| 3618 // - The (smi) input -0x80000000, produces +0x80000000, which does not fit | |
| 3619 // a smi. In this case, the inline code sets the result and jumps directly | |
| 3620 // to the allocation_entry label. | |
| 3621 DCHECK(instr->context() != NULL); | |
| 3622 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 3623 Register input = ToRegister(instr->value()); | |
| 3624 Register temp1 = ToRegister(instr->temp1()); | |
| 3625 Register temp2 = ToRegister(instr->temp2()); | |
| 3626 Register result_bits = ToRegister(instr->temp3()); | |
| 3627 Register result = ToRegister(instr->result()); | |
| 3628 | |
| 3629 Label runtime_allocation; | |
| 3630 | |
| 3631 // Deoptimize if the input is not a HeapNumber. | |
| 3632 DeoptimizeIfNotHeapNumber(input, instr); | |
| 3633 | |
| 3634 // If the argument is positive, we can return it as-is, without any need to | |
| 3635 // allocate a new HeapNumber for the result. We have to do this in integer | |
| 3636 // registers (rather than with fabs) because we need to be able to distinguish | |
| 3637 // the two zeroes. | |
| 3638 __ Ldr(result_bits, FieldMemOperand(input, HeapNumber::kValueOffset)); | |
| 3639 __ Mov(result, input); | |
| 3640 __ Tbz(result_bits, kXSignBit, exit); | |
| 3641 | |
| 3642 // Calculate abs(input) by clearing the sign bit. | |
| 3643 __ Bic(result_bits, result_bits, kXSignMask); | |
| 3644 | |
| 3645 // Allocate a new HeapNumber to hold the result. | |
| 3646 // result_bits The bit representation of the (double) result. | |
| 3647 __ Bind(allocation_entry); | |
| 3648 __ AllocateHeapNumber(result, &runtime_allocation, temp1, temp2); | |
| 3649 // The inline (non-deferred) code will store result_bits into result. | |
| 3650 __ B(exit); | |
| 3651 | |
| 3652 __ Bind(&runtime_allocation); | |
| 3653 if (FLAG_debug_code) { | |
| 3654 // Because result is in the pointer map, we need to make sure it has a valid | |
| 3655 // tagged value before we call the runtime. We speculatively set it to the | |
| 3656 // input (for abs(+x)) or to a smi (for abs(-SMI_MIN)), so it should already | |
| 3657 // be valid. | |
| 3658 Label result_ok; | |
| 3659 Register input = ToRegister(instr->value()); | |
| 3660 __ JumpIfSmi(result, &result_ok); | |
| 3661 __ Cmp(input, result); | |
| 3662 __ Assert(eq, kUnexpectedValue); | |
| 3663 __ Bind(&result_ok); | |
| 3664 } | |
| 3665 | |
| 3666 { PushSafepointRegistersScope scope(this); | |
| 3667 CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr, | |
| 3668 instr->context()); | |
| 3669 __ StoreToSafepointRegisterSlot(x0, result); | |
| 3670 } | |
| 3671 // The inline (non-deferred) code will store result_bits into result. | |
| 3672 } | |
| 3673 | |
| 3674 | |
| 3675 void LCodeGen::DoMathAbsTagged(LMathAbsTagged* instr) { | |
| 3676 // Class for deferred case. | |
| 3677 class DeferredMathAbsTagged: public LDeferredCode { | |
| 3678 public: | |
| 3679 DeferredMathAbsTagged(LCodeGen* codegen, LMathAbsTagged* instr) | |
| 3680 : LDeferredCode(codegen), instr_(instr) { } | |
| 3681 virtual void Generate() { | |
| 3682 codegen()->DoDeferredMathAbsTagged(instr_, exit(), | |
| 3683 allocation_entry()); | |
| 3684 } | |
| 3685 virtual LInstruction* instr() { return instr_; } | |
| 3686 Label* allocation_entry() { return &allocation; } | |
| 3687 private: | |
| 3688 LMathAbsTagged* instr_; | |
| 3689 Label allocation; | |
| 3690 }; | |
| 3691 | |
| 3692 // TODO(jbramley): The early-exit mechanism would skip the new frame handling | |
| 3693 // in GenerateDeferredCode. Tidy this up. | |
| 3694 DCHECK(!NeedsDeferredFrame()); | |
| 3695 | |
| 3696 DeferredMathAbsTagged* deferred = | |
| 3697 new(zone()) DeferredMathAbsTagged(this, instr); | |
| 3698 | |
| 3699 DCHECK(instr->hydrogen()->value()->representation().IsTagged() || | |
| 3700 instr->hydrogen()->value()->representation().IsSmi()); | |
| 3701 Register input = ToRegister(instr->value()); | |
| 3702 Register result_bits = ToRegister(instr->temp3()); | |
| 3703 Register result = ToRegister(instr->result()); | |
| 3704 Label done; | |
| 3705 | |
| 3706 // Handle smis inline. | |
| 3707 // We can treat smis as 64-bit integers, since the (low-order) tag bits will | |
| 3708 // never get set by the negation. This is therefore the same as the Integer32 | |
| 3709 // case in DoMathAbs, except that it operates on 64-bit values. | |
| 3710 STATIC_ASSERT((kSmiValueSize == 32) && (kSmiShift == 32) && (kSmiTag == 0)); | |
| 3711 | |
| 3712 __ JumpIfNotSmi(input, deferred->entry()); | |
| 3713 | |
| 3714 __ Abs(result, input, NULL, &done); | |
| 3715 | |
| 3716 // The result is the magnitude (abs) of the smallest value a smi can | |
| 3717 // represent, encoded as a double. | |
| 3718 __ Mov(result_bits, double_to_rawbits(0x80000000)); | |
| 3719 __ B(deferred->allocation_entry()); | |
| 3720 | |
| 3721 __ Bind(deferred->exit()); | |
| 3722 __ Str(result_bits, FieldMemOperand(result, HeapNumber::kValueOffset)); | |
| 3723 | |
| 3724 __ Bind(&done); | |
| 3725 } | |
| 3726 | |
| 3727 | |
| 3728 void LCodeGen::DoMathExp(LMathExp* instr) { | |
| 3729 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 3730 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 3731 DoubleRegister double_temp1 = ToDoubleRegister(instr->double_temp1()); | |
| 3732 DoubleRegister double_temp2 = double_scratch(); | |
| 3733 Register temp1 = ToRegister(instr->temp1()); | |
| 3734 Register temp2 = ToRegister(instr->temp2()); | |
| 3735 Register temp3 = ToRegister(instr->temp3()); | |
| 3736 | |
| 3737 MathExpGenerator::EmitMathExp(masm(), input, result, | |
| 3738 double_temp1, double_temp2, | |
| 3739 temp1, temp2, temp3); | |
| 3740 } | |
| 3741 | |
| 3742 | |
| 3743 void LCodeGen::DoMathFloorD(LMathFloorD* instr) { | |
| 3744 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 3745 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 3746 | |
| 3747 __ Frintm(result, input); | |
| 3748 } | |
| 3749 | |
| 3750 | |
| 3751 void LCodeGen::DoMathFloorI(LMathFloorI* instr) { | |
| 3752 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 3753 Register result = ToRegister(instr->result()); | |
| 3754 | |
| 3755 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 3756 DeoptimizeIfMinusZero(input, instr, Deoptimizer::kMinusZero); | |
| 3757 } | |
| 3758 | |
| 3759 __ Fcvtms(result, input); | |
| 3760 | |
| 3761 // Check that the result fits into a 32-bit integer. | |
| 3762 // - The result did not overflow. | |
| 3763 __ Cmp(result, Operand(result, SXTW)); | |
| 3764 // - The input was not NaN. | |
| 3765 __ Fccmp(input, input, NoFlag, eq); | |
| 3766 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN); | |
| 3767 } | |
| 3768 | |
| 3769 | |
| 3770 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { | |
| 3771 Register dividend = ToRegister32(instr->dividend()); | |
| 3772 Register result = ToRegister32(instr->result()); | |
| 3773 int32_t divisor = instr->divisor(); | |
| 3774 | |
| 3775 // If the divisor is 1, return the dividend. | |
| 3776 if (divisor == 1) { | |
| 3777 __ Mov(result, dividend, kDiscardForSameWReg); | |
| 3778 return; | |
| 3779 } | |
| 3780 | |
| 3781 // If the divisor is positive, things are easy: There can be no deopts and we | |
| 3782 // can simply do an arithmetic right shift. | |
| 3783 int32_t shift = WhichPowerOf2Abs(divisor); | |
| 3784 if (divisor > 1) { | |
| 3785 __ Mov(result, Operand(dividend, ASR, shift)); | |
| 3786 return; | |
| 3787 } | |
| 3788 | |
| 3789 // If the divisor is negative, we have to negate and handle edge cases. | |
| 3790 __ Negs(result, dividend); | |
| 3791 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 3792 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); | |
| 3793 } | |
| 3794 | |
| 3795 // Dividing by -1 is basically negation, unless we overflow. | |
| 3796 if (divisor == -1) { | |
| 3797 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { | |
| 3798 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 3799 } | |
| 3800 return; | |
| 3801 } | |
| 3802 | |
| 3803 // If the negation could not overflow, simply shifting is OK. | |
| 3804 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { | |
| 3805 __ Mov(result, Operand(dividend, ASR, shift)); | |
| 3806 return; | |
| 3807 } | |
| 3808 | |
| 3809 __ Asr(result, result, shift); | |
| 3810 __ Csel(result, result, kMinInt / divisor, vc); | |
| 3811 } | |
| 3812 | |
| 3813 | |
| 3814 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { | |
| 3815 Register dividend = ToRegister32(instr->dividend()); | |
| 3816 int32_t divisor = instr->divisor(); | |
| 3817 Register result = ToRegister32(instr->result()); | |
| 3818 DCHECK(!AreAliased(dividend, result)); | |
| 3819 | |
| 3820 if (divisor == 0) { | |
| 3821 Deoptimize(instr, Deoptimizer::kDivisionByZero); | |
| 3822 return; | |
| 3823 } | |
| 3824 | |
| 3825 // Check for (0 / -x) that will produce negative zero. | |
| 3826 HMathFloorOfDiv* hdiv = instr->hydrogen(); | |
| 3827 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | |
| 3828 DeoptimizeIfZero(dividend, instr, Deoptimizer::kMinusZero); | |
| 3829 } | |
| 3830 | |
| 3831 // Easy case: We need no dynamic check for the dividend and the flooring | |
| 3832 // division is the same as the truncating division. | |
| 3833 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || | |
| 3834 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { | |
| 3835 __ TruncatingDiv(result, dividend, Abs(divisor)); | |
| 3836 if (divisor < 0) __ Neg(result, result); | |
| 3837 return; | |
| 3838 } | |
| 3839 | |
| 3840 // In the general case we may need to adjust before and after the truncating | |
| 3841 // division to get a flooring division. | |
| 3842 Register temp = ToRegister32(instr->temp()); | |
| 3843 DCHECK(!AreAliased(temp, dividend, result)); | |
| 3844 Label needs_adjustment, done; | |
| 3845 __ Cmp(dividend, 0); | |
| 3846 __ B(divisor > 0 ? lt : gt, &needs_adjustment); | |
| 3847 __ TruncatingDiv(result, dividend, Abs(divisor)); | |
| 3848 if (divisor < 0) __ Neg(result, result); | |
| 3849 __ B(&done); | |
| 3850 __ Bind(&needs_adjustment); | |
| 3851 __ Add(temp, dividend, Operand(divisor > 0 ? 1 : -1)); | |
| 3852 __ TruncatingDiv(result, temp, Abs(divisor)); | |
| 3853 if (divisor < 0) __ Neg(result, result); | |
| 3854 __ Sub(result, result, Operand(1)); | |
| 3855 __ Bind(&done); | |
| 3856 } | |
| 3857 | |
| 3858 | |
| 3859 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. | |
| 3860 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { | |
| 3861 Register dividend = ToRegister32(instr->dividend()); | |
| 3862 Register divisor = ToRegister32(instr->divisor()); | |
| 3863 Register remainder = ToRegister32(instr->temp()); | |
| 3864 Register result = ToRegister32(instr->result()); | |
| 3865 | |
| 3866 // This can't cause an exception on ARM, so we can speculatively | |
| 3867 // execute it already now. | |
| 3868 __ Sdiv(result, dividend, divisor); | |
| 3869 | |
| 3870 // Check for x / 0. | |
| 3871 DeoptimizeIfZero(divisor, instr, Deoptimizer::kDivisionByZero); | |
| 3872 | |
| 3873 // Check for (kMinInt / -1). | |
| 3874 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { | |
| 3875 // The V flag will be set iff dividend == kMinInt. | |
| 3876 __ Cmp(dividend, 1); | |
| 3877 __ Ccmp(divisor, -1, NoFlag, vs); | |
| 3878 DeoptimizeIf(eq, instr, Deoptimizer::kOverflow); | |
| 3879 } | |
| 3880 | |
| 3881 // Check for (0 / -x) that will produce negative zero. | |
| 3882 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 3883 __ Cmp(divisor, 0); | |
| 3884 __ Ccmp(dividend, 0, ZFlag, mi); | |
| 3885 // "divisor" can't be null because the code would have already been | |
| 3886 // deoptimized. The Z flag is set only if (divisor < 0) and (dividend == 0). | |
| 3887 // In this case we need to deoptimize to produce a -0. | |
| 3888 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); | |
| 3889 } | |
| 3890 | |
| 3891 Label done; | |
| 3892 // If both operands have the same sign then we are done. | |
| 3893 __ Eor(remainder, dividend, divisor); | |
| 3894 __ Tbz(remainder, kWSignBit, &done); | |
| 3895 | |
| 3896 // Check if the result needs to be corrected. | |
| 3897 __ Msub(remainder, result, divisor, dividend); | |
| 3898 __ Cbz(remainder, &done); | |
| 3899 __ Sub(result, result, 1); | |
| 3900 | |
| 3901 __ Bind(&done); | |
| 3902 } | |
| 3903 | |
| 3904 | |
| 3905 void LCodeGen::DoMathLog(LMathLog* instr) { | |
| 3906 DCHECK(instr->IsMarkedAsCall()); | |
| 3907 DCHECK(ToDoubleRegister(instr->value()).is(d0)); | |
| 3908 __ CallCFunction(ExternalReference::math_log_double_function(isolate()), | |
| 3909 0, 1); | |
| 3910 DCHECK(ToDoubleRegister(instr->result()).Is(d0)); | |
| 3911 } | |
| 3912 | |
| 3913 | |
| 3914 void LCodeGen::DoMathClz32(LMathClz32* instr) { | |
| 3915 Register input = ToRegister32(instr->value()); | |
| 3916 Register result = ToRegister32(instr->result()); | |
| 3917 __ Clz(result, input); | |
| 3918 } | |
| 3919 | |
| 3920 | |
| 3921 void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { | |
| 3922 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 3923 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 3924 Label done; | |
| 3925 | |
| 3926 // Math.pow(x, 0.5) differs from fsqrt(x) in the following cases: | |
| 3927 // Math.pow(-Infinity, 0.5) == +Infinity | |
| 3928 // Math.pow(-0.0, 0.5) == +0.0 | |
| 3929 | |
| 3930 // Catch -infinity inputs first. | |
| 3931 // TODO(jbramley): A constant infinity register would be helpful here. | |
| 3932 __ Fmov(double_scratch(), kFP64NegativeInfinity); | |
| 3933 __ Fcmp(double_scratch(), input); | |
| 3934 __ Fabs(result, input); | |
| 3935 __ B(&done, eq); | |
| 3936 | |
| 3937 // Add +0.0 to convert -0.0 to +0.0. | |
| 3938 __ Fadd(double_scratch(), input, fp_zero); | |
| 3939 __ Fsqrt(result, double_scratch()); | |
| 3940 | |
| 3941 __ Bind(&done); | |
| 3942 } | |
| 3943 | |
| 3944 | |
| 3945 void LCodeGen::DoPower(LPower* instr) { | |
| 3946 Representation exponent_type = instr->hydrogen()->right()->representation(); | |
| 3947 // Having marked this as a call, we can use any registers. | |
| 3948 // Just make sure that the input/output registers are the expected ones. | |
| 3949 Register tagged_exponent = MathPowTaggedDescriptor::exponent(); | |
| 3950 Register integer_exponent = MathPowIntegerDescriptor::exponent(); | |
| 3951 DCHECK(!instr->right()->IsDoubleRegister() || | |
| 3952 ToDoubleRegister(instr->right()).is(d1)); | |
| 3953 DCHECK(exponent_type.IsInteger32() || !instr->right()->IsRegister() || | |
| 3954 ToRegister(instr->right()).is(tagged_exponent)); | |
| 3955 DCHECK(!exponent_type.IsInteger32() || | |
| 3956 ToRegister(instr->right()).is(integer_exponent)); | |
| 3957 DCHECK(ToDoubleRegister(instr->left()).is(d0)); | |
| 3958 DCHECK(ToDoubleRegister(instr->result()).is(d0)); | |
| 3959 | |
| 3960 if (exponent_type.IsSmi()) { | |
| 3961 MathPowStub stub(isolate(), MathPowStub::TAGGED); | |
| 3962 __ CallStub(&stub); | |
| 3963 } else if (exponent_type.IsTagged()) { | |
| 3964 Label no_deopt; | |
| 3965 __ JumpIfSmi(tagged_exponent, &no_deopt); | |
| 3966 DeoptimizeIfNotHeapNumber(tagged_exponent, instr); | |
| 3967 __ Bind(&no_deopt); | |
| 3968 MathPowStub stub(isolate(), MathPowStub::TAGGED); | |
| 3969 __ CallStub(&stub); | |
| 3970 } else if (exponent_type.IsInteger32()) { | |
| 3971 // Ensure integer exponent has no garbage in top 32-bits, as MathPowStub | |
| 3972 // supports large integer exponents. | |
| 3973 __ Sxtw(integer_exponent, integer_exponent); | |
| 3974 MathPowStub stub(isolate(), MathPowStub::INTEGER); | |
| 3975 __ CallStub(&stub); | |
| 3976 } else { | |
| 3977 DCHECK(exponent_type.IsDouble()); | |
| 3978 MathPowStub stub(isolate(), MathPowStub::DOUBLE); | |
| 3979 __ CallStub(&stub); | |
| 3980 } | |
| 3981 } | |
| 3982 | |
| 3983 | |
| 3984 void LCodeGen::DoMathRoundD(LMathRoundD* instr) { | |
| 3985 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 3986 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 3987 DoubleRegister scratch_d = double_scratch(); | |
| 3988 | |
| 3989 DCHECK(!AreAliased(input, result, scratch_d)); | |
| 3990 | |
| 3991 Label done; | |
| 3992 | |
| 3993 __ Frinta(result, input); | |
| 3994 __ Fcmp(input, 0.0); | |
| 3995 __ Fccmp(result, input, ZFlag, lt); | |
| 3996 // The result is correct if the input was in [-0, +infinity], or was a | |
| 3997 // negative integral value. | |
| 3998 __ B(eq, &done); | |
| 3999 | |
| 4000 // Here the input is negative, non integral, with an exponent lower than 52. | |
| 4001 // We do not have to worry about the 0.49999999999999994 (0x3fdfffffffffffff) | |
| 4002 // case. So we can safely add 0.5. | |
| 4003 __ Fmov(scratch_d, 0.5); | |
| 4004 __ Fadd(result, input, scratch_d); | |
| 4005 __ Frintm(result, result); | |
| 4006 // The range [-0.5, -0.0[ yielded +0.0. Force the sign to negative. | |
| 4007 __ Fabs(result, result); | |
| 4008 __ Fneg(result, result); | |
| 4009 | |
| 4010 __ Bind(&done); | |
| 4011 } | |
| 4012 | |
| 4013 | |
| 4014 void LCodeGen::DoMathRoundI(LMathRoundI* instr) { | |
| 4015 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 4016 DoubleRegister temp = ToDoubleRegister(instr->temp1()); | |
| 4017 DoubleRegister dot_five = double_scratch(); | |
| 4018 Register result = ToRegister(instr->result()); | |
| 4019 Label done; | |
| 4020 | |
| 4021 // Math.round() rounds to the nearest integer, with ties going towards | |
| 4022 // +infinity. This does not match any IEEE-754 rounding mode. | |
| 4023 // - Infinities and NaNs are propagated unchanged, but cause deopts because | |
| 4024 // they can't be represented as integers. | |
| 4025 // - The sign of the result is the same as the sign of the input. This means | |
| 4026 // that -0.0 rounds to itself, and values -0.5 <= input < 0 also produce a | |
| 4027 // result of -0.0. | |
| 4028 | |
| 4029 // Add 0.5 and round towards -infinity. | |
| 4030 __ Fmov(dot_five, 0.5); | |
| 4031 __ Fadd(temp, input, dot_five); | |
| 4032 __ Fcvtms(result, temp); | |
| 4033 | |
| 4034 // The result is correct if: | |
| 4035 // result is not 0, as the input could be NaN or [-0.5, -0.0]. | |
| 4036 // result is not 1, as 0.499...94 will wrongly map to 1. | |
| 4037 // result fits in 32 bits. | |
| 4038 __ Cmp(result, Operand(result.W(), SXTW)); | |
| 4039 __ Ccmp(result, 1, ZFlag, eq); | |
| 4040 __ B(hi, &done); | |
| 4041 | |
| 4042 // At this point, we have to handle possible inputs of NaN or numbers in the | |
| 4043 // range [-0.5, 1.5[, or numbers larger than 32 bits. | |
| 4044 | |
| 4045 // Deoptimize if the result > 1, as it must be larger than 32 bits. | |
| 4046 __ Cmp(result, 1); | |
| 4047 DeoptimizeIf(hi, instr, Deoptimizer::kOverflow); | |
| 4048 | |
| 4049 // Deoptimize for negative inputs, which at this point are only numbers in | |
| 4050 // the range [-0.5, -0.0] | |
| 4051 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 4052 __ Fmov(result, input); | |
| 4053 DeoptimizeIfNegative(result, instr, Deoptimizer::kMinusZero); | |
| 4054 } | |
| 4055 | |
| 4056 // Deoptimize if the input was NaN. | |
| 4057 __ Fcmp(input, dot_five); | |
| 4058 DeoptimizeIf(vs, instr, Deoptimizer::kNaN); | |
| 4059 | |
| 4060 // Now, the only unhandled inputs are in the range [0.0, 1.5[ (or [-0.5, 1.5[ | |
| 4061 // if we didn't generate a -0.0 bailout). If input >= 0.5 then return 1, | |
| 4062 // else 0; we avoid dealing with 0.499...94 directly. | |
| 4063 __ Cset(result, ge); | |
| 4064 __ Bind(&done); | |
| 4065 } | |
| 4066 | |
| 4067 | |
| 4068 void LCodeGen::DoMathFround(LMathFround* instr) { | |
| 4069 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 4070 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 4071 __ Fcvt(result.S(), input); | |
| 4072 __ Fcvt(result, result.S()); | |
| 4073 } | |
| 4074 | |
| 4075 | |
| 4076 void LCodeGen::DoMathSqrt(LMathSqrt* instr) { | |
| 4077 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 4078 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 4079 __ Fsqrt(result, input); | |
| 4080 } | |
| 4081 | |
| 4082 | |
| 4083 void LCodeGen::DoMathMinMax(LMathMinMax* instr) { | |
| 4084 HMathMinMax::Operation op = instr->hydrogen()->operation(); | |
| 4085 if (instr->hydrogen()->representation().IsInteger32()) { | |
| 4086 Register result = ToRegister32(instr->result()); | |
| 4087 Register left = ToRegister32(instr->left()); | |
| 4088 Operand right = ToOperand32(instr->right()); | |
| 4089 | |
| 4090 __ Cmp(left, right); | |
| 4091 __ Csel(result, left, right, (op == HMathMinMax::kMathMax) ? ge : le); | |
| 4092 } else if (instr->hydrogen()->representation().IsSmi()) { | |
| 4093 Register result = ToRegister(instr->result()); | |
| 4094 Register left = ToRegister(instr->left()); | |
| 4095 Operand right = ToOperand(instr->right()); | |
| 4096 | |
| 4097 __ Cmp(left, right); | |
| 4098 __ Csel(result, left, right, (op == HMathMinMax::kMathMax) ? ge : le); | |
| 4099 } else { | |
| 4100 DCHECK(instr->hydrogen()->representation().IsDouble()); | |
| 4101 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 4102 DoubleRegister left = ToDoubleRegister(instr->left()); | |
| 4103 DoubleRegister right = ToDoubleRegister(instr->right()); | |
| 4104 | |
| 4105 if (op == HMathMinMax::kMathMax) { | |
| 4106 __ Fmax(result, left, right); | |
| 4107 } else { | |
| 4108 DCHECK(op == HMathMinMax::kMathMin); | |
| 4109 __ Fmin(result, left, right); | |
| 4110 } | |
| 4111 } | |
| 4112 } | |
| 4113 | |
| 4114 | |
| 4115 void LCodeGen::DoModByPowerOf2I(LModByPowerOf2I* instr) { | |
| 4116 Register dividend = ToRegister32(instr->dividend()); | |
| 4117 int32_t divisor = instr->divisor(); | |
| 4118 DCHECK(dividend.is(ToRegister32(instr->result()))); | |
| 4119 | |
| 4120 // Theoretically, a variation of the branch-free code for integer division by | |
| 4121 // a power of 2 (calculating the remainder via an additional multiplication | |
| 4122 // (which gets simplified to an 'and') and subtraction) should be faster, and | |
| 4123 // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to | |
| 4124 // indicate that positive dividends are heavily favored, so the branching | |
| 4125 // version performs better. | |
| 4126 HMod* hmod = instr->hydrogen(); | |
| 4127 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); | |
| 4128 Label dividend_is_not_negative, done; | |
| 4129 if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) { | |
| 4130 __ Tbz(dividend, kWSignBit, ÷nd_is_not_negative); | |
| 4131 // Note that this is correct even for kMinInt operands. | |
| 4132 __ Neg(dividend, dividend); | |
| 4133 __ And(dividend, dividend, mask); | |
| 4134 __ Negs(dividend, dividend); | |
| 4135 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 4136 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); | |
| 4137 } | |
| 4138 __ B(&done); | |
| 4139 } | |
| 4140 | |
| 4141 __ bind(÷nd_is_not_negative); | |
| 4142 __ And(dividend, dividend, mask); | |
| 4143 __ bind(&done); | |
| 4144 } | |
| 4145 | |
| 4146 | |
| 4147 void LCodeGen::DoModByConstI(LModByConstI* instr) { | |
| 4148 Register dividend = ToRegister32(instr->dividend()); | |
| 4149 int32_t divisor = instr->divisor(); | |
| 4150 Register result = ToRegister32(instr->result()); | |
| 4151 Register temp = ToRegister32(instr->temp()); | |
| 4152 DCHECK(!AreAliased(dividend, result, temp)); | |
| 4153 | |
| 4154 if (divisor == 0) { | |
| 4155 Deoptimize(instr, Deoptimizer::kDivisionByZero); | |
| 4156 return; | |
| 4157 } | |
| 4158 | |
| 4159 __ TruncatingDiv(result, dividend, Abs(divisor)); | |
| 4160 __ Sxtw(dividend.X(), dividend); | |
| 4161 __ Mov(temp, Abs(divisor)); | |
| 4162 __ Smsubl(result.X(), result, temp, dividend.X()); | |
| 4163 | |
| 4164 // Check for negative zero. | |
| 4165 HMod* hmod = instr->hydrogen(); | |
| 4166 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 4167 Label remainder_not_zero; | |
| 4168 __ Cbnz(result, &remainder_not_zero); | |
| 4169 DeoptimizeIfNegative(dividend, instr, Deoptimizer::kMinusZero); | |
| 4170 __ bind(&remainder_not_zero); | |
| 4171 } | |
| 4172 } | |
| 4173 | |
| 4174 | |
| 4175 void LCodeGen::DoModI(LModI* instr) { | |
| 4176 Register dividend = ToRegister32(instr->left()); | |
| 4177 Register divisor = ToRegister32(instr->right()); | |
| 4178 Register result = ToRegister32(instr->result()); | |
| 4179 | |
| 4180 Label done; | |
| 4181 // modulo = dividend - quotient * divisor | |
| 4182 __ Sdiv(result, dividend, divisor); | |
| 4183 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { | |
| 4184 DeoptimizeIfZero(divisor, instr, Deoptimizer::kDivisionByZero); | |
| 4185 } | |
| 4186 __ Msub(result, result, divisor, dividend); | |
| 4187 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 4188 __ Cbnz(result, &done); | |
| 4189 DeoptimizeIfNegative(dividend, instr, Deoptimizer::kMinusZero); | |
| 4190 } | |
| 4191 __ Bind(&done); | |
| 4192 } | |
| 4193 | |
| 4194 | |
| 4195 void LCodeGen::DoMulConstIS(LMulConstIS* instr) { | |
| 4196 DCHECK(instr->hydrogen()->representation().IsSmiOrInteger32()); | |
| 4197 bool is_smi = instr->hydrogen()->representation().IsSmi(); | |
| 4198 Register result = | |
| 4199 is_smi ? ToRegister(instr->result()) : ToRegister32(instr->result()); | |
| 4200 Register left = | |
| 4201 is_smi ? ToRegister(instr->left()) : ToRegister32(instr->left()); | |
| 4202 int32_t right = ToInteger32(instr->right()); | |
| 4203 DCHECK((right > -kMaxInt) && (right < kMaxInt)); | |
| 4204 | |
| 4205 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | |
| 4206 bool bailout_on_minus_zero = | |
| 4207 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); | |
| 4208 | |
| 4209 if (bailout_on_minus_zero) { | |
| 4210 if (right < 0) { | |
| 4211 // The result is -0 if right is negative and left is zero. | |
| 4212 DeoptimizeIfZero(left, instr, Deoptimizer::kMinusZero); | |
| 4213 } else if (right == 0) { | |
| 4214 // The result is -0 if the right is zero and the left is negative. | |
| 4215 DeoptimizeIfNegative(left, instr, Deoptimizer::kMinusZero); | |
| 4216 } | |
| 4217 } | |
| 4218 | |
| 4219 switch (right) { | |
| 4220 // Cases which can detect overflow. | |
| 4221 case -1: | |
| 4222 if (can_overflow) { | |
| 4223 // Only 0x80000000 can overflow here. | |
| 4224 __ Negs(result, left); | |
| 4225 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 4226 } else { | |
| 4227 __ Neg(result, left); | |
| 4228 } | |
| 4229 break; | |
| 4230 case 0: | |
| 4231 // This case can never overflow. | |
| 4232 __ Mov(result, 0); | |
| 4233 break; | |
| 4234 case 1: | |
| 4235 // This case can never overflow. | |
| 4236 __ Mov(result, left, kDiscardForSameWReg); | |
| 4237 break; | |
| 4238 case 2: | |
| 4239 if (can_overflow) { | |
| 4240 __ Adds(result, left, left); | |
| 4241 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 4242 } else { | |
| 4243 __ Add(result, left, left); | |
| 4244 } | |
| 4245 break; | |
| 4246 | |
| 4247 default: | |
| 4248 // Multiplication by constant powers of two (and some related values) | |
| 4249 // can be done efficiently with shifted operands. | |
| 4250 int32_t right_abs = Abs(right); | |
| 4251 | |
| 4252 if (base::bits::IsPowerOfTwo32(right_abs)) { | |
| 4253 int right_log2 = WhichPowerOf2(right_abs); | |
| 4254 | |
| 4255 if (can_overflow) { | |
| 4256 Register scratch = result; | |
| 4257 DCHECK(!AreAliased(scratch, left)); | |
| 4258 __ Cls(scratch, left); | |
| 4259 __ Cmp(scratch, right_log2); | |
| 4260 DeoptimizeIf(lt, instr, Deoptimizer::kOverflow); | |
| 4261 } | |
| 4262 | |
| 4263 if (right >= 0) { | |
| 4264 // result = left << log2(right) | |
| 4265 __ Lsl(result, left, right_log2); | |
| 4266 } else { | |
| 4267 // result = -left << log2(-right) | |
| 4268 if (can_overflow) { | |
| 4269 __ Negs(result, Operand(left, LSL, right_log2)); | |
| 4270 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 4271 } else { | |
| 4272 __ Neg(result, Operand(left, LSL, right_log2)); | |
| 4273 } | |
| 4274 } | |
| 4275 return; | |
| 4276 } | |
| 4277 | |
| 4278 | |
| 4279 // For the following cases, we could perform a conservative overflow check | |
| 4280 // with CLS as above. However the few cycles saved are likely not worth | |
| 4281 // the risk of deoptimizing more often than required. | |
| 4282 DCHECK(!can_overflow); | |
| 4283 | |
| 4284 if (right >= 0) { | |
| 4285 if (base::bits::IsPowerOfTwo32(right - 1)) { | |
| 4286 // result = left + left << log2(right - 1) | |
| 4287 __ Add(result, left, Operand(left, LSL, WhichPowerOf2(right - 1))); | |
| 4288 } else if (base::bits::IsPowerOfTwo32(right + 1)) { | |
| 4289 // result = -left + left << log2(right + 1) | |
| 4290 __ Sub(result, left, Operand(left, LSL, WhichPowerOf2(right + 1))); | |
| 4291 __ Neg(result, result); | |
| 4292 } else { | |
| 4293 UNREACHABLE(); | |
| 4294 } | |
| 4295 } else { | |
| 4296 if (base::bits::IsPowerOfTwo32(-right + 1)) { | |
| 4297 // result = left - left << log2(-right + 1) | |
| 4298 __ Sub(result, left, Operand(left, LSL, WhichPowerOf2(-right + 1))); | |
| 4299 } else if (base::bits::IsPowerOfTwo32(-right - 1)) { | |
| 4300 // result = -left - left << log2(-right - 1) | |
| 4301 __ Add(result, left, Operand(left, LSL, WhichPowerOf2(-right - 1))); | |
| 4302 __ Neg(result, result); | |
| 4303 } else { | |
| 4304 UNREACHABLE(); | |
| 4305 } | |
| 4306 } | |
| 4307 } | |
| 4308 } | |
| 4309 | |
| 4310 | |
| 4311 void LCodeGen::DoMulI(LMulI* instr) { | |
| 4312 Register result = ToRegister32(instr->result()); | |
| 4313 Register left = ToRegister32(instr->left()); | |
| 4314 Register right = ToRegister32(instr->right()); | |
| 4315 | |
| 4316 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | |
| 4317 bool bailout_on_minus_zero = | |
| 4318 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); | |
| 4319 | |
| 4320 if (bailout_on_minus_zero && !left.Is(right)) { | |
| 4321 // If one operand is zero and the other is negative, the result is -0. | |
| 4322 // - Set Z (eq) if either left or right, or both, are 0. | |
| 4323 __ Cmp(left, 0); | |
| 4324 __ Ccmp(right, 0, ZFlag, ne); | |
| 4325 // - If so (eq), set N (mi) if left + right is negative. | |
| 4326 // - Otherwise, clear N. | |
| 4327 __ Ccmn(left, right, NoFlag, eq); | |
| 4328 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero); | |
| 4329 } | |
| 4330 | |
| 4331 if (can_overflow) { | |
| 4332 __ Smull(result.X(), left, right); | |
| 4333 __ Cmp(result.X(), Operand(result, SXTW)); | |
| 4334 DeoptimizeIf(ne, instr, Deoptimizer::kOverflow); | |
| 4335 } else { | |
| 4336 __ Mul(result, left, right); | |
| 4337 } | |
| 4338 } | |
| 4339 | |
| 4340 | |
| 4341 void LCodeGen::DoMulS(LMulS* instr) { | |
| 4342 Register result = ToRegister(instr->result()); | |
| 4343 Register left = ToRegister(instr->left()); | |
| 4344 Register right = ToRegister(instr->right()); | |
| 4345 | |
| 4346 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | |
| 4347 bool bailout_on_minus_zero = | |
| 4348 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); | |
| 4349 | |
| 4350 if (bailout_on_minus_zero && !left.Is(right)) { | |
| 4351 // If one operand is zero and the other is negative, the result is -0. | |
| 4352 // - Set Z (eq) if either left or right, or both, are 0. | |
| 4353 __ Cmp(left, 0); | |
| 4354 __ Ccmp(right, 0, ZFlag, ne); | |
| 4355 // - If so (eq), set N (mi) if left + right is negative. | |
| 4356 // - Otherwise, clear N. | |
| 4357 __ Ccmn(left, right, NoFlag, eq); | |
| 4358 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero); | |
| 4359 } | |
| 4360 | |
| 4361 STATIC_ASSERT((kSmiShift == 32) && (kSmiTag == 0)); | |
| 4362 if (can_overflow) { | |
| 4363 __ Smulh(result, left, right); | |
| 4364 __ Cmp(result, Operand(result.W(), SXTW)); | |
| 4365 __ SmiTag(result); | |
| 4366 DeoptimizeIf(ne, instr, Deoptimizer::kOverflow); | |
| 4367 } else { | |
| 4368 if (AreAliased(result, left, right)) { | |
| 4369 // All three registers are the same: half untag the input and then | |
| 4370 // multiply, giving a tagged result. | |
| 4371 STATIC_ASSERT((kSmiShift % 2) == 0); | |
| 4372 __ Asr(result, left, kSmiShift / 2); | |
| 4373 __ Mul(result, result, result); | |
| 4374 } else if (result.Is(left) && !left.Is(right)) { | |
| 4375 // Registers result and left alias, right is distinct: untag left into | |
| 4376 // result, and then multiply by right, giving a tagged result. | |
| 4377 __ SmiUntag(result, left); | |
| 4378 __ Mul(result, result, right); | |
| 4379 } else { | |
| 4380 DCHECK(!left.Is(result)); | |
| 4381 // Registers result and right alias, left is distinct, or all registers | |
| 4382 // are distinct: untag right into result, and then multiply by left, | |
| 4383 // giving a tagged result. | |
| 4384 __ SmiUntag(result, right); | |
| 4385 __ Mul(result, left, result); | |
| 4386 } | |
| 4387 } | |
| 4388 } | |
| 4389 | |
| 4390 | |
| 4391 void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { | |
| 4392 // TODO(3095996): Get rid of this. For now, we need to make the | |
| 4393 // result register contain a valid pointer because it is already | |
| 4394 // contained in the register pointer map. | |
| 4395 Register result = ToRegister(instr->result()); | |
| 4396 __ Mov(result, 0); | |
| 4397 | |
| 4398 PushSafepointRegistersScope scope(this); | |
| 4399 // NumberTagU and NumberTagD use the context from the frame, rather than | |
| 4400 // the environment's HContext or HInlinedContext value. | |
| 4401 // They only call Runtime::kAllocateHeapNumber. | |
| 4402 // The corresponding HChange instructions are added in a phase that does | |
| 4403 // not have easy access to the local context. | |
| 4404 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | |
| 4405 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | |
| 4406 RecordSafepointWithRegisters( | |
| 4407 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); | |
| 4408 __ StoreToSafepointRegisterSlot(x0, result); | |
| 4409 } | |
| 4410 | |
| 4411 | |
| 4412 void LCodeGen::DoNumberTagD(LNumberTagD* instr) { | |
| 4413 class DeferredNumberTagD: public LDeferredCode { | |
| 4414 public: | |
| 4415 DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) | |
| 4416 : LDeferredCode(codegen), instr_(instr) { } | |
| 4417 virtual void Generate() { codegen()->DoDeferredNumberTagD(instr_); } | |
| 4418 virtual LInstruction* instr() { return instr_; } | |
| 4419 private: | |
| 4420 LNumberTagD* instr_; | |
| 4421 }; | |
| 4422 | |
| 4423 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 4424 Register result = ToRegister(instr->result()); | |
| 4425 Register temp1 = ToRegister(instr->temp1()); | |
| 4426 Register temp2 = ToRegister(instr->temp2()); | |
| 4427 | |
| 4428 DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr); | |
| 4429 if (FLAG_inline_new) { | |
| 4430 __ AllocateHeapNumber(result, deferred->entry(), temp1, temp2); | |
| 4431 } else { | |
| 4432 __ B(deferred->entry()); | |
| 4433 } | |
| 4434 | |
| 4435 __ Bind(deferred->exit()); | |
| 4436 __ Str(input, FieldMemOperand(result, HeapNumber::kValueOffset)); | |
| 4437 } | |
| 4438 | |
| 4439 | |
| 4440 void LCodeGen::DoDeferredNumberTagU(LInstruction* instr, | |
| 4441 LOperand* value, | |
| 4442 LOperand* temp1, | |
| 4443 LOperand* temp2) { | |
| 4444 Label slow, convert_and_store; | |
| 4445 Register src = ToRegister32(value); | |
| 4446 Register dst = ToRegister(instr->result()); | |
| 4447 Register scratch1 = ToRegister(temp1); | |
| 4448 | |
| 4449 if (FLAG_inline_new) { | |
| 4450 Register scratch2 = ToRegister(temp2); | |
| 4451 __ AllocateHeapNumber(dst, &slow, scratch1, scratch2); | |
| 4452 __ B(&convert_and_store); | |
| 4453 } | |
| 4454 | |
| 4455 // Slow case: call the runtime system to do the number allocation. | |
| 4456 __ Bind(&slow); | |
| 4457 // TODO(3095996): Put a valid pointer value in the stack slot where the result | |
| 4458 // register is stored, as this register is in the pointer map, but contains an | |
| 4459 // integer value. | |
| 4460 __ Mov(dst, 0); | |
| 4461 { | |
| 4462 // Preserve the value of all registers. | |
| 4463 PushSafepointRegistersScope scope(this); | |
| 4464 | |
| 4465 // NumberTagU and NumberTagD use the context from the frame, rather than | |
| 4466 // the environment's HContext or HInlinedContext value. | |
| 4467 // They only call Runtime::kAllocateHeapNumber. | |
| 4468 // The corresponding HChange instructions are added in a phase that does | |
| 4469 // not have easy access to the local context. | |
| 4470 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | |
| 4471 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | |
| 4472 RecordSafepointWithRegisters( | |
| 4473 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); | |
| 4474 __ StoreToSafepointRegisterSlot(x0, dst); | |
| 4475 } | |
| 4476 | |
| 4477 // Convert number to floating point and store in the newly allocated heap | |
| 4478 // number. | |
| 4479 __ Bind(&convert_and_store); | |
| 4480 DoubleRegister dbl_scratch = double_scratch(); | |
| 4481 __ Ucvtf(dbl_scratch, src); | |
| 4482 __ Str(dbl_scratch, FieldMemOperand(dst, HeapNumber::kValueOffset)); | |
| 4483 } | |
| 4484 | |
| 4485 | |
| 4486 void LCodeGen::DoNumberTagU(LNumberTagU* instr) { | |
| 4487 class DeferredNumberTagU: public LDeferredCode { | |
| 4488 public: | |
| 4489 DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) | |
| 4490 : LDeferredCode(codegen), instr_(instr) { } | |
| 4491 virtual void Generate() { | |
| 4492 codegen()->DoDeferredNumberTagU(instr_, | |
| 4493 instr_->value(), | |
| 4494 instr_->temp1(), | |
| 4495 instr_->temp2()); | |
| 4496 } | |
| 4497 virtual LInstruction* instr() { return instr_; } | |
| 4498 private: | |
| 4499 LNumberTagU* instr_; | |
| 4500 }; | |
| 4501 | |
| 4502 Register value = ToRegister32(instr->value()); | |
| 4503 Register result = ToRegister(instr->result()); | |
| 4504 | |
| 4505 DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); | |
| 4506 __ Cmp(value, Smi::kMaxValue); | |
| 4507 __ B(hi, deferred->entry()); | |
| 4508 __ SmiTag(result, value.X()); | |
| 4509 __ Bind(deferred->exit()); | |
| 4510 } | |
| 4511 | |
| 4512 | |
| 4513 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { | |
| 4514 Register input = ToRegister(instr->value()); | |
| 4515 Register scratch = ToRegister(instr->temp()); | |
| 4516 DoubleRegister result = ToDoubleRegister(instr->result()); | |
| 4517 bool can_convert_undefined_to_nan = | |
| 4518 instr->hydrogen()->can_convert_undefined_to_nan(); | |
| 4519 | |
| 4520 Label done, load_smi; | |
| 4521 | |
| 4522 // Work out what untag mode we're working with. | |
| 4523 HValue* value = instr->hydrogen()->value(); | |
| 4524 NumberUntagDMode mode = value->representation().IsSmi() | |
| 4525 ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED; | |
| 4526 | |
| 4527 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { | |
| 4528 __ JumpIfSmi(input, &load_smi); | |
| 4529 | |
| 4530 Label convert_undefined; | |
| 4531 | |
| 4532 // Heap number map check. | |
| 4533 if (can_convert_undefined_to_nan) { | |
| 4534 __ JumpIfNotHeapNumber(input, &convert_undefined); | |
| 4535 } else { | |
| 4536 DeoptimizeIfNotHeapNumber(input, instr); | |
| 4537 } | |
| 4538 | |
| 4539 // Load heap number. | |
| 4540 __ Ldr(result, FieldMemOperand(input, HeapNumber::kValueOffset)); | |
| 4541 if (instr->hydrogen()->deoptimize_on_minus_zero()) { | |
| 4542 DeoptimizeIfMinusZero(result, instr, Deoptimizer::kMinusZero); | |
| 4543 } | |
| 4544 __ B(&done); | |
| 4545 | |
| 4546 if (can_convert_undefined_to_nan) { | |
| 4547 __ Bind(&convert_undefined); | |
| 4548 DeoptimizeIfNotRoot(input, Heap::kUndefinedValueRootIndex, instr, | |
| 4549 Deoptimizer::kNotAHeapNumberUndefined); | |
| 4550 | |
| 4551 __ LoadRoot(scratch, Heap::kNanValueRootIndex); | |
| 4552 __ Ldr(result, FieldMemOperand(scratch, HeapNumber::kValueOffset)); | |
| 4553 __ B(&done); | |
| 4554 } | |
| 4555 | |
| 4556 } else { | |
| 4557 DCHECK(mode == NUMBER_CANDIDATE_IS_SMI); | |
| 4558 // Fall through to load_smi. | |
| 4559 } | |
| 4560 | |
| 4561 // Smi to double register conversion. | |
| 4562 __ Bind(&load_smi); | |
| 4563 __ SmiUntagToDouble(result, input); | |
| 4564 | |
| 4565 __ Bind(&done); | |
| 4566 } | |
| 4567 | |
| 4568 | |
| 4569 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { | |
| 4570 // This is a pseudo-instruction that ensures that the environment here is | |
| 4571 // properly registered for deoptimization and records the assembler's PC | |
| 4572 // offset. | |
| 4573 LEnvironment* environment = instr->environment(); | |
| 4574 | |
| 4575 // If the environment were already registered, we would have no way of | |
| 4576 // backpatching it with the spill slot operands. | |
| 4577 DCHECK(!environment->HasBeenRegistered()); | |
| 4578 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | |
| 4579 | |
| 4580 GenerateOsrPrologue(); | |
| 4581 } | |
| 4582 | |
| 4583 | |
| 4584 void LCodeGen::DoParameter(LParameter* instr) { | |
| 4585 // Nothing to do. | |
| 4586 } | |
| 4587 | |
| 4588 | |
| 4589 void LCodeGen::DoPreparePushArguments(LPreparePushArguments* instr) { | |
| 4590 __ PushPreamble(instr->argc(), kPointerSize); | |
| 4591 } | |
| 4592 | |
| 4593 | |
| 4594 void LCodeGen::DoPushArguments(LPushArguments* instr) { | |
| 4595 MacroAssembler::PushPopQueue args(masm()); | |
| 4596 | |
| 4597 for (int i = 0; i < instr->ArgumentCount(); ++i) { | |
| 4598 LOperand* arg = instr->argument(i); | |
| 4599 if (arg->IsDoubleRegister() || arg->IsDoubleStackSlot()) { | |
| 4600 Abort(kDoPushArgumentNotImplementedForDoubleType); | |
| 4601 return; | |
| 4602 } | |
| 4603 args.Queue(ToRegister(arg)); | |
| 4604 } | |
| 4605 | |
| 4606 // The preamble was done by LPreparePushArguments. | |
| 4607 args.PushQueued(MacroAssembler::PushPopQueue::SKIP_PREAMBLE); | |
| 4608 | |
| 4609 RecordPushedArgumentsDelta(instr->ArgumentCount()); | |
| 4610 } | |
| 4611 | |
| 4612 | |
| 4613 void LCodeGen::DoReturn(LReturn* instr) { | |
| 4614 if (FLAG_trace && info()->IsOptimizing()) { | |
| 4615 // Push the return value on the stack as the parameter. | |
| 4616 // Runtime::TraceExit returns its parameter in x0. We're leaving the code | |
| 4617 // managed by the register allocator and tearing down the frame, it's | |
| 4618 // safe to write to the context register. | |
| 4619 __ Push(x0); | |
| 4620 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | |
| 4621 __ CallRuntime(Runtime::kTraceExit, 1); | |
| 4622 } | |
| 4623 | |
| 4624 if (info()->saves_caller_doubles()) { | |
| 4625 RestoreCallerDoubles(); | |
| 4626 } | |
| 4627 | |
| 4628 if (NeedsEagerFrame()) { | |
| 4629 Register stack_pointer = masm()->StackPointer(); | |
| 4630 __ Mov(stack_pointer, fp); | |
| 4631 __ Pop(fp, lr); | |
| 4632 } | |
| 4633 | |
| 4634 if (instr->has_constant_parameter_count()) { | |
| 4635 int parameter_count = ToInteger32(instr->constant_parameter_count()); | |
| 4636 __ Drop(parameter_count + 1); | |
| 4637 } else { | |
| 4638 DCHECK(info()->IsStub()); // Functions would need to drop one more value. | |
| 4639 Register parameter_count = ToRegister(instr->parameter_count()); | |
| 4640 __ DropBySMI(parameter_count); | |
| 4641 } | |
| 4642 __ Ret(); | |
| 4643 } | |
| 4644 | |
| 4645 | |
| 4646 MemOperand LCodeGen::BuildSeqStringOperand(Register string, | |
| 4647 Register temp, | |
| 4648 LOperand* index, | |
| 4649 String::Encoding encoding) { | |
| 4650 if (index->IsConstantOperand()) { | |
| 4651 int offset = ToInteger32(LConstantOperand::cast(index)); | |
| 4652 if (encoding == String::TWO_BYTE_ENCODING) { | |
| 4653 offset *= kUC16Size; | |
| 4654 } | |
| 4655 STATIC_ASSERT(kCharSize == 1); | |
| 4656 return FieldMemOperand(string, SeqString::kHeaderSize + offset); | |
| 4657 } | |
| 4658 | |
| 4659 __ Add(temp, string, SeqString::kHeaderSize - kHeapObjectTag); | |
| 4660 if (encoding == String::ONE_BYTE_ENCODING) { | |
| 4661 return MemOperand(temp, ToRegister32(index), SXTW); | |
| 4662 } else { | |
| 4663 STATIC_ASSERT(kUC16Size == 2); | |
| 4664 return MemOperand(temp, ToRegister32(index), SXTW, 1); | |
| 4665 } | |
| 4666 } | |
| 4667 | |
| 4668 | |
| 4669 void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { | |
| 4670 String::Encoding encoding = instr->hydrogen()->encoding(); | |
| 4671 Register string = ToRegister(instr->string()); | |
| 4672 Register result = ToRegister(instr->result()); | |
| 4673 Register temp = ToRegister(instr->temp()); | |
| 4674 | |
| 4675 if (FLAG_debug_code) { | |
| 4676 // Even though this lithium instruction comes with a temp register, we | |
| 4677 // can't use it here because we want to use "AtStart" constraints on the | |
| 4678 // inputs and the debug code here needs a scratch register. | |
| 4679 UseScratchRegisterScope temps(masm()); | |
| 4680 Register dbg_temp = temps.AcquireX(); | |
| 4681 | |
| 4682 __ Ldr(dbg_temp, FieldMemOperand(string, HeapObject::kMapOffset)); | |
| 4683 __ Ldrb(dbg_temp, FieldMemOperand(dbg_temp, Map::kInstanceTypeOffset)); | |
| 4684 | |
| 4685 __ And(dbg_temp, dbg_temp, | |
| 4686 Operand(kStringRepresentationMask | kStringEncodingMask)); | |
| 4687 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; | |
| 4688 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; | |
| 4689 __ Cmp(dbg_temp, Operand(encoding == String::ONE_BYTE_ENCODING | |
| 4690 ? one_byte_seq_type : two_byte_seq_type)); | |
| 4691 __ Check(eq, kUnexpectedStringType); | |
| 4692 } | |
| 4693 | |
| 4694 MemOperand operand = | |
| 4695 BuildSeqStringOperand(string, temp, instr->index(), encoding); | |
| 4696 if (encoding == String::ONE_BYTE_ENCODING) { | |
| 4697 __ Ldrb(result, operand); | |
| 4698 } else { | |
| 4699 __ Ldrh(result, operand); | |
| 4700 } | |
| 4701 } | |
| 4702 | |
| 4703 | |
| 4704 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { | |
| 4705 String::Encoding encoding = instr->hydrogen()->encoding(); | |
| 4706 Register string = ToRegister(instr->string()); | |
| 4707 Register value = ToRegister(instr->value()); | |
| 4708 Register temp = ToRegister(instr->temp()); | |
| 4709 | |
| 4710 if (FLAG_debug_code) { | |
| 4711 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 4712 Register index = ToRegister(instr->index()); | |
| 4713 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; | |
| 4714 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; | |
| 4715 int encoding_mask = | |
| 4716 instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING | |
| 4717 ? one_byte_seq_type : two_byte_seq_type; | |
| 4718 __ EmitSeqStringSetCharCheck(string, index, kIndexIsInteger32, temp, | |
| 4719 encoding_mask); | |
| 4720 } | |
| 4721 MemOperand operand = | |
| 4722 BuildSeqStringOperand(string, temp, instr->index(), encoding); | |
| 4723 if (encoding == String::ONE_BYTE_ENCODING) { | |
| 4724 __ Strb(value, operand); | |
| 4725 } else { | |
| 4726 __ Strh(value, operand); | |
| 4727 } | |
| 4728 } | |
| 4729 | |
| 4730 | |
| 4731 void LCodeGen::DoSmiTag(LSmiTag* instr) { | |
| 4732 HChange* hchange = instr->hydrogen(); | |
| 4733 Register input = ToRegister(instr->value()); | |
| 4734 Register output = ToRegister(instr->result()); | |
| 4735 if (hchange->CheckFlag(HValue::kCanOverflow) && | |
| 4736 hchange->value()->CheckFlag(HValue::kUint32)) { | |
| 4737 DeoptimizeIfNegative(input.W(), instr, Deoptimizer::kOverflow); | |
| 4738 } | |
| 4739 __ SmiTag(output, input); | |
| 4740 } | |
| 4741 | |
| 4742 | |
| 4743 void LCodeGen::DoSmiUntag(LSmiUntag* instr) { | |
| 4744 Register input = ToRegister(instr->value()); | |
| 4745 Register result = ToRegister(instr->result()); | |
| 4746 Label done, untag; | |
| 4747 | |
| 4748 if (instr->needs_check()) { | |
| 4749 DeoptimizeIfNotSmi(input, instr, Deoptimizer::kNotASmi); | |
| 4750 } | |
| 4751 | |
| 4752 __ Bind(&untag); | |
| 4753 __ SmiUntag(result, input); | |
| 4754 __ Bind(&done); | |
| 4755 } | |
| 4756 | |
| 4757 | |
| 4758 void LCodeGen::DoShiftI(LShiftI* instr) { | |
| 4759 LOperand* right_op = instr->right(); | |
| 4760 Register left = ToRegister32(instr->left()); | |
| 4761 Register result = ToRegister32(instr->result()); | |
| 4762 | |
| 4763 if (right_op->IsRegister()) { | |
| 4764 Register right = ToRegister32(instr->right()); | |
| 4765 switch (instr->op()) { | |
| 4766 case Token::ROR: __ Ror(result, left, right); break; | |
| 4767 case Token::SAR: __ Asr(result, left, right); break; | |
| 4768 case Token::SHL: __ Lsl(result, left, right); break; | |
| 4769 case Token::SHR: | |
| 4770 __ Lsr(result, left, right); | |
| 4771 if (instr->can_deopt()) { | |
| 4772 // If `left >>> right` >= 0x80000000, the result is not representable | |
| 4773 // in a signed 32-bit smi. | |
| 4774 DeoptimizeIfNegative(result, instr, Deoptimizer::kNegativeValue); | |
| 4775 } | |
| 4776 break; | |
| 4777 default: UNREACHABLE(); | |
| 4778 } | |
| 4779 } else { | |
| 4780 DCHECK(right_op->IsConstantOperand()); | |
| 4781 int shift_count = JSShiftAmountFromLConstant(right_op); | |
| 4782 if (shift_count == 0) { | |
| 4783 if ((instr->op() == Token::SHR) && instr->can_deopt()) { | |
| 4784 DeoptimizeIfNegative(left, instr, Deoptimizer::kNegativeValue); | |
| 4785 } | |
| 4786 __ Mov(result, left, kDiscardForSameWReg); | |
| 4787 } else { | |
| 4788 switch (instr->op()) { | |
| 4789 case Token::ROR: __ Ror(result, left, shift_count); break; | |
| 4790 case Token::SAR: __ Asr(result, left, shift_count); break; | |
| 4791 case Token::SHL: __ Lsl(result, left, shift_count); break; | |
| 4792 case Token::SHR: __ Lsr(result, left, shift_count); break; | |
| 4793 default: UNREACHABLE(); | |
| 4794 } | |
| 4795 } | |
| 4796 } | |
| 4797 } | |
| 4798 | |
| 4799 | |
| 4800 void LCodeGen::DoShiftS(LShiftS* instr) { | |
| 4801 LOperand* right_op = instr->right(); | |
| 4802 Register left = ToRegister(instr->left()); | |
| 4803 Register result = ToRegister(instr->result()); | |
| 4804 | |
| 4805 if (right_op->IsRegister()) { | |
| 4806 Register right = ToRegister(instr->right()); | |
| 4807 | |
| 4808 // JavaScript shifts only look at the bottom 5 bits of the 'right' operand. | |
| 4809 // Since we're handling smis in X registers, we have to extract these bits | |
| 4810 // explicitly. | |
| 4811 __ Ubfx(result, right, kSmiShift, 5); | |
| 4812 | |
| 4813 switch (instr->op()) { | |
| 4814 case Token::ROR: { | |
| 4815 // This is the only case that needs a scratch register. To keep things | |
| 4816 // simple for the other cases, borrow a MacroAssembler scratch register. | |
| 4817 UseScratchRegisterScope temps(masm()); | |
| 4818 Register temp = temps.AcquireW(); | |
| 4819 __ SmiUntag(temp, left); | |
| 4820 __ Ror(result.W(), temp.W(), result.W()); | |
| 4821 __ SmiTag(result); | |
| 4822 break; | |
| 4823 } | |
| 4824 case Token::SAR: | |
| 4825 __ Asr(result, left, result); | |
| 4826 __ Bic(result, result, kSmiShiftMask); | |
| 4827 break; | |
| 4828 case Token::SHL: | |
| 4829 __ Lsl(result, left, result); | |
| 4830 break; | |
| 4831 case Token::SHR: | |
| 4832 __ Lsr(result, left, result); | |
| 4833 __ Bic(result, result, kSmiShiftMask); | |
| 4834 if (instr->can_deopt()) { | |
| 4835 // If `left >>> right` >= 0x80000000, the result is not representable | |
| 4836 // in a signed 32-bit smi. | |
| 4837 DeoptimizeIfNegative(result, instr, Deoptimizer::kNegativeValue); | |
| 4838 } | |
| 4839 break; | |
| 4840 default: UNREACHABLE(); | |
| 4841 } | |
| 4842 } else { | |
| 4843 DCHECK(right_op->IsConstantOperand()); | |
| 4844 int shift_count = JSShiftAmountFromLConstant(right_op); | |
| 4845 if (shift_count == 0) { | |
| 4846 if ((instr->op() == Token::SHR) && instr->can_deopt()) { | |
| 4847 DeoptimizeIfNegative(left, instr, Deoptimizer::kNegativeValue); | |
| 4848 } | |
| 4849 __ Mov(result, left); | |
| 4850 } else { | |
| 4851 switch (instr->op()) { | |
| 4852 case Token::ROR: | |
| 4853 __ SmiUntag(result, left); | |
| 4854 __ Ror(result.W(), result.W(), shift_count); | |
| 4855 __ SmiTag(result); | |
| 4856 break; | |
| 4857 case Token::SAR: | |
| 4858 __ Asr(result, left, shift_count); | |
| 4859 __ Bic(result, result, kSmiShiftMask); | |
| 4860 break; | |
| 4861 case Token::SHL: | |
| 4862 __ Lsl(result, left, shift_count); | |
| 4863 break; | |
| 4864 case Token::SHR: | |
| 4865 __ Lsr(result, left, shift_count); | |
| 4866 __ Bic(result, result, kSmiShiftMask); | |
| 4867 break; | |
| 4868 default: UNREACHABLE(); | |
| 4869 } | |
| 4870 } | |
| 4871 } | |
| 4872 } | |
| 4873 | |
| 4874 | |
| 4875 void LCodeGen::DoDebugBreak(LDebugBreak* instr) { | |
| 4876 __ Debug("LDebugBreak", 0, BREAK); | |
| 4877 } | |
| 4878 | |
| 4879 | |
| 4880 void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { | |
| 4881 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 4882 Register scratch1 = x5; | |
| 4883 Register scratch2 = x6; | |
| 4884 DCHECK(instr->IsMarkedAsCall()); | |
| 4885 | |
| 4886 // TODO(all): if Mov could handle object in new space then it could be used | |
| 4887 // here. | |
| 4888 __ LoadHeapObject(scratch1, instr->hydrogen()->pairs()); | |
| 4889 __ Mov(scratch2, Smi::FromInt(instr->hydrogen()->flags())); | |
| 4890 __ Push(scratch1, scratch2); | |
| 4891 CallRuntime(Runtime::kDeclareGlobals, 2, instr); | |
| 4892 } | |
| 4893 | |
| 4894 | |
| 4895 void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { | |
| 4896 PushSafepointRegistersScope scope(this); | |
| 4897 LoadContextFromDeferred(instr->context()); | |
| 4898 __ CallRuntimeSaveDoubles(Runtime::kStackGuard); | |
| 4899 RecordSafepointWithLazyDeopt( | |
| 4900 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); | |
| 4901 DCHECK(instr->HasEnvironment()); | |
| 4902 LEnvironment* env = instr->environment(); | |
| 4903 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); | |
| 4904 } | |
| 4905 | |
| 4906 | |
| 4907 void LCodeGen::DoStackCheck(LStackCheck* instr) { | |
| 4908 class DeferredStackCheck: public LDeferredCode { | |
| 4909 public: | |
| 4910 DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) | |
| 4911 : LDeferredCode(codegen), instr_(instr) { } | |
| 4912 virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); } | |
| 4913 virtual LInstruction* instr() { return instr_; } | |
| 4914 private: | |
| 4915 LStackCheck* instr_; | |
| 4916 }; | |
| 4917 | |
| 4918 DCHECK(instr->HasEnvironment()); | |
| 4919 LEnvironment* env = instr->environment(); | |
| 4920 // There is no LLazyBailout instruction for stack-checks. We have to | |
| 4921 // prepare for lazy deoptimization explicitly here. | |
| 4922 if (instr->hydrogen()->is_function_entry()) { | |
| 4923 // Perform stack overflow check. | |
| 4924 Label done; | |
| 4925 __ CompareRoot(masm()->StackPointer(), Heap::kStackLimitRootIndex); | |
| 4926 __ B(hs, &done); | |
| 4927 | |
| 4928 PredictableCodeSizeScope predictable(masm_, | |
| 4929 Assembler::kCallSizeWithRelocation); | |
| 4930 DCHECK(instr->context()->IsRegister()); | |
| 4931 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 4932 CallCode(isolate()->builtins()->StackCheck(), | |
| 4933 RelocInfo::CODE_TARGET, | |
| 4934 instr); | |
| 4935 __ Bind(&done); | |
| 4936 } else { | |
| 4937 DCHECK(instr->hydrogen()->is_backwards_branch()); | |
| 4938 // Perform stack overflow check if this goto needs it before jumping. | |
| 4939 DeferredStackCheck* deferred_stack_check = | |
| 4940 new(zone()) DeferredStackCheck(this, instr); | |
| 4941 __ CompareRoot(masm()->StackPointer(), Heap::kStackLimitRootIndex); | |
| 4942 __ B(lo, deferred_stack_check->entry()); | |
| 4943 | |
| 4944 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); | |
| 4945 __ Bind(instr->done_label()); | |
| 4946 deferred_stack_check->SetExit(instr->done_label()); | |
| 4947 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); | |
| 4948 // Don't record a deoptimization index for the safepoint here. | |
| 4949 // This will be done explicitly when emitting call and the safepoint in | |
| 4950 // the deferred code. | |
| 4951 } | |
| 4952 } | |
| 4953 | |
| 4954 | |
| 4955 void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { | |
| 4956 Register function = ToRegister(instr->function()); | |
| 4957 Register code_object = ToRegister(instr->code_object()); | |
| 4958 Register temp = ToRegister(instr->temp()); | |
| 4959 __ Add(temp, code_object, Code::kHeaderSize - kHeapObjectTag); | |
| 4960 __ Str(temp, FieldMemOperand(function, JSFunction::kCodeEntryOffset)); | |
| 4961 } | |
| 4962 | |
| 4963 | |
| 4964 void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { | |
| 4965 Register context = ToRegister(instr->context()); | |
| 4966 Register value = ToRegister(instr->value()); | |
| 4967 Register scratch = ToRegister(instr->temp()); | |
| 4968 MemOperand target = ContextMemOperand(context, instr->slot_index()); | |
| 4969 | |
| 4970 Label skip_assignment; | |
| 4971 | |
| 4972 if (instr->hydrogen()->RequiresHoleCheck()) { | |
| 4973 __ Ldr(scratch, target); | |
| 4974 if (instr->hydrogen()->DeoptimizesOnHole()) { | |
| 4975 DeoptimizeIfRoot(scratch, Heap::kTheHoleValueRootIndex, instr, | |
| 4976 Deoptimizer::kHole); | |
| 4977 } else { | |
| 4978 __ JumpIfNotRoot(scratch, Heap::kTheHoleValueRootIndex, &skip_assignment); | |
| 4979 } | |
| 4980 } | |
| 4981 | |
| 4982 __ Str(value, target); | |
| 4983 if (instr->hydrogen()->NeedsWriteBarrier()) { | |
| 4984 SmiCheck check_needed = | |
| 4985 instr->hydrogen()->value()->type().IsHeapObject() | |
| 4986 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; | |
| 4987 __ RecordWriteContextSlot(context, static_cast<int>(target.offset()), value, | |
| 4988 scratch, GetLinkRegisterState(), kSaveFPRegs, | |
| 4989 EMIT_REMEMBERED_SET, check_needed); | |
| 4990 } | |
| 4991 __ Bind(&skip_assignment); | |
| 4992 } | |
| 4993 | |
| 4994 | |
| 4995 void LCodeGen::DoStoreKeyedExternal(LStoreKeyedExternal* instr) { | |
| 4996 Register ext_ptr = ToRegister(instr->elements()); | |
| 4997 Register key = no_reg; | |
| 4998 Register scratch; | |
| 4999 ElementsKind elements_kind = instr->elements_kind(); | |
| 5000 | |
| 5001 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); | |
| 5002 bool key_is_constant = instr->key()->IsConstantOperand(); | |
| 5003 int constant_key = 0; | |
| 5004 if (key_is_constant) { | |
| 5005 DCHECK(instr->temp() == NULL); | |
| 5006 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | |
| 5007 if (constant_key & 0xf0000000) { | |
| 5008 Abort(kArrayIndexConstantValueTooBig); | |
| 5009 } | |
| 5010 } else { | |
| 5011 key = ToRegister(instr->key()); | |
| 5012 scratch = ToRegister(instr->temp()); | |
| 5013 } | |
| 5014 | |
| 5015 MemOperand dst = | |
| 5016 PrepareKeyedExternalArrayOperand(key, ext_ptr, scratch, key_is_smi, | |
| 5017 key_is_constant, constant_key, | |
| 5018 elements_kind, | |
| 5019 instr->base_offset()); | |
| 5020 | |
| 5021 if (elements_kind == FLOAT32_ELEMENTS) { | |
| 5022 DoubleRegister value = ToDoubleRegister(instr->value()); | |
| 5023 DoubleRegister dbl_scratch = double_scratch(); | |
| 5024 __ Fcvt(dbl_scratch.S(), value); | |
| 5025 __ Str(dbl_scratch.S(), dst); | |
| 5026 } else if (elements_kind == FLOAT64_ELEMENTS) { | |
| 5027 DoubleRegister value = ToDoubleRegister(instr->value()); | |
| 5028 __ Str(value, dst); | |
| 5029 } else { | |
| 5030 Register value = ToRegister(instr->value()); | |
| 5031 | |
| 5032 switch (elements_kind) { | |
| 5033 case UINT8_ELEMENTS: | |
| 5034 case UINT8_CLAMPED_ELEMENTS: | |
| 5035 case INT8_ELEMENTS: | |
| 5036 __ Strb(value, dst); | |
| 5037 break; | |
| 5038 case INT16_ELEMENTS: | |
| 5039 case UINT16_ELEMENTS: | |
| 5040 __ Strh(value, dst); | |
| 5041 break; | |
| 5042 case INT32_ELEMENTS: | |
| 5043 case UINT32_ELEMENTS: | |
| 5044 __ Str(value.W(), dst); | |
| 5045 break; | |
| 5046 case FLOAT32_ELEMENTS: | |
| 5047 case FLOAT64_ELEMENTS: | |
| 5048 case FAST_DOUBLE_ELEMENTS: | |
| 5049 case FAST_ELEMENTS: | |
| 5050 case FAST_SMI_ELEMENTS: | |
| 5051 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
| 5052 case FAST_HOLEY_ELEMENTS: | |
| 5053 case FAST_HOLEY_SMI_ELEMENTS: | |
| 5054 case DICTIONARY_ELEMENTS: | |
| 5055 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: | |
| 5056 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: | |
| 5057 UNREACHABLE(); | |
| 5058 break; | |
| 5059 } | |
| 5060 } | |
| 5061 } | |
| 5062 | |
| 5063 | |
| 5064 void LCodeGen::DoStoreKeyedFixedDouble(LStoreKeyedFixedDouble* instr) { | |
| 5065 Register elements = ToRegister(instr->elements()); | |
| 5066 DoubleRegister value = ToDoubleRegister(instr->value()); | |
| 5067 MemOperand mem_op; | |
| 5068 | |
| 5069 if (instr->key()->IsConstantOperand()) { | |
| 5070 int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | |
| 5071 if (constant_key & 0xf0000000) { | |
| 5072 Abort(kArrayIndexConstantValueTooBig); | |
| 5073 } | |
| 5074 int offset = instr->base_offset() + constant_key * kDoubleSize; | |
| 5075 mem_op = MemOperand(elements, offset); | |
| 5076 } else { | |
| 5077 Register store_base = ToRegister(instr->temp()); | |
| 5078 Register key = ToRegister(instr->key()); | |
| 5079 bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi(); | |
| 5080 mem_op = PrepareKeyedArrayOperand(store_base, elements, key, key_is_tagged, | |
| 5081 instr->hydrogen()->elements_kind(), | |
| 5082 instr->hydrogen()->representation(), | |
| 5083 instr->base_offset()); | |
| 5084 } | |
| 5085 | |
| 5086 if (instr->NeedsCanonicalization()) { | |
| 5087 __ CanonicalizeNaN(double_scratch(), value); | |
| 5088 __ Str(double_scratch(), mem_op); | |
| 5089 } else { | |
| 5090 __ Str(value, mem_op); | |
| 5091 } | |
| 5092 } | |
| 5093 | |
| 5094 | |
| 5095 void LCodeGen::DoStoreKeyedFixed(LStoreKeyedFixed* instr) { | |
| 5096 Register value = ToRegister(instr->value()); | |
| 5097 Register elements = ToRegister(instr->elements()); | |
| 5098 Register scratch = no_reg; | |
| 5099 Register store_base = no_reg; | |
| 5100 Register key = no_reg; | |
| 5101 MemOperand mem_op; | |
| 5102 | |
| 5103 if (!instr->key()->IsConstantOperand() || | |
| 5104 instr->hydrogen()->NeedsWriteBarrier()) { | |
| 5105 scratch = ToRegister(instr->temp()); | |
| 5106 } | |
| 5107 | |
| 5108 Representation representation = instr->hydrogen()->value()->representation(); | |
| 5109 if (instr->key()->IsConstantOperand()) { | |
| 5110 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); | |
| 5111 int offset = instr->base_offset() + | |
| 5112 ToInteger32(const_operand) * kPointerSize; | |
| 5113 store_base = elements; | |
| 5114 if (representation.IsInteger32()) { | |
| 5115 DCHECK(instr->hydrogen()->store_mode() == STORE_TO_INITIALIZED_ENTRY); | |
| 5116 DCHECK(instr->hydrogen()->elements_kind() == FAST_SMI_ELEMENTS); | |
| 5117 STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits); | |
| 5118 STATIC_ASSERT(kSmiTag == 0); | |
| 5119 mem_op = UntagSmiMemOperand(store_base, offset); | |
| 5120 } else { | |
| 5121 mem_op = MemOperand(store_base, offset); | |
| 5122 } | |
| 5123 } else { | |
| 5124 store_base = scratch; | |
| 5125 key = ToRegister(instr->key()); | |
| 5126 bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi(); | |
| 5127 | |
| 5128 mem_op = PrepareKeyedArrayOperand(store_base, elements, key, key_is_tagged, | |
| 5129 instr->hydrogen()->elements_kind(), | |
| 5130 representation, instr->base_offset()); | |
| 5131 } | |
| 5132 | |
| 5133 __ Store(value, mem_op, representation); | |
| 5134 | |
| 5135 if (instr->hydrogen()->NeedsWriteBarrier()) { | |
| 5136 DCHECK(representation.IsTagged()); | |
| 5137 // This assignment may cause element_addr to alias store_base. | |
| 5138 Register element_addr = scratch; | |
| 5139 SmiCheck check_needed = | |
| 5140 instr->hydrogen()->value()->type().IsHeapObject() | |
| 5141 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; | |
| 5142 // Compute address of modified element and store it into key register. | |
| 5143 __ Add(element_addr, mem_op.base(), mem_op.OffsetAsOperand()); | |
| 5144 __ RecordWrite(elements, element_addr, value, GetLinkRegisterState(), | |
| 5145 kSaveFPRegs, EMIT_REMEMBERED_SET, check_needed, | |
| 5146 instr->hydrogen()->PointersToHereCheckForValue()); | |
| 5147 } | |
| 5148 } | |
| 5149 | |
| 5150 | |
| 5151 void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { | |
| 5152 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 5153 DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister())); | |
| 5154 DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister())); | |
| 5155 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); | |
| 5156 | |
| 5157 if (instr->hydrogen()->HasVectorAndSlot()) { | |
| 5158 EmitVectorStoreICRegisters<LStoreKeyedGeneric>(instr); | |
| 5159 } | |
| 5160 | |
| 5161 Handle<Code> ic = CodeFactory::KeyedStoreICInOptimizedCode( | |
| 5162 isolate(), instr->language_mode(), | |
| 5163 instr->hydrogen()->initialization_state()).code(); | |
| 5164 CallCode(ic, RelocInfo::CODE_TARGET, instr); | |
| 5165 } | |
| 5166 | |
| 5167 | |
| 5168 void LCodeGen::DoMaybeGrowElements(LMaybeGrowElements* instr) { | |
| 5169 class DeferredMaybeGrowElements final : public LDeferredCode { | |
| 5170 public: | |
| 5171 DeferredMaybeGrowElements(LCodeGen* codegen, LMaybeGrowElements* instr) | |
| 5172 : LDeferredCode(codegen), instr_(instr) {} | |
| 5173 void Generate() override { codegen()->DoDeferredMaybeGrowElements(instr_); } | |
| 5174 LInstruction* instr() override { return instr_; } | |
| 5175 | |
| 5176 private: | |
| 5177 LMaybeGrowElements* instr_; | |
| 5178 }; | |
| 5179 | |
| 5180 Register result = x0; | |
| 5181 DeferredMaybeGrowElements* deferred = | |
| 5182 new (zone()) DeferredMaybeGrowElements(this, instr); | |
| 5183 LOperand* key = instr->key(); | |
| 5184 LOperand* current_capacity = instr->current_capacity(); | |
| 5185 | |
| 5186 DCHECK(instr->hydrogen()->key()->representation().IsInteger32()); | |
| 5187 DCHECK(instr->hydrogen()->current_capacity()->representation().IsInteger32()); | |
| 5188 DCHECK(key->IsConstantOperand() || key->IsRegister()); | |
| 5189 DCHECK(current_capacity->IsConstantOperand() || | |
| 5190 current_capacity->IsRegister()); | |
| 5191 | |
| 5192 if (key->IsConstantOperand() && current_capacity->IsConstantOperand()) { | |
| 5193 int32_t constant_key = ToInteger32(LConstantOperand::cast(key)); | |
| 5194 int32_t constant_capacity = | |
| 5195 ToInteger32(LConstantOperand::cast(current_capacity)); | |
| 5196 if (constant_key >= constant_capacity) { | |
| 5197 // Deferred case. | |
| 5198 __ B(deferred->entry()); | |
| 5199 } | |
| 5200 } else if (key->IsConstantOperand()) { | |
| 5201 int32_t constant_key = ToInteger32(LConstantOperand::cast(key)); | |
| 5202 __ Cmp(ToRegister(current_capacity), Operand(constant_key)); | |
| 5203 __ B(le, deferred->entry()); | |
| 5204 } else if (current_capacity->IsConstantOperand()) { | |
| 5205 int32_t constant_capacity = | |
| 5206 ToInteger32(LConstantOperand::cast(current_capacity)); | |
| 5207 __ Cmp(ToRegister(key), Operand(constant_capacity)); | |
| 5208 __ B(ge, deferred->entry()); | |
| 5209 } else { | |
| 5210 __ Cmp(ToRegister(key), ToRegister(current_capacity)); | |
| 5211 __ B(ge, deferred->entry()); | |
| 5212 } | |
| 5213 | |
| 5214 __ Mov(result, ToRegister(instr->elements())); | |
| 5215 | |
| 5216 __ Bind(deferred->exit()); | |
| 5217 } | |
| 5218 | |
| 5219 | |
| 5220 void LCodeGen::DoDeferredMaybeGrowElements(LMaybeGrowElements* instr) { | |
| 5221 // TODO(3095996): Get rid of this. For now, we need to make the | |
| 5222 // result register contain a valid pointer because it is already | |
| 5223 // contained in the register pointer map. | |
| 5224 Register result = x0; | |
| 5225 __ Mov(result, 0); | |
| 5226 | |
| 5227 // We have to call a stub. | |
| 5228 { | |
| 5229 PushSafepointRegistersScope scope(this); | |
| 5230 __ Move(result, ToRegister(instr->object())); | |
| 5231 | |
| 5232 LOperand* key = instr->key(); | |
| 5233 if (key->IsConstantOperand()) { | |
| 5234 __ Mov(x3, Operand(ToSmi(LConstantOperand::cast(key)))); | |
| 5235 } else { | |
| 5236 __ Mov(x3, ToRegister(key)); | |
| 5237 __ SmiTag(x3); | |
| 5238 } | |
| 5239 | |
| 5240 GrowArrayElementsStub stub(isolate(), instr->hydrogen()->is_js_array(), | |
| 5241 instr->hydrogen()->kind()); | |
| 5242 __ CallStub(&stub); | |
| 5243 RecordSafepointWithLazyDeopt( | |
| 5244 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); | |
| 5245 __ StoreToSafepointRegisterSlot(result, result); | |
| 5246 } | |
| 5247 | |
| 5248 // Deopt on smi, which means the elements array changed to dictionary mode. | |
| 5249 DeoptimizeIfSmi(result, instr, Deoptimizer::kSmi); | |
| 5250 } | |
| 5251 | |
| 5252 | |
| 5253 void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { | |
| 5254 Representation representation = instr->representation(); | |
| 5255 | |
| 5256 Register object = ToRegister(instr->object()); | |
| 5257 HObjectAccess access = instr->hydrogen()->access(); | |
| 5258 int offset = access.offset(); | |
| 5259 | |
| 5260 if (access.IsExternalMemory()) { | |
| 5261 DCHECK(!instr->hydrogen()->has_transition()); | |
| 5262 DCHECK(!instr->hydrogen()->NeedsWriteBarrier()); | |
| 5263 Register value = ToRegister(instr->value()); | |
| 5264 __ Store(value, MemOperand(object, offset), representation); | |
| 5265 return; | |
| 5266 } | |
| 5267 | |
| 5268 __ AssertNotSmi(object); | |
| 5269 | |
| 5270 if (!FLAG_unbox_double_fields && representation.IsDouble()) { | |
| 5271 DCHECK(access.IsInobject()); | |
| 5272 DCHECK(!instr->hydrogen()->has_transition()); | |
| 5273 DCHECK(!instr->hydrogen()->NeedsWriteBarrier()); | |
| 5274 FPRegister value = ToDoubleRegister(instr->value()); | |
| 5275 __ Str(value, FieldMemOperand(object, offset)); | |
| 5276 return; | |
| 5277 } | |
| 5278 | |
| 5279 DCHECK(!representation.IsSmi() || | |
| 5280 !instr->value()->IsConstantOperand() || | |
| 5281 IsInteger32Constant(LConstantOperand::cast(instr->value()))); | |
| 5282 | |
| 5283 if (instr->hydrogen()->has_transition()) { | |
| 5284 Handle<Map> transition = instr->hydrogen()->transition_map(); | |
| 5285 AddDeprecationDependency(transition); | |
| 5286 // Store the new map value. | |
| 5287 Register new_map_value = ToRegister(instr->temp0()); | |
| 5288 __ Mov(new_map_value, Operand(transition)); | |
| 5289 __ Str(new_map_value, FieldMemOperand(object, HeapObject::kMapOffset)); | |
| 5290 if (instr->hydrogen()->NeedsWriteBarrierForMap()) { | |
| 5291 // Update the write barrier for the map field. | |
| 5292 __ RecordWriteForMap(object, | |
| 5293 new_map_value, | |
| 5294 ToRegister(instr->temp1()), | |
| 5295 GetLinkRegisterState(), | |
| 5296 kSaveFPRegs); | |
| 5297 } | |
| 5298 } | |
| 5299 | |
| 5300 // Do the store. | |
| 5301 Register destination; | |
| 5302 if (access.IsInobject()) { | |
| 5303 destination = object; | |
| 5304 } else { | |
| 5305 Register temp0 = ToRegister(instr->temp0()); | |
| 5306 __ Ldr(temp0, FieldMemOperand(object, JSObject::kPropertiesOffset)); | |
| 5307 destination = temp0; | |
| 5308 } | |
| 5309 | |
| 5310 if (FLAG_unbox_double_fields && representation.IsDouble()) { | |
| 5311 DCHECK(access.IsInobject()); | |
| 5312 FPRegister value = ToDoubleRegister(instr->value()); | |
| 5313 __ Str(value, FieldMemOperand(object, offset)); | |
| 5314 } else if (representation.IsSmi() && | |
| 5315 instr->hydrogen()->value()->representation().IsInteger32()) { | |
| 5316 DCHECK(instr->hydrogen()->store_mode() == STORE_TO_INITIALIZED_ENTRY); | |
| 5317 #ifdef DEBUG | |
| 5318 Register temp0 = ToRegister(instr->temp0()); | |
| 5319 __ Ldr(temp0, FieldMemOperand(destination, offset)); | |
| 5320 __ AssertSmi(temp0); | |
| 5321 // If destination aliased temp0, restore it to the address calculated | |
| 5322 // earlier. | |
| 5323 if (destination.Is(temp0)) { | |
| 5324 DCHECK(!access.IsInobject()); | |
| 5325 __ Ldr(destination, FieldMemOperand(object, JSObject::kPropertiesOffset)); | |
| 5326 } | |
| 5327 #endif | |
| 5328 STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits); | |
| 5329 STATIC_ASSERT(kSmiTag == 0); | |
| 5330 Register value = ToRegister(instr->value()); | |
| 5331 __ Store(value, UntagSmiFieldMemOperand(destination, offset), | |
| 5332 Representation::Integer32()); | |
| 5333 } else { | |
| 5334 Register value = ToRegister(instr->value()); | |
| 5335 __ Store(value, FieldMemOperand(destination, offset), representation); | |
| 5336 } | |
| 5337 if (instr->hydrogen()->NeedsWriteBarrier()) { | |
| 5338 Register value = ToRegister(instr->value()); | |
| 5339 __ RecordWriteField(destination, | |
| 5340 offset, | |
| 5341 value, // Clobbered. | |
| 5342 ToRegister(instr->temp1()), // Clobbered. | |
| 5343 GetLinkRegisterState(), | |
| 5344 kSaveFPRegs, | |
| 5345 EMIT_REMEMBERED_SET, | |
| 5346 instr->hydrogen()->SmiCheckForWriteBarrier(), | |
| 5347 instr->hydrogen()->PointersToHereCheckForValue()); | |
| 5348 } | |
| 5349 } | |
| 5350 | |
| 5351 | |
| 5352 void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { | |
| 5353 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 5354 DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister())); | |
| 5355 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); | |
| 5356 | |
| 5357 if (instr->hydrogen()->HasVectorAndSlot()) { | |
| 5358 EmitVectorStoreICRegisters<LStoreNamedGeneric>(instr); | |
| 5359 } | |
| 5360 | |
| 5361 __ Mov(StoreDescriptor::NameRegister(), Operand(instr->name())); | |
| 5362 Handle<Code> ic = CodeFactory::StoreICInOptimizedCode( | |
| 5363 isolate(), instr->language_mode(), | |
| 5364 instr->hydrogen()->initialization_state()).code(); | |
| 5365 CallCode(ic, RelocInfo::CODE_TARGET, instr); | |
| 5366 } | |
| 5367 | |
| 5368 | |
| 5369 void LCodeGen::DoStoreGlobalViaContext(LStoreGlobalViaContext* instr) { | |
| 5370 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 5371 DCHECK(ToRegister(instr->value()) | |
| 5372 .is(StoreGlobalViaContextDescriptor::ValueRegister())); | |
| 5373 | |
| 5374 int const slot = instr->slot_index(); | |
| 5375 int const depth = instr->depth(); | |
| 5376 if (depth <= StoreGlobalViaContextStub::kMaximumDepth) { | |
| 5377 __ Mov(StoreGlobalViaContextDescriptor::SlotRegister(), Operand(slot)); | |
| 5378 Handle<Code> stub = CodeFactory::StoreGlobalViaContext( | |
| 5379 isolate(), depth, instr->language_mode()) | |
| 5380 .code(); | |
| 5381 CallCode(stub, RelocInfo::CODE_TARGET, instr); | |
| 5382 } else { | |
| 5383 __ Push(Smi::FromInt(slot)); | |
| 5384 __ Push(StoreGlobalViaContextDescriptor::ValueRegister()); | |
| 5385 __ CallRuntime(is_strict(instr->language_mode()) | |
| 5386 ? Runtime::kStoreGlobalViaContext_Strict | |
| 5387 : Runtime::kStoreGlobalViaContext_Sloppy, | |
| 5388 2); | |
| 5389 } | |
| 5390 } | |
| 5391 | |
| 5392 | |
| 5393 void LCodeGen::DoStringAdd(LStringAdd* instr) { | |
| 5394 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 5395 DCHECK(ToRegister(instr->left()).Is(x1)); | |
| 5396 DCHECK(ToRegister(instr->right()).Is(x0)); | |
| 5397 StringAddStub stub(isolate(), | |
| 5398 instr->hydrogen()->flags(), | |
| 5399 instr->hydrogen()->pretenure_flag()); | |
| 5400 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | |
| 5401 } | |
| 5402 | |
| 5403 | |
| 5404 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { | |
| 5405 class DeferredStringCharCodeAt: public LDeferredCode { | |
| 5406 public: | |
| 5407 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) | |
| 5408 : LDeferredCode(codegen), instr_(instr) { } | |
| 5409 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } | |
| 5410 virtual LInstruction* instr() { return instr_; } | |
| 5411 private: | |
| 5412 LStringCharCodeAt* instr_; | |
| 5413 }; | |
| 5414 | |
| 5415 DeferredStringCharCodeAt* deferred = | |
| 5416 new(zone()) DeferredStringCharCodeAt(this, instr); | |
| 5417 | |
| 5418 StringCharLoadGenerator::Generate(masm(), | |
| 5419 ToRegister(instr->string()), | |
| 5420 ToRegister32(instr->index()), | |
| 5421 ToRegister(instr->result()), | |
| 5422 deferred->entry()); | |
| 5423 __ Bind(deferred->exit()); | |
| 5424 } | |
| 5425 | |
| 5426 | |
| 5427 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { | |
| 5428 Register string = ToRegister(instr->string()); | |
| 5429 Register result = ToRegister(instr->result()); | |
| 5430 | |
| 5431 // TODO(3095996): Get rid of this. For now, we need to make the | |
| 5432 // result register contain a valid pointer because it is already | |
| 5433 // contained in the register pointer map. | |
| 5434 __ Mov(result, 0); | |
| 5435 | |
| 5436 PushSafepointRegistersScope scope(this); | |
| 5437 __ Push(string); | |
| 5438 // Push the index as a smi. This is safe because of the checks in | |
| 5439 // DoStringCharCodeAt above. | |
| 5440 Register index = ToRegister(instr->index()); | |
| 5441 __ SmiTagAndPush(index); | |
| 5442 | |
| 5443 CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2, instr, | |
| 5444 instr->context()); | |
| 5445 __ AssertSmi(x0); | |
| 5446 __ SmiUntag(x0); | |
| 5447 __ StoreToSafepointRegisterSlot(x0, result); | |
| 5448 } | |
| 5449 | |
| 5450 | |
| 5451 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { | |
| 5452 class DeferredStringCharFromCode: public LDeferredCode { | |
| 5453 public: | |
| 5454 DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) | |
| 5455 : LDeferredCode(codegen), instr_(instr) { } | |
| 5456 virtual void Generate() { codegen()->DoDeferredStringCharFromCode(instr_); } | |
| 5457 virtual LInstruction* instr() { return instr_; } | |
| 5458 private: | |
| 5459 LStringCharFromCode* instr_; | |
| 5460 }; | |
| 5461 | |
| 5462 DeferredStringCharFromCode* deferred = | |
| 5463 new(zone()) DeferredStringCharFromCode(this, instr); | |
| 5464 | |
| 5465 DCHECK(instr->hydrogen()->value()->representation().IsInteger32()); | |
| 5466 Register char_code = ToRegister32(instr->char_code()); | |
| 5467 Register result = ToRegister(instr->result()); | |
| 5468 | |
| 5469 __ Cmp(char_code, String::kMaxOneByteCharCode); | |
| 5470 __ B(hi, deferred->entry()); | |
| 5471 __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); | |
| 5472 __ Add(result, result, FixedArray::kHeaderSize - kHeapObjectTag); | |
| 5473 __ Ldr(result, MemOperand(result, char_code, SXTW, kPointerSizeLog2)); | |
| 5474 __ CompareRoot(result, Heap::kUndefinedValueRootIndex); | |
| 5475 __ B(eq, deferred->entry()); | |
| 5476 __ Bind(deferred->exit()); | |
| 5477 } | |
| 5478 | |
| 5479 | |
| 5480 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { | |
| 5481 Register char_code = ToRegister(instr->char_code()); | |
| 5482 Register result = ToRegister(instr->result()); | |
| 5483 | |
| 5484 // TODO(3095996): Get rid of this. For now, we need to make the | |
| 5485 // result register contain a valid pointer because it is already | |
| 5486 // contained in the register pointer map. | |
| 5487 __ Mov(result, 0); | |
| 5488 | |
| 5489 PushSafepointRegistersScope scope(this); | |
| 5490 __ SmiTagAndPush(char_code); | |
| 5491 CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); | |
| 5492 __ StoreToSafepointRegisterSlot(x0, result); | |
| 5493 } | |
| 5494 | |
| 5495 | |
| 5496 void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { | |
| 5497 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 5498 DCHECK(ToRegister(instr->left()).is(x1)); | |
| 5499 DCHECK(ToRegister(instr->right()).is(x0)); | |
| 5500 | |
| 5501 Handle<Code> code = CodeFactory::StringCompare(isolate()).code(); | |
| 5502 CallCode(code, RelocInfo::CODE_TARGET, instr); | |
| 5503 | |
| 5504 EmitCompareAndBranch(instr, TokenToCondition(instr->op(), false), x0, 0); | |
| 5505 } | |
| 5506 | |
| 5507 | |
| 5508 void LCodeGen::DoSubI(LSubI* instr) { | |
| 5509 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | |
| 5510 Register result = ToRegister32(instr->result()); | |
| 5511 Register left = ToRegister32(instr->left()); | |
| 5512 Operand right = ToShiftedRightOperand32(instr->right(), instr); | |
| 5513 | |
| 5514 if (can_overflow) { | |
| 5515 __ Subs(result, left, right); | |
| 5516 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 5517 } else { | |
| 5518 __ Sub(result, left, right); | |
| 5519 } | |
| 5520 } | |
| 5521 | |
| 5522 | |
| 5523 void LCodeGen::DoSubS(LSubS* instr) { | |
| 5524 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | |
| 5525 Register result = ToRegister(instr->result()); | |
| 5526 Register left = ToRegister(instr->left()); | |
| 5527 Operand right = ToOperand(instr->right()); | |
| 5528 if (can_overflow) { | |
| 5529 __ Subs(result, left, right); | |
| 5530 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow); | |
| 5531 } else { | |
| 5532 __ Sub(result, left, right); | |
| 5533 } | |
| 5534 } | |
| 5535 | |
| 5536 | |
| 5537 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr, | |
| 5538 LOperand* value, | |
| 5539 LOperand* temp1, | |
| 5540 LOperand* temp2) { | |
| 5541 Register input = ToRegister(value); | |
| 5542 Register scratch1 = ToRegister(temp1); | |
| 5543 DoubleRegister dbl_scratch1 = double_scratch(); | |
| 5544 | |
| 5545 Label done; | |
| 5546 | |
| 5547 if (instr->truncating()) { | |
| 5548 Register output = ToRegister(instr->result()); | |
| 5549 Label check_bools; | |
| 5550 | |
| 5551 // If it's not a heap number, jump to undefined check. | |
| 5552 __ JumpIfNotHeapNumber(input, &check_bools); | |
| 5553 | |
| 5554 // A heap number: load value and convert to int32 using truncating function. | |
| 5555 __ TruncateHeapNumberToI(output, input); | |
| 5556 __ B(&done); | |
| 5557 | |
| 5558 __ Bind(&check_bools); | |
| 5559 | |
| 5560 Register true_root = output; | |
| 5561 Register false_root = scratch1; | |
| 5562 __ LoadTrueFalseRoots(true_root, false_root); | |
| 5563 __ Cmp(input, true_root); | |
| 5564 __ Cset(output, eq); | |
| 5565 __ Ccmp(input, false_root, ZFlag, ne); | |
| 5566 __ B(eq, &done); | |
| 5567 | |
| 5568 // Output contains zero, undefined is converted to zero for truncating | |
| 5569 // conversions. | |
| 5570 DeoptimizeIfNotRoot(input, Heap::kUndefinedValueRootIndex, instr, | |
| 5571 Deoptimizer::kNotAHeapNumberUndefinedBoolean); | |
| 5572 } else { | |
| 5573 Register output = ToRegister32(instr->result()); | |
| 5574 DoubleRegister dbl_scratch2 = ToDoubleRegister(temp2); | |
| 5575 | |
| 5576 DeoptimizeIfNotHeapNumber(input, instr); | |
| 5577 | |
| 5578 // A heap number: load value and convert to int32 using non-truncating | |
| 5579 // function. If the result is out of range, branch to deoptimize. | |
| 5580 __ Ldr(dbl_scratch1, FieldMemOperand(input, HeapNumber::kValueOffset)); | |
| 5581 __ TryRepresentDoubleAsInt32(output, dbl_scratch1, dbl_scratch2); | |
| 5582 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN); | |
| 5583 | |
| 5584 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 5585 __ Cmp(output, 0); | |
| 5586 __ B(ne, &done); | |
| 5587 __ Fmov(scratch1, dbl_scratch1); | |
| 5588 DeoptimizeIfNegative(scratch1, instr, Deoptimizer::kMinusZero); | |
| 5589 } | |
| 5590 } | |
| 5591 __ Bind(&done); | |
| 5592 } | |
| 5593 | |
| 5594 | |
| 5595 void LCodeGen::DoTaggedToI(LTaggedToI* instr) { | |
| 5596 class DeferredTaggedToI: public LDeferredCode { | |
| 5597 public: | |
| 5598 DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) | |
| 5599 : LDeferredCode(codegen), instr_(instr) { } | |
| 5600 virtual void Generate() { | |
| 5601 codegen()->DoDeferredTaggedToI(instr_, instr_->value(), instr_->temp1(), | |
| 5602 instr_->temp2()); | |
| 5603 } | |
| 5604 | |
| 5605 virtual LInstruction* instr() { return instr_; } | |
| 5606 private: | |
| 5607 LTaggedToI* instr_; | |
| 5608 }; | |
| 5609 | |
| 5610 Register input = ToRegister(instr->value()); | |
| 5611 Register output = ToRegister(instr->result()); | |
| 5612 | |
| 5613 if (instr->hydrogen()->value()->representation().IsSmi()) { | |
| 5614 __ SmiUntag(output, input); | |
| 5615 } else { | |
| 5616 DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); | |
| 5617 | |
| 5618 __ JumpIfNotSmi(input, deferred->entry()); | |
| 5619 __ SmiUntag(output, input); | |
| 5620 __ Bind(deferred->exit()); | |
| 5621 } | |
| 5622 } | |
| 5623 | |
| 5624 | |
| 5625 void LCodeGen::DoThisFunction(LThisFunction* instr) { | |
| 5626 Register result = ToRegister(instr->result()); | |
| 5627 __ Ldr(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | |
| 5628 } | |
| 5629 | |
| 5630 | |
| 5631 void LCodeGen::DoToFastProperties(LToFastProperties* instr) { | |
| 5632 DCHECK(ToRegister(instr->value()).Is(x0)); | |
| 5633 DCHECK(ToRegister(instr->result()).Is(x0)); | |
| 5634 __ Push(x0); | |
| 5635 CallRuntime(Runtime::kToFastProperties, 1, instr); | |
| 5636 } | |
| 5637 | |
| 5638 | |
| 5639 void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { | |
| 5640 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 5641 Label materialized; | |
| 5642 // Registers will be used as follows: | |
| 5643 // x7 = literals array. | |
| 5644 // x1 = regexp literal. | |
| 5645 // x0 = regexp literal clone. | |
| 5646 // x10-x12 are used as temporaries. | |
| 5647 int literal_offset = | |
| 5648 LiteralsArray::OffsetOfLiteralAt(instr->hydrogen()->literal_index()); | |
| 5649 __ LoadObject(x7, instr->hydrogen()->literals()); | |
| 5650 __ Ldr(x1, FieldMemOperand(x7, literal_offset)); | |
| 5651 __ JumpIfNotRoot(x1, Heap::kUndefinedValueRootIndex, &materialized); | |
| 5652 | |
| 5653 // Create regexp literal using runtime function | |
| 5654 // Result will be in x0. | |
| 5655 __ Mov(x12, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); | |
| 5656 __ Mov(x11, Operand(instr->hydrogen()->pattern())); | |
| 5657 __ Mov(x10, Operand(instr->hydrogen()->flags())); | |
| 5658 __ Push(x7, x12, x11, x10); | |
| 5659 CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); | |
| 5660 __ Mov(x1, x0); | |
| 5661 | |
| 5662 __ Bind(&materialized); | |
| 5663 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; | |
| 5664 Label allocated, runtime_allocate; | |
| 5665 | |
| 5666 __ Allocate(size, x0, x10, x11, &runtime_allocate, TAG_OBJECT); | |
| 5667 __ B(&allocated); | |
| 5668 | |
| 5669 __ Bind(&runtime_allocate); | |
| 5670 __ Mov(x0, Smi::FromInt(size)); | |
| 5671 __ Push(x1, x0); | |
| 5672 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | |
| 5673 __ Pop(x1); | |
| 5674 | |
| 5675 __ Bind(&allocated); | |
| 5676 // Copy the content into the newly allocated memory. | |
| 5677 __ CopyFields(x0, x1, CPURegList(x10, x11, x12), size / kPointerSize); | |
| 5678 } | |
| 5679 | |
| 5680 | |
| 5681 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { | |
| 5682 Register object = ToRegister(instr->object()); | |
| 5683 | |
| 5684 Handle<Map> from_map = instr->original_map(); | |
| 5685 Handle<Map> to_map = instr->transitioned_map(); | |
| 5686 ElementsKind from_kind = instr->from_kind(); | |
| 5687 ElementsKind to_kind = instr->to_kind(); | |
| 5688 | |
| 5689 Label not_applicable; | |
| 5690 | |
| 5691 if (IsSimpleMapChangeTransition(from_kind, to_kind)) { | |
| 5692 Register temp1 = ToRegister(instr->temp1()); | |
| 5693 Register new_map = ToRegister(instr->temp2()); | |
| 5694 __ CheckMap(object, temp1, from_map, ¬_applicable, DONT_DO_SMI_CHECK); | |
| 5695 __ Mov(new_map, Operand(to_map)); | |
| 5696 __ Str(new_map, FieldMemOperand(object, HeapObject::kMapOffset)); | |
| 5697 // Write barrier. | |
| 5698 __ RecordWriteForMap(object, new_map, temp1, GetLinkRegisterState(), | |
| 5699 kDontSaveFPRegs); | |
| 5700 } else { | |
| 5701 { | |
| 5702 UseScratchRegisterScope temps(masm()); | |
| 5703 // Use the temp register only in a restricted scope - the codegen checks | |
| 5704 // that we do not use any register across a call. | |
| 5705 __ CheckMap(object, temps.AcquireX(), from_map, ¬_applicable, | |
| 5706 DONT_DO_SMI_CHECK); | |
| 5707 } | |
| 5708 DCHECK(object.is(x0)); | |
| 5709 DCHECK(ToRegister(instr->context()).is(cp)); | |
| 5710 PushSafepointRegistersScope scope(this); | |
| 5711 __ Mov(x1, Operand(to_map)); | |
| 5712 bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE; | |
| 5713 TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array); | |
| 5714 __ CallStub(&stub); | |
| 5715 RecordSafepointWithRegisters( | |
| 5716 instr->pointer_map(), 0, Safepoint::kLazyDeopt); | |
| 5717 } | |
| 5718 __ Bind(¬_applicable); | |
| 5719 } | |
| 5720 | |
| 5721 | |
| 5722 void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { | |
| 5723 Register object = ToRegister(instr->object()); | |
| 5724 Register temp1 = ToRegister(instr->temp1()); | |
| 5725 Register temp2 = ToRegister(instr->temp2()); | |
| 5726 | |
| 5727 Label no_memento_found; | |
| 5728 __ TestJSArrayForAllocationMemento(object, temp1, temp2, &no_memento_found); | |
| 5729 DeoptimizeIf(eq, instr, Deoptimizer::kMementoFound); | |
| 5730 __ Bind(&no_memento_found); | |
| 5731 } | |
| 5732 | |
| 5733 | |
| 5734 void LCodeGen::DoTruncateDoubleToIntOrSmi(LTruncateDoubleToIntOrSmi* instr) { | |
| 5735 DoubleRegister input = ToDoubleRegister(instr->value()); | |
| 5736 Register result = ToRegister(instr->result()); | |
| 5737 __ TruncateDoubleToI(result, input); | |
| 5738 if (instr->tag_result()) { | |
| 5739 __ SmiTag(result, result); | |
| 5740 } | |
| 5741 } | |
| 5742 | |
| 5743 | |
| 5744 void LCodeGen::DoTypeof(LTypeof* instr) { | |
| 5745 DCHECK(ToRegister(instr->value()).is(x3)); | |
| 5746 DCHECK(ToRegister(instr->result()).is(x0)); | |
| 5747 Label end, do_call; | |
| 5748 Register value_register = ToRegister(instr->value()); | |
| 5749 __ JumpIfNotSmi(value_register, &do_call); | |
| 5750 __ Mov(x0, Immediate(isolate()->factory()->number_string())); | |
| 5751 __ B(&end); | |
| 5752 __ Bind(&do_call); | |
| 5753 TypeofStub stub(isolate()); | |
| 5754 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | |
| 5755 __ Bind(&end); | |
| 5756 } | |
| 5757 | |
| 5758 | |
| 5759 void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { | |
| 5760 Handle<String> type_name = instr->type_literal(); | |
| 5761 Label* true_label = instr->TrueLabel(chunk_); | |
| 5762 Label* false_label = instr->FalseLabel(chunk_); | |
| 5763 Register value = ToRegister(instr->value()); | |
| 5764 | |
| 5765 Factory* factory = isolate()->factory(); | |
| 5766 if (String::Equals(type_name, factory->number_string())) { | |
| 5767 __ JumpIfSmi(value, true_label); | |
| 5768 | |
| 5769 int true_block = instr->TrueDestination(chunk_); | |
| 5770 int false_block = instr->FalseDestination(chunk_); | |
| 5771 int next_block = GetNextEmittedBlock(); | |
| 5772 | |
| 5773 if (true_block == false_block) { | |
| 5774 EmitGoto(true_block); | |
| 5775 } else if (true_block == next_block) { | |
| 5776 __ JumpIfNotHeapNumber(value, chunk_->GetAssemblyLabel(false_block)); | |
| 5777 } else { | |
| 5778 __ JumpIfHeapNumber(value, chunk_->GetAssemblyLabel(true_block)); | |
| 5779 if (false_block != next_block) { | |
| 5780 __ B(chunk_->GetAssemblyLabel(false_block)); | |
| 5781 } | |
| 5782 } | |
| 5783 | |
| 5784 } else if (String::Equals(type_name, factory->string_string())) { | |
| 5785 DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL)); | |
| 5786 Register map = ToRegister(instr->temp1()); | |
| 5787 Register scratch = ToRegister(instr->temp2()); | |
| 5788 | |
| 5789 __ JumpIfSmi(value, false_label); | |
| 5790 __ CompareObjectType(value, map, scratch, FIRST_NONSTRING_TYPE); | |
| 5791 EmitBranch(instr, lt); | |
| 5792 | |
| 5793 } else if (String::Equals(type_name, factory->symbol_string())) { | |
| 5794 DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL)); | |
| 5795 Register map = ToRegister(instr->temp1()); | |
| 5796 Register scratch = ToRegister(instr->temp2()); | |
| 5797 | |
| 5798 __ JumpIfSmi(value, false_label); | |
| 5799 __ CompareObjectType(value, map, scratch, SYMBOL_TYPE); | |
| 5800 EmitBranch(instr, eq); | |
| 5801 | |
| 5802 } else if (String::Equals(type_name, factory->boolean_string())) { | |
| 5803 __ JumpIfRoot(value, Heap::kTrueValueRootIndex, true_label); | |
| 5804 __ CompareRoot(value, Heap::kFalseValueRootIndex); | |
| 5805 EmitBranch(instr, eq); | |
| 5806 | |
| 5807 } else if (String::Equals(type_name, factory->undefined_string())) { | |
| 5808 DCHECK(instr->temp1() != NULL); | |
| 5809 Register scratch = ToRegister(instr->temp1()); | |
| 5810 | |
| 5811 __ JumpIfRoot(value, Heap::kUndefinedValueRootIndex, true_label); | |
| 5812 __ JumpIfSmi(value, false_label); | |
| 5813 // Check for undetectable objects and jump to the true branch in this case. | |
| 5814 __ Ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset)); | |
| 5815 __ Ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); | |
| 5816 EmitTestAndBranch(instr, ne, scratch, 1 << Map::kIsUndetectable); | |
| 5817 | |
| 5818 } else if (String::Equals(type_name, factory->function_string())) { | |
| 5819 DCHECK(instr->temp1() != NULL); | |
| 5820 Register scratch = ToRegister(instr->temp1()); | |
| 5821 | |
| 5822 __ JumpIfSmi(value, false_label); | |
| 5823 __ Ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset)); | |
| 5824 __ Ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); | |
| 5825 __ And(scratch, scratch, | |
| 5826 (1 << Map::kIsCallable) | (1 << Map::kIsUndetectable)); | |
| 5827 EmitCompareAndBranch(instr, eq, scratch, 1 << Map::kIsCallable); | |
| 5828 | |
| 5829 } else if (String::Equals(type_name, factory->object_string())) { | |
| 5830 DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL)); | |
| 5831 Register map = ToRegister(instr->temp1()); | |
| 5832 Register scratch = ToRegister(instr->temp2()); | |
| 5833 | |
| 5834 __ JumpIfSmi(value, false_label); | |
| 5835 __ JumpIfRoot(value, Heap::kNullValueRootIndex, true_label); | |
| 5836 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); | |
| 5837 __ JumpIfObjectType(value, map, scratch, FIRST_SPEC_OBJECT_TYPE, | |
| 5838 false_label, lt); | |
| 5839 // Check for callable or undetectable objects => false. | |
| 5840 __ Ldrb(scratch, FieldMemOperand(map, Map::kBitFieldOffset)); | |
| 5841 EmitTestAndBranch(instr, eq, scratch, | |
| 5842 (1 << Map::kIsCallable) | (1 << Map::kIsUndetectable)); | |
| 5843 | |
| 5844 // clang-format off | |
| 5845 #define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \ | |
| 5846 } else if (String::Equals(type_name, factory->type##_string())) { \ | |
| 5847 DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL)); \ | |
| 5848 Register map = ToRegister(instr->temp1()); \ | |
| 5849 \ | |
| 5850 __ JumpIfSmi(value, false_label); \ | |
| 5851 __ Ldr(map, FieldMemOperand(value, HeapObject::kMapOffset)); \ | |
| 5852 __ CompareRoot(map, Heap::k##Type##MapRootIndex); \ | |
| 5853 EmitBranch(instr, eq); | |
| 5854 SIMD128_TYPES(SIMD128_TYPE) | |
| 5855 #undef SIMD128_TYPE | |
| 5856 // clang-format on | |
| 5857 | |
| 5858 } else { | |
| 5859 __ B(false_label); | |
| 5860 } | |
| 5861 } | |
| 5862 | |
| 5863 | |
| 5864 void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { | |
| 5865 __ Ucvtf(ToDoubleRegister(instr->result()), ToRegister32(instr->value())); | |
| 5866 } | |
| 5867 | |
| 5868 | |
| 5869 void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { | |
| 5870 Register object = ToRegister(instr->value()); | |
| 5871 Register map = ToRegister(instr->map()); | |
| 5872 Register temp = ToRegister(instr->temp()); | |
| 5873 __ Ldr(temp, FieldMemOperand(object, HeapObject::kMapOffset)); | |
| 5874 __ Cmp(map, temp); | |
| 5875 DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap); | |
| 5876 } | |
| 5877 | |
| 5878 | |
| 5879 void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { | |
| 5880 Register receiver = ToRegister(instr->receiver()); | |
| 5881 Register function = ToRegister(instr->function()); | |
| 5882 Register result = ToRegister(instr->result()); | |
| 5883 | |
| 5884 // If the receiver is null or undefined, we have to pass the global object as | |
| 5885 // a receiver to normal functions. Values have to be passed unchanged to | |
| 5886 // builtins and strict-mode functions. | |
| 5887 Label global_object, done, copy_receiver; | |
| 5888 | |
| 5889 if (!instr->hydrogen()->known_function()) { | |
| 5890 __ Ldr(result, FieldMemOperand(function, | |
| 5891 JSFunction::kSharedFunctionInfoOffset)); | |
| 5892 | |
| 5893 // CompilerHints is an int32 field. See objects.h. | |
| 5894 __ Ldr(result.W(), | |
| 5895 FieldMemOperand(result, SharedFunctionInfo::kCompilerHintsOffset)); | |
| 5896 | |
| 5897 // Do not transform the receiver to object for strict mode functions. | |
| 5898 __ Tbnz(result, SharedFunctionInfo::kStrictModeFunction, ©_receiver); | |
| 5899 | |
| 5900 // Do not transform the receiver to object for builtins. | |
| 5901 __ Tbnz(result, SharedFunctionInfo::kNative, ©_receiver); | |
| 5902 } | |
| 5903 | |
| 5904 // Normal function. Replace undefined or null with global receiver. | |
| 5905 __ JumpIfRoot(receiver, Heap::kNullValueRootIndex, &global_object); | |
| 5906 __ JumpIfRoot(receiver, Heap::kUndefinedValueRootIndex, &global_object); | |
| 5907 | |
| 5908 // Deoptimize if the receiver is not a JS object. | |
| 5909 DeoptimizeIfSmi(receiver, instr, Deoptimizer::kSmi); | |
| 5910 __ CompareObjectType(receiver, result, result, FIRST_SPEC_OBJECT_TYPE); | |
| 5911 __ B(ge, ©_receiver); | |
| 5912 Deoptimize(instr, Deoptimizer::kNotAJavaScriptObject); | |
| 5913 | |
| 5914 __ Bind(&global_object); | |
| 5915 __ Ldr(result, FieldMemOperand(function, JSFunction::kContextOffset)); | |
| 5916 __ Ldr(result, ContextMemOperand(result, Context::GLOBAL_OBJECT_INDEX)); | |
| 5917 __ Ldr(result, FieldMemOperand(result, GlobalObject::kGlobalProxyOffset)); | |
| 5918 __ B(&done); | |
| 5919 | |
| 5920 __ Bind(©_receiver); | |
| 5921 __ Mov(result, receiver); | |
| 5922 __ Bind(&done); | |
| 5923 } | |
| 5924 | |
| 5925 | |
| 5926 void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr, | |
| 5927 Register result, | |
| 5928 Register object, | |
| 5929 Register index) { | |
| 5930 PushSafepointRegistersScope scope(this); | |
| 5931 __ Push(object); | |
| 5932 __ Push(index); | |
| 5933 __ Mov(cp, 0); | |
| 5934 __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble); | |
| 5935 RecordSafepointWithRegisters( | |
| 5936 instr->pointer_map(), 2, Safepoint::kNoLazyDeopt); | |
| 5937 __ StoreToSafepointRegisterSlot(x0, result); | |
| 5938 } | |
| 5939 | |
| 5940 | |
| 5941 void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { | |
| 5942 class DeferredLoadMutableDouble final : public LDeferredCode { | |
| 5943 public: | |
| 5944 DeferredLoadMutableDouble(LCodeGen* codegen, | |
| 5945 LLoadFieldByIndex* instr, | |
| 5946 Register result, | |
| 5947 Register object, | |
| 5948 Register index) | |
| 5949 : LDeferredCode(codegen), | |
| 5950 instr_(instr), | |
| 5951 result_(result), | |
| 5952 object_(object), | |
| 5953 index_(index) { | |
| 5954 } | |
| 5955 void Generate() override { | |
| 5956 codegen()->DoDeferredLoadMutableDouble(instr_, result_, object_, index_); | |
| 5957 } | |
| 5958 LInstruction* instr() override { return instr_; } | |
| 5959 | |
| 5960 private: | |
| 5961 LLoadFieldByIndex* instr_; | |
| 5962 Register result_; | |
| 5963 Register object_; | |
| 5964 Register index_; | |
| 5965 }; | |
| 5966 Register object = ToRegister(instr->object()); | |
| 5967 Register index = ToRegister(instr->index()); | |
| 5968 Register result = ToRegister(instr->result()); | |
| 5969 | |
| 5970 __ AssertSmi(index); | |
| 5971 | |
| 5972 DeferredLoadMutableDouble* deferred; | |
| 5973 deferred = new(zone()) DeferredLoadMutableDouble( | |
| 5974 this, instr, result, object, index); | |
| 5975 | |
| 5976 Label out_of_object, done; | |
| 5977 | |
| 5978 __ TestAndBranchIfAnySet( | |
| 5979 index, reinterpret_cast<uint64_t>(Smi::FromInt(1)), deferred->entry()); | |
| 5980 __ Mov(index, Operand(index, ASR, 1)); | |
| 5981 | |
| 5982 __ Cmp(index, Smi::FromInt(0)); | |
| 5983 __ B(lt, &out_of_object); | |
| 5984 | |
| 5985 STATIC_ASSERT(kPointerSizeLog2 > kSmiTagSize); | |
| 5986 __ Add(result, object, Operand::UntagSmiAndScale(index, kPointerSizeLog2)); | |
| 5987 __ Ldr(result, FieldMemOperand(result, JSObject::kHeaderSize)); | |
| 5988 | |
| 5989 __ B(&done); | |
| 5990 | |
| 5991 __ Bind(&out_of_object); | |
| 5992 __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | |
| 5993 // Index is equal to negated out of object property index plus 1. | |
| 5994 __ Sub(result, result, Operand::UntagSmiAndScale(index, kPointerSizeLog2)); | |
| 5995 __ Ldr(result, FieldMemOperand(result, | |
| 5996 FixedArray::kHeaderSize - kPointerSize)); | |
| 5997 __ Bind(deferred->exit()); | |
| 5998 __ Bind(&done); | |
| 5999 } | |
| 6000 | |
| 6001 | |
| 6002 void LCodeGen::DoStoreFrameContext(LStoreFrameContext* instr) { | |
| 6003 Register context = ToRegister(instr->context()); | |
| 6004 __ Str(context, MemOperand(fp, StandardFrameConstants::kContextOffset)); | |
| 6005 } | |
| 6006 | |
| 6007 | |
| 6008 void LCodeGen::DoAllocateBlockContext(LAllocateBlockContext* instr) { | |
| 6009 Handle<ScopeInfo> scope_info = instr->scope_info(); | |
| 6010 __ Push(scope_info); | |
| 6011 __ Push(ToRegister(instr->function())); | |
| 6012 CallRuntime(Runtime::kPushBlockContext, 2, instr); | |
| 6013 RecordSafepoint(Safepoint::kNoLazyDeopt); | |
| 6014 } | |
| 6015 | |
| 6016 | |
| 6017 } // namespace internal | |
| 6018 } // namespace v8 | |
| OLD | NEW |