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