OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 // is already pushed by a call instruction, and PushTryHandler from the | 718 // is already pushed by a call instruction, and PushTryHandler from the |
719 // macro assembler will leave the top of stack in the eax register to be | 719 // macro assembler will leave the top of stack in the eax register to be |
720 // pushed separately). | 720 // pushed separately). |
721 Adjust(kHandlerSize - 2); | 721 Adjust(kHandlerSize - 2); |
722 __ PushTryHandler(IN_JAVASCRIPT, type); | 722 __ PushTryHandler(IN_JAVASCRIPT, type); |
723 // TODO(1222589): remove the reliance of PushTryHandler on a cached TOS | 723 // TODO(1222589): remove the reliance of PushTryHandler on a cached TOS |
724 EmitPush(eax); | 724 EmitPush(eax); |
725 } | 725 } |
726 | 726 |
727 | 727 |
728 Result VirtualFrame::RawCallStub(CodeStub* stub, int frame_arg_count) { | 728 Result VirtualFrame::RawCallStub(CodeStub* stub) { |
729 ASSERT(cgen_->HasValidEntryRegisters()); | 729 ASSERT(cgen_->HasValidEntryRegisters()); |
730 __ CallStub(stub); | 730 __ CallStub(stub); |
731 Result result = cgen_->allocator()->Allocate(eax); | 731 Result result = cgen_->allocator()->Allocate(eax); |
732 ASSERT(result.is_valid()); | 732 ASSERT(result.is_valid()); |
733 return result; | 733 return result; |
734 } | 734 } |
735 | 735 |
736 | 736 |
737 Result VirtualFrame::CallRuntime(Runtime::Function* f, | 737 Result VirtualFrame::CallRuntime(Runtime::Function* f, int arg_count) { |
738 int frame_arg_count) { | 738 PrepareForCall(arg_count, arg_count); |
739 PrepareForCall(frame_arg_count, frame_arg_count); | |
740 ASSERT(cgen_->HasValidEntryRegisters()); | 739 ASSERT(cgen_->HasValidEntryRegisters()); |
741 __ CallRuntime(f, frame_arg_count); | 740 __ CallRuntime(f, arg_count); |
742 Result result = cgen_->allocator()->Allocate(eax); | 741 Result result = cgen_->allocator()->Allocate(eax); |
743 ASSERT(result.is_valid()); | 742 ASSERT(result.is_valid()); |
744 return result; | 743 return result; |
745 } | 744 } |
746 | 745 |
747 | 746 |
748 Result VirtualFrame::CallRuntime(Runtime::FunctionId id, | 747 Result VirtualFrame::CallRuntime(Runtime::FunctionId id, int arg_count) { |
749 int frame_arg_count) { | 748 PrepareForCall(arg_count, arg_count); |
750 PrepareForCall(frame_arg_count, frame_arg_count); | |
751 ASSERT(cgen_->HasValidEntryRegisters()); | 749 ASSERT(cgen_->HasValidEntryRegisters()); |
752 __ CallRuntime(id, frame_arg_count); | 750 __ CallRuntime(id, arg_count); |
753 Result result = cgen_->allocator()->Allocate(eax); | 751 Result result = cgen_->allocator()->Allocate(eax); |
754 ASSERT(result.is_valid()); | 752 ASSERT(result.is_valid()); |
755 return result; | 753 return result; |
756 } | 754 } |
757 | 755 |
758 | 756 |
759 Result VirtualFrame::InvokeBuiltin(Builtins::JavaScript id, | 757 Result VirtualFrame::InvokeBuiltin(Builtins::JavaScript id, |
760 InvokeFlag flag, | 758 InvokeFlag flag, |
761 int frame_arg_count) { | 759 int arg_count) { |
762 PrepareForCall(frame_arg_count, frame_arg_count); | 760 PrepareForCall(arg_count, arg_count); |
763 ASSERT(cgen_->HasValidEntryRegisters()); | 761 ASSERT(cgen_->HasValidEntryRegisters()); |
764 __ InvokeBuiltin(id, flag); | 762 __ InvokeBuiltin(id, flag); |
765 Result result = cgen_->allocator()->Allocate(eax); | 763 Result result = cgen_->allocator()->Allocate(eax); |
766 ASSERT(result.is_valid()); | 764 ASSERT(result.is_valid()); |
767 return result; | 765 return result; |
768 } | 766 } |
769 | 767 |
770 | 768 |
771 Result VirtualFrame::RawCallCodeObject(Handle<Code> code, | 769 Result VirtualFrame::RawCallCodeObject(Handle<Code> code, |
772 RelocInfo::Mode rmode) { | 770 RelocInfo::Mode rmode) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); | 836 Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
839 // TODO(1222589): Make the IC grab the values from the stack. | 837 // TODO(1222589): Make the IC grab the values from the stack. |
840 Result value = Pop(); | 838 Result value = Pop(); |
841 PrepareForCall(2, 0); // Two stack args, neither callee-dropped. | 839 PrepareForCall(2, 0); // Two stack args, neither callee-dropped. |
842 value.ToRegister(eax); | 840 value.ToRegister(eax); |
843 value.Unuse(); | 841 value.Unuse(); |
844 return RawCallCodeObject(ic, RelocInfo::CODE_TARGET); | 842 return RawCallCodeObject(ic, RelocInfo::CODE_TARGET); |
845 } | 843 } |
846 | 844 |
847 | 845 |
848 Result VirtualFrame::CallCodeObject(Handle<Code> code, | 846 Result VirtualFrame::CallCallIC(RelocInfo::Mode mode, |
849 RelocInfo::Mode rmode, | 847 int arg_count, |
850 Result* arg0, | 848 int loop_nesting) { |
851 Result* arg1, | 849 // Arguments, receiver, and function name are on top of the frame. |
852 int dropped_args) { | 850 // The IC expects them on the stack. It does not drop the function |
853 int spilled_args = 1; | 851 // name slot (but it does drop the rest). |
854 switch (code->kind()) { | 852 Handle<Code> ic = (loop_nesting > 0) |
855 case Code::BUILTIN: | 853 ? cgen_->ComputeCallInitializeInLoop(arg_count) |
856 ASSERT(*code == Builtins::builtin(Builtins::JSConstructCall)); | 854 : cgen_->ComputeCallInitialize(arg_count); |
857 ASSERT(arg0->reg().is(eax)); | 855 // Spill args, receiver, and function. The call will drop args and |
858 ASSERT(arg1->reg().is(edi)); | 856 // receiver. |
859 spilled_args = dropped_args + 1; | 857 PrepareForCall(arg_count + 2, arg_count + 1); |
860 break; | 858 return RawCallCodeObject(ic, mode); |
861 default: | 859 } |
862 // No other types of code objects are called with values | 860 |
863 // in exactly two registers. | 861 |
864 UNREACHABLE(); | 862 Result VirtualFrame::CallConstructor(int arg_count) { |
865 break; | 863 // Arguments, receiver, and function are on top of the frame. The |
866 } | 864 // IC expects arg count in eax, function in edi, and the arguments |
867 PrepareForCall(spilled_args, dropped_args); | 865 // and receiver on the stack. |
868 arg0->Unuse(); | 866 Handle<Code> ic(Builtins::builtin(Builtins::JSConstructCall)); |
869 arg1->Unuse(); | 867 // Duplicate the function before preparing the frame. |
870 return RawCallCodeObject(code, rmode); | 868 PushElementAt(arg_count + 1); |
| 869 Result function = Pop(); |
| 870 PrepareForCall(arg_count + 1, arg_count + 1); // Spill args and receiver. |
| 871 function.ToRegister(edi); |
| 872 |
| 873 // Constructors are called with the number of arguments in register |
| 874 // eax for now. Another option would be to have separate construct |
| 875 // call trampolines per different arguments counts encountered. |
| 876 Result num_args = cgen_->allocator()->Allocate(eax); |
| 877 ASSERT(num_args.is_valid()); |
| 878 __ Set(num_args.reg(), Immediate(arg_count)); |
| 879 |
| 880 function.Unuse(); |
| 881 num_args.Unuse(); |
| 882 return RawCallCodeObject(ic, RelocInfo::CONSTRUCT_CALL); |
871 } | 883 } |
872 | 884 |
873 | 885 |
874 void VirtualFrame::Drop(int count) { | 886 void VirtualFrame::Drop(int count) { |
875 ASSERT(height() >= count); | 887 ASSERT(height() >= count); |
876 int num_virtual_elements = (elements_.length() - 1) - stack_pointer_; | 888 int num_virtual_elements = (elements_.length() - 1) - stack_pointer_; |
877 | 889 |
878 // Emit code to lower the stack pointer if necessary. | 890 // Emit code to lower the stack pointer if necessary. |
879 if (num_virtual_elements < count) { | 891 if (num_virtual_elements < count) { |
880 int num_dropped = count - num_virtual_elements; | 892 int num_dropped = count - num_virtual_elements; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 ASSERT(stack_pointer_ == elements_.length() - 1); | 992 ASSERT(stack_pointer_ == elements_.length() - 1); |
981 elements_.Add(FrameElement::MemoryElement()); | 993 elements_.Add(FrameElement::MemoryElement()); |
982 stack_pointer_++; | 994 stack_pointer_++; |
983 __ push(immediate); | 995 __ push(immediate); |
984 } | 996 } |
985 | 997 |
986 | 998 |
987 #undef __ | 999 #undef __ |
988 | 1000 |
989 } } // namespace v8::internal | 1001 } } // namespace v8::internal |
OLD | NEW |