Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: src/x64/lithium-codegen-x64.cc

Issue 1304633002: Correctify instanceof and make it optimizable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Add MIPS/MIPS64 ports. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/x64/lithium-codegen-x64.h ('k') | src/x64/lithium-x64.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if V8_TARGET_ARCH_X64 5 #if V8_TARGET_ARCH_X64
6 6
7 #include "src/base/bits.h" 7 #include "src/base/bits.h"
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/cpu-profiler.h" 10 #include "src/cpu-profiler.h"
(...skipping 2075 matching lines...) Expand 10 before | Expand all | Expand 10 after
2086 __ j(cc, chunk_->GetAssemblyLabel(left_block)); 2086 __ j(cc, chunk_->GetAssemblyLabel(left_block));
2087 } else { 2087 } else {
2088 __ j(cc, chunk_->GetAssemblyLabel(left_block)); 2088 __ j(cc, chunk_->GetAssemblyLabel(left_block));
2089 if (cc != always) { 2089 if (cc != always) {
2090 __ jmp(chunk_->GetAssemblyLabel(right_block)); 2090 __ jmp(chunk_->GetAssemblyLabel(right_block));
2091 } 2091 }
2092 } 2092 }
2093 } 2093 }
2094 2094
2095 2095
2096 template<class InstrType> 2096 template <class InstrType>
2097 void LCodeGen::EmitTrueBranch(InstrType instr, Condition cc) {
2098 int true_block = instr->TrueDestination(chunk_);
2099 __ j(cc, chunk_->GetAssemblyLabel(true_block));
2100 }
2101
2102
2103 template <class InstrType>
2097 void LCodeGen::EmitFalseBranch(InstrType instr, Condition cc) { 2104 void LCodeGen::EmitFalseBranch(InstrType instr, Condition cc) {
2098 int false_block = instr->FalseDestination(chunk_); 2105 int false_block = instr->FalseDestination(chunk_);
2099 __ j(cc, chunk_->GetAssemblyLabel(false_block)); 2106 __ j(cc, chunk_->GetAssemblyLabel(false_block));
2100 } 2107 }
2101 2108
2102 2109
2103 void LCodeGen::DoDebugBreak(LDebugBreak* instr) { 2110 void LCodeGen::DoDebugBreak(LDebugBreak* instr) {
2104 __ int3(); 2111 __ int3();
2105 } 2112 }
2106 2113
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
2664 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { 2671 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) {
2665 Register reg = ToRegister(instr->value()); 2672 Register reg = ToRegister(instr->value());
2666 2673
2667 __ Cmp(FieldOperand(reg, HeapObject::kMapOffset), instr->map()); 2674 __ Cmp(FieldOperand(reg, HeapObject::kMapOffset), instr->map());
2668 EmitBranch(instr, equal); 2675 EmitBranch(instr, equal);
2669 } 2676 }
2670 2677
2671 2678
2672 void LCodeGen::DoInstanceOf(LInstanceOf* instr) { 2679 void LCodeGen::DoInstanceOf(LInstanceOf* instr) {
2673 DCHECK(ToRegister(instr->context()).is(rsi)); 2680 DCHECK(ToRegister(instr->context()).is(rsi));
2674 InstanceofStub stub(isolate(), InstanceofStub::kNoFlags); 2681 DCHECK(ToRegister(instr->left()).is(InstanceOfDescriptor::LeftRegister()));
2675 __ Push(ToRegister(instr->left())); 2682 DCHECK(ToRegister(instr->right()).is(InstanceOfDescriptor::RightRegister()));
2676 __ Push(ToRegister(instr->right())); 2683 DCHECK(ToRegister(instr->result()).is(rax));
2684 InstanceOfStub stub(isolate());
2677 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); 2685 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
2678 Label true_value, done;
2679 __ testp(rax, rax);
2680 __ j(zero, &true_value, Label::kNear);
2681 __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex);
2682 __ jmp(&done, Label::kNear);
2683 __ bind(&true_value);
2684 __ LoadRoot(ToRegister(instr->result()), Heap::kTrueValueRootIndex);
2685 __ bind(&done);
2686 } 2686 }
2687 2687
2688 2688
2689 void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { 2689 void LCodeGen::DoHasInPrototypeChainAndBranch(
2690 class DeferredInstanceOfKnownGlobal final : public LDeferredCode { 2690 LHasInPrototypeChainAndBranch* instr) {
2691 public: 2691 Register const object = ToRegister(instr->object());
2692 DeferredInstanceOfKnownGlobal(LCodeGen* codegen, 2692 Register const object_map = kScratchRegister;
2693 LInstanceOfKnownGlobal* instr) 2693 Register const object_prototype = object_map;
2694 : LDeferredCode(codegen), instr_(instr) { } 2694 Register const prototype = ToRegister(instr->prototype());
2695 void Generate() override {
2696 codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_);
2697 }
2698 LInstruction* instr() override { return instr_; }
2699 Label* map_check() { return &map_check_; }
2700 private:
2701 LInstanceOfKnownGlobal* instr_;
2702 Label map_check_;
2703 };
2704 2695
2705 DCHECK(ToRegister(instr->context()).is(rsi)); 2696 // The {object} must be a spec object. It's sufficient to know that {object}
2706 DeferredInstanceOfKnownGlobal* deferred; 2697 // is not a smi, since all other non-spec objects have {null} prototypes and
2707 deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr); 2698 // will be ruled out below.
2699 if (instr->hydrogen()->ObjectNeedsSmiCheck()) {
2700 Condition is_smi = __ CheckSmi(object);
2701 EmitFalseBranch(instr, is_smi);
2702 }
2708 2703
2709 Label done, false_result; 2704 // Loop through the {object}s prototype chain looking for the {prototype}.
2710 Register object = ToRegister(instr->value()); 2705 __ movp(object_map, FieldOperand(object, HeapObject::kMapOffset));
2711 2706 Label loop;
2712 // A Smi is not an instance of anything. 2707 __ bind(&loop);
2713 __ JumpIfSmi(object, &false_result, Label::kNear); 2708 __ movp(object_prototype, FieldOperand(object_map, Map::kPrototypeOffset));
2714 2709 __ cmpp(object_prototype, prototype);
2715 // This is the inlined call site instanceof cache. The two occurences of the 2710 EmitTrueBranch(instr, equal);
2716 // hole value will be patched to the last map/result pair generated by the 2711 __ CompareRoot(object_prototype, Heap::kNullValueRootIndex);
2717 // instanceof stub. 2712 EmitFalseBranch(instr, equal);
2718 Label cache_miss; 2713 __ movp(object_map, FieldOperand(object_prototype, HeapObject::kMapOffset));
2719 // Use a temp register to avoid memory operands with variable lengths. 2714 __ jmp(&loop);
2720 Register map = ToRegister(instr->temp());
2721 __ movp(map, FieldOperand(object, HeapObject::kMapOffset));
2722 __ bind(deferred->map_check()); // Label for calculating code patching.
2723 Handle<Cell> cache_cell = factory()->NewCell(factory()->the_hole_value());
2724 __ Move(kScratchRegister, cache_cell, RelocInfo::CELL);
2725 __ cmpp(map, Operand(kScratchRegister, 0));
2726 __ j(not_equal, &cache_miss, Label::kNear);
2727 // Patched to load either true or false.
2728 __ LoadRoot(ToRegister(instr->result()), Heap::kTheHoleValueRootIndex);
2729 #ifdef DEBUG
2730 // Check that the code size between patch label and patch sites is invariant.
2731 Label end_of_patched_code;
2732 __ bind(&end_of_patched_code);
2733 DCHECK(true);
2734 #endif
2735 __ jmp(&done, Label::kNear);
2736
2737 // The inlined call site cache did not match. Check for null and string
2738 // before calling the deferred code.
2739 __ bind(&cache_miss); // Null is not an instance of anything.
2740 __ CompareRoot(object, Heap::kNullValueRootIndex);
2741 __ j(equal, &false_result, Label::kNear);
2742
2743 // String values are not instances of anything.
2744 __ JumpIfNotString(object, kScratchRegister, deferred->entry());
2745
2746 __ bind(&false_result);
2747 __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex);
2748
2749 __ bind(deferred->exit());
2750 __ bind(&done);
2751 } 2715 }
2752 2716
2753 2717
2754 void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr,
2755 Label* map_check) {
2756 {
2757 PushSafepointRegistersScope scope(this);
2758 InstanceofStub::Flags flags = static_cast<InstanceofStub::Flags>(
2759 InstanceofStub::kNoFlags | InstanceofStub::kCallSiteInlineCheck);
2760 InstanceofStub stub(isolate(), flags);
2761
2762 __ Push(ToRegister(instr->value()));
2763 __ Push(instr->function());
2764
2765 static const int kAdditionalDelta = kPointerSize == kInt64Size ? 10 : 16;
2766 int delta =
2767 masm_->SizeOfCodeGeneratedSince(map_check) + kAdditionalDelta;
2768 DCHECK(delta >= 0);
2769 __ PushImm32(delta);
2770
2771 // We are pushing three values on the stack but recording a
2772 // safepoint with two arguments because stub is going to
2773 // remove the third argument from the stack before jumping
2774 // to instanceof builtin on the slow path.
2775 CallCodeGeneric(stub.GetCode(),
2776 RelocInfo::CODE_TARGET,
2777 instr,
2778 RECORD_SAFEPOINT_WITH_REGISTERS,
2779 2);
2780 DCHECK(delta == masm_->SizeOfCodeGeneratedSince(map_check));
2781 LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment();
2782 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
2783 // Move result to a register that survives the end of the
2784 // PushSafepointRegisterScope.
2785 __ movp(kScratchRegister, rax);
2786 }
2787 __ testp(kScratchRegister, kScratchRegister);
2788 Label load_false;
2789 Label done;
2790 __ j(not_zero, &load_false, Label::kNear);
2791 __ LoadRoot(rax, Heap::kTrueValueRootIndex);
2792 __ jmp(&done, Label::kNear);
2793 __ bind(&load_false);
2794 __ LoadRoot(rax, Heap::kFalseValueRootIndex);
2795 __ bind(&done);
2796 }
2797
2798
2799 void LCodeGen::DoCmpT(LCmpT* instr) { 2718 void LCodeGen::DoCmpT(LCmpT* instr) {
2800 DCHECK(ToRegister(instr->context()).is(rsi)); 2719 DCHECK(ToRegister(instr->context()).is(rsi));
2801 Token::Value op = instr->op(); 2720 Token::Value op = instr->op();
2802 2721
2803 Handle<Code> ic = 2722 Handle<Code> ic =
2804 CodeFactory::CompareIC(isolate(), op, instr->strength()).code(); 2723 CodeFactory::CompareIC(isolate(), op, instr->strength()).code();
2805 CallCode(ic, RelocInfo::CODE_TARGET, instr); 2724 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2806 2725
2807 Condition condition = TokenToCondition(op, false); 2726 Condition condition = TokenToCondition(op, false);
2808 Label true_value, done; 2727 Label true_value, done;
(...skipping 3246 matching lines...) Expand 10 before | Expand all | Expand 10 after
6055 RecordSafepoint(Safepoint::kNoLazyDeopt); 5974 RecordSafepoint(Safepoint::kNoLazyDeopt);
6056 } 5975 }
6057 5976
6058 5977
6059 #undef __ 5978 #undef __
6060 5979
6061 } // namespace internal 5980 } // namespace internal
6062 } // namespace v8 5981 } // namespace v8
6063 5982
6064 #endif // V8_TARGET_ARCH_X64 5983 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/lithium-codegen-x64.h ('k') | src/x64/lithium-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698