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

Side by Side Diff: src/arm/codegen-arm.cc

Issue 113895: Simplify deferred code by removing some unneeded or redundant stuff. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/arm/codegen-arm.h ('k') | src/codegen.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 282 }
283 283
284 // Code generation state must be reset. 284 // Code generation state must be reset.
285 ASSERT(!has_cc()); 285 ASSERT(!has_cc());
286 ASSERT(state_ == NULL); 286 ASSERT(state_ == NULL);
287 ASSERT(!function_return_is_shadowed_); 287 ASSERT(!function_return_is_shadowed_);
288 function_return_.Unuse(); 288 function_return_.Unuse();
289 DeleteFrame(); 289 DeleteFrame();
290 290
291 // Process any deferred code using the register allocator. 291 // Process any deferred code using the register allocator.
292 if (HasStackOverflow()) { 292 if (!HasStackOverflow()) {
293 ClearDeferred();
294 } else {
295 ProcessDeferred(); 293 ProcessDeferred();
296 } 294 }
297 295
298 allocator_ = NULL; 296 allocator_ = NULL;
299 scope_ = NULL; 297 scope_ = NULL;
300 } 298 }
301 299
302 300
303 MemOperand CodeGenerator::SlotOperand(Slot* slot, Register tmp) { 301 MemOperand CodeGenerator::SlotOperand(Slot* slot, Register tmp) {
304 // Currently, this assertion will fail if we try to assign to 302 // Currently, this assertion will fail if we try to assign to
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 default: 748 default:
751 // Other cases should have been handled before this point. 749 // Other cases should have been handled before this point.
752 UNREACHABLE(); 750 UNREACHABLE();
753 break; 751 break;
754 } 752 }
755 } 753 }
756 754
757 755
758 class DeferredInlineSmiOperation: public DeferredCode { 756 class DeferredInlineSmiOperation: public DeferredCode {
759 public: 757 public:
760 DeferredInlineSmiOperation(CodeGenerator* generator, 758 DeferredInlineSmiOperation(Token::Value op,
761 Token::Value op,
762 int value, 759 int value,
763 bool reversed, 760 bool reversed,
764 OverwriteMode overwrite_mode) 761 OverwriteMode overwrite_mode)
765 : DeferredCode(generator), 762 : op_(op),
766 op_(op),
767 value_(value), 763 value_(value),
768 reversed_(reversed), 764 reversed_(reversed),
769 overwrite_mode_(overwrite_mode) { 765 overwrite_mode_(overwrite_mode) {
770 set_comment("[ DeferredInlinedSmiOperation"); 766 set_comment("[ DeferredInlinedSmiOperation");
771 } 767 }
772 768
773 virtual void Generate(); 769 virtual void Generate();
774 770
775 private: 771 private:
776 Token::Value op_; 772 Token::Value op_;
777 int value_; 773 int value_;
778 bool reversed_; 774 bool reversed_;
779 OverwriteMode overwrite_mode_; 775 OverwriteMode overwrite_mode_;
780 }; 776 };
781 777
782 778
779 #undef __
780 #define __ ACCESS_MASM(masm)
781
782
783 void DeferredInlineSmiOperation::Generate() { 783 void DeferredInlineSmiOperation::Generate() {
784 MacroAssembler* masm = cgen()->masm();
784 enter()->Bind(); 785 enter()->Bind();
785 VirtualFrame::SpilledScope spilled_scope; 786 VirtualFrame::SpilledScope spilled_scope;
786 787
787 switch (op_) { 788 switch (op_) {
788 case Token::ADD: { 789 case Token::ADD: {
789 if (reversed_) { 790 if (reversed_) {
790 // revert optimistic add 791 // revert optimistic add
791 __ sub(r0, r0, Operand(Smi::FromInt(value_))); 792 __ sub(r0, r0, Operand(Smi::FromInt(value_)));
792 __ mov(r1, Operand(Smi::FromInt(value_))); 793 __ mov(r1, Operand(Smi::FromInt(value_)));
793 } else { 794 } else {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 break; 835 break;
835 } 836 }
836 837
837 default: 838 default:
838 // other cases should have been handled before this point. 839 // other cases should have been handled before this point.
839 UNREACHABLE(); 840 UNREACHABLE();
840 break; 841 break;
841 } 842 }
842 843
843 GenericBinaryOpStub igostub(op_, overwrite_mode_); 844 GenericBinaryOpStub igostub(op_, overwrite_mode_);
844 Result arg0 = generator()->allocator()->Allocate(r1); 845 Result arg0 = cgen()->allocator()->Allocate(r1);
845 ASSERT(arg0.is_valid()); 846 ASSERT(arg0.is_valid());
846 Result arg1 = generator()->allocator()->Allocate(r0); 847 Result arg1 = cgen()->allocator()->Allocate(r0);
847 ASSERT(arg1.is_valid()); 848 ASSERT(arg1.is_valid());
848 generator()->frame()->CallStub(&igostub, &arg0, &arg1); 849 cgen()->frame()->CallStub(&igostub, &arg0, &arg1);
849 exit_.Jump(); 850 exit_.Jump();
850 } 851 }
851 852
852 853
854 #undef __
855 #define __ ACCESS_MASM(masm_)
856
857
853 void CodeGenerator::SmiOperation(Token::Value op, 858 void CodeGenerator::SmiOperation(Token::Value op,
854 Handle<Object> value, 859 Handle<Object> value,
855 bool reversed, 860 bool reversed,
856 OverwriteMode mode) { 861 OverwriteMode mode) {
857 VirtualFrame::SpilledScope spilled_scope; 862 VirtualFrame::SpilledScope spilled_scope;
858 // NOTE: This is an attempt to inline (a bit) more of the code for 863 // NOTE: This is an attempt to inline (a bit) more of the code for
859 // some possible smi operations (like + and -) when (at least) one 864 // some possible smi operations (like + and -) when (at least) one
860 // of the operands is a literal smi. With this optimization, the 865 // of the operands is a literal smi. With this optimization, the
861 // performance of the system is increased by ~15%, and the generated 866 // performance of the system is increased by ~15%, and the generated
862 // code size is increased by ~1% (measured on a combination of 867 // code size is increased by ~1% (measured on a combination of
863 // different benchmarks). 868 // different benchmarks).
864 869
865 // sp[0] : operand 870 // sp[0] : operand
866 871
867 int int_value = Smi::cast(*value)->value(); 872 int int_value = Smi::cast(*value)->value();
868 873
869 JumpTarget exit; 874 JumpTarget exit;
870 frame_->EmitPop(r0); 875 frame_->EmitPop(r0);
871 876
872 switch (op) { 877 switch (op) {
873 case Token::ADD: { 878 case Token::ADD: {
874 DeferredCode* deferred = 879 DeferredCode* deferred =
875 new DeferredInlineSmiOperation(this, op, int_value, reversed, mode); 880 new DeferredInlineSmiOperation(op, int_value, reversed, mode);
876 881
877 __ add(r0, r0, Operand(value), SetCC); 882 __ add(r0, r0, Operand(value), SetCC);
878 deferred->enter()->Branch(vs); 883 deferred->enter()->Branch(vs);
879 __ tst(r0, Operand(kSmiTagMask)); 884 __ tst(r0, Operand(kSmiTagMask));
880 deferred->enter()->Branch(ne); 885 deferred->enter()->Branch(ne);
881 deferred->BindExit(); 886 deferred->BindExit();
882 break; 887 break;
883 } 888 }
884 889
885 case Token::SUB: { 890 case Token::SUB: {
886 DeferredCode* deferred = 891 DeferredCode* deferred =
887 new DeferredInlineSmiOperation(this, op, int_value, reversed, mode); 892 new DeferredInlineSmiOperation(op, int_value, reversed, mode);
888 893
889 if (!reversed) { 894 if (!reversed) {
890 __ sub(r0, r0, Operand(value), SetCC); 895 __ sub(r0, r0, Operand(value), SetCC);
891 } else { 896 } else {
892 __ rsb(r0, r0, Operand(value), SetCC); 897 __ rsb(r0, r0, Operand(value), SetCC);
893 } 898 }
894 deferred->enter()->Branch(vs); 899 deferred->enter()->Branch(vs);
895 __ tst(r0, Operand(kSmiTagMask)); 900 __ tst(r0, Operand(kSmiTagMask));
896 deferred->enter()->Branch(ne); 901 deferred->enter()->Branch(ne);
897 deferred->BindExit(); 902 deferred->BindExit();
898 break; 903 break;
899 } 904 }
900 905
901 case Token::BIT_OR: 906 case Token::BIT_OR:
902 case Token::BIT_XOR: 907 case Token::BIT_XOR:
903 case Token::BIT_AND: { 908 case Token::BIT_AND: {
904 DeferredCode* deferred = 909 DeferredCode* deferred =
905 new DeferredInlineSmiOperation(this, op, int_value, reversed, mode); 910 new DeferredInlineSmiOperation(op, int_value, reversed, mode);
906 __ tst(r0, Operand(kSmiTagMask)); 911 __ tst(r0, Operand(kSmiTagMask));
907 deferred->enter()->Branch(ne); 912 deferred->enter()->Branch(ne);
908 switch (op) { 913 switch (op) {
909 case Token::BIT_OR: __ orr(r0, r0, Operand(value)); break; 914 case Token::BIT_OR: __ orr(r0, r0, Operand(value)); break;
910 case Token::BIT_XOR: __ eor(r0, r0, Operand(value)); break; 915 case Token::BIT_XOR: __ eor(r0, r0, Operand(value)); break;
911 case Token::BIT_AND: __ and_(r0, r0, Operand(value)); break; 916 case Token::BIT_AND: __ and_(r0, r0, Operand(value)); break;
912 default: UNREACHABLE(); 917 default: UNREACHABLE();
913 } 918 }
914 deferred->BindExit(); 919 deferred->BindExit();
915 break; 920 break;
916 } 921 }
917 922
918 case Token::SHL: 923 case Token::SHL:
919 case Token::SHR: 924 case Token::SHR:
920 case Token::SAR: { 925 case Token::SAR: {
921 if (reversed) { 926 if (reversed) {
922 __ mov(ip, Operand(value)); 927 __ mov(ip, Operand(value));
923 frame_->EmitPush(ip); 928 frame_->EmitPush(ip);
924 frame_->EmitPush(r0); 929 frame_->EmitPush(r0);
925 GenericBinaryOperation(op, mode); 930 GenericBinaryOperation(op, mode);
926 931
927 } else { 932 } else {
928 int shift_value = int_value & 0x1f; // least significant 5 bits 933 int shift_value = int_value & 0x1f; // least significant 5 bits
929 DeferredCode* deferred = 934 DeferredCode* deferred =
930 new DeferredInlineSmiOperation(this, op, shift_value, false, mode); 935 new DeferredInlineSmiOperation(op, shift_value, false, mode);
931 __ tst(r0, Operand(kSmiTagMask)); 936 __ tst(r0, Operand(kSmiTagMask));
932 deferred->enter()->Branch(ne); 937 deferred->enter()->Branch(ne);
933 __ mov(r2, Operand(r0, ASR, kSmiTagSize)); // remove tags 938 __ mov(r2, Operand(r0, ASR, kSmiTagSize)); // remove tags
934 switch (op) { 939 switch (op) {
935 case Token::SHL: { 940 case Token::SHL: {
936 __ mov(r2, Operand(r2, LSL, shift_value)); 941 __ mov(r2, Operand(r2, LSL, shift_value));
937 // check that the *unsigned* result fits in a smi 942 // check that the *unsigned* result fits in a smi
938 __ add(r3, r2, Operand(0x40000000), SetCC); 943 __ add(r3, r2, Operand(0x40000000), SetCC);
939 deferred->enter()->Branch(mi); 944 deferred->enter()->Branch(mi);
940 break; 945 break;
(...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after
2647 ASSERT(frame_->height() == original_height + 1); 2652 ASSERT(frame_->height() == original_height + 1);
2648 } 2653 }
2649 2654
2650 2655
2651 // This deferred code stub will be used for creating the boilerplate 2656 // This deferred code stub will be used for creating the boilerplate
2652 // by calling Runtime_CreateObjectLiteralBoilerplate. 2657 // by calling Runtime_CreateObjectLiteralBoilerplate.
2653 // Each created boilerplate is stored in the JSFunction and they are 2658 // Each created boilerplate is stored in the JSFunction and they are
2654 // therefore context dependent. 2659 // therefore context dependent.
2655 class DeferredObjectLiteral: public DeferredCode { 2660 class DeferredObjectLiteral: public DeferredCode {
2656 public: 2661 public:
2657 DeferredObjectLiteral(CodeGenerator* generator, ObjectLiteral* node) 2662 DeferredObjectLiteral(ObjectLiteral* node) : node_(node) {
2658 : DeferredCode(generator), node_(node) {
2659 set_comment("[ DeferredObjectLiteral"); 2663 set_comment("[ DeferredObjectLiteral");
2660 } 2664 }
2661 2665
2662 virtual void Generate(); 2666 virtual void Generate();
2663 2667
2664 private: 2668 private:
2665 ObjectLiteral* node_; 2669 ObjectLiteral* node_;
2666 }; 2670 };
2667 2671
2668 2672
2673 #undef __
2674 #define __ ACCESS_MASM(masm)
2675
2676
2669 void DeferredObjectLiteral::Generate() { 2677 void DeferredObjectLiteral::Generate() {
2678 MacroAssembler* masm = cgen()->masm();
2670 // Argument is passed in r1. 2679 // Argument is passed in r1.
2671 enter()->Bind(); 2680 enter()->Bind();
2672 VirtualFrame::SpilledScope spilled_scope; 2681 VirtualFrame::SpilledScope spilled_scope;
2673 2682
2674 // If the entry is undefined we call the runtime system to compute 2683 // If the entry is undefined we call the runtime system to compute
2675 // the literal. 2684 // the literal.
2676 2685
2677 VirtualFrame* frame = generator()->frame(); 2686 VirtualFrame* frame = cgen()->frame();
2678 // Literal array (0). 2687 // Literal array (0).
2679 frame->EmitPush(r1); 2688 frame->EmitPush(r1);
2680 // Literal index (1). 2689 // Literal index (1).
2681 __ mov(r0, Operand(Smi::FromInt(node_->literal_index()))); 2690 __ mov(r0, Operand(Smi::FromInt(node_->literal_index())));
2682 frame->EmitPush(r0); 2691 frame->EmitPush(r0);
2683 // Constant properties (2). 2692 // Constant properties (2).
2684 __ mov(r0, Operand(node_->constant_properties())); 2693 __ mov(r0, Operand(node_->constant_properties()));
2685 frame->EmitPush(r0); 2694 frame->EmitPush(r0);
2686 Result boilerplate = 2695 Result boilerplate =
2687 frame->CallRuntime(Runtime::kCreateObjectLiteralBoilerplate, 3); 2696 frame->CallRuntime(Runtime::kCreateObjectLiteralBoilerplate, 3);
2688 __ mov(r2, Operand(boilerplate.reg())); 2697 __ mov(r2, Operand(boilerplate.reg()));
2689 // Result is returned in r2. 2698 // Result is returned in r2.
2690 exit_.Jump(); 2699 exit_.Jump();
2691 } 2700 }
2692 2701
2693 2702
2703 #undef __
2704 #define __ ACCESS_MASM(masm_)
2705
2706
2694 void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { 2707 void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) {
2695 #ifdef DEBUG 2708 #ifdef DEBUG
2696 int original_height = frame_->height(); 2709 int original_height = frame_->height();
2697 #endif 2710 #endif
2698 VirtualFrame::SpilledScope spilled_scope; 2711 VirtualFrame::SpilledScope spilled_scope;
2699 Comment cmnt(masm_, "[ ObjectLiteral"); 2712 Comment cmnt(masm_, "[ ObjectLiteral");
2700 2713
2701 DeferredObjectLiteral* deferred = new DeferredObjectLiteral(this, node); 2714 DeferredObjectLiteral* deferred = new DeferredObjectLiteral(node);
2702 2715
2703 // Retrieve the literal array and check the allocated entry. 2716 // Retrieve the literal array and check the allocated entry.
2704 2717
2705 // Load the function of this activation. 2718 // Load the function of this activation.
2706 __ ldr(r1, frame_->Function()); 2719 __ ldr(r1, frame_->Function());
2707 2720
2708 // Load the literals array of the function. 2721 // Load the literals array of the function.
2709 __ ldr(r1, FieldMemOperand(r1, JSFunction::kLiteralsOffset)); 2722 __ ldr(r1, FieldMemOperand(r1, JSFunction::kLiteralsOffset));
2710 2723
2711 // Load the literal at the ast saved index. 2724 // Load the literal at the ast saved index.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 ASSERT(frame_->height() == original_height + 1); 2789 ASSERT(frame_->height() == original_height + 1);
2777 } 2790 }
2778 2791
2779 2792
2780 // This deferred code stub will be used for creating the boilerplate 2793 // This deferred code stub will be used for creating the boilerplate
2781 // by calling Runtime_CreateArrayLiteralBoilerplate. 2794 // by calling Runtime_CreateArrayLiteralBoilerplate.
2782 // Each created boilerplate is stored in the JSFunction and they are 2795 // Each created boilerplate is stored in the JSFunction and they are
2783 // therefore context dependent. 2796 // therefore context dependent.
2784 class DeferredArrayLiteral: public DeferredCode { 2797 class DeferredArrayLiteral: public DeferredCode {
2785 public: 2798 public:
2786 DeferredArrayLiteral(CodeGenerator* generator, ArrayLiteral* node) 2799 DeferredArrayLiteral(ArrayLiteral* node) : node_(node) {
2787 : DeferredCode(generator), node_(node) {
2788 set_comment("[ DeferredArrayLiteral"); 2800 set_comment("[ DeferredArrayLiteral");
2789 } 2801 }
2790 2802
2791 virtual void Generate(); 2803 virtual void Generate();
2792 2804
2793 private: 2805 private:
2794 ArrayLiteral* node_; 2806 ArrayLiteral* node_;
2795 }; 2807 };
2796 2808
2797 2809
2810 #undef __
2811 #define __ ACCESS_MASM(masm)
2812
2813
2798 void DeferredArrayLiteral::Generate() { 2814 void DeferredArrayLiteral::Generate() {
2815 MacroAssembler* masm = cgen()->masm();
2799 // Argument is passed in r1. 2816 // Argument is passed in r1.
2800 enter()->Bind(); 2817 enter()->Bind();
2801 VirtualFrame::SpilledScope spilled_scope; 2818 VirtualFrame::SpilledScope spilled_scope;
2802 2819
2803 // If the entry is undefined we call the runtime system to computed 2820 // If the entry is undefined we call the runtime system to computed
2804 // the literal. 2821 // the literal.
2805 2822
2806 VirtualFrame* frame = generator()->frame(); 2823 VirtualFrame* frame = cgen()->frame();
2807 // Literal array (0). 2824 // Literal array (0).
2808 frame->EmitPush(r1); 2825 frame->EmitPush(r1);
2809 // Literal index (1). 2826 // Literal index (1).
2810 __ mov(r0, Operand(Smi::FromInt(node_->literal_index()))); 2827 __ mov(r0, Operand(Smi::FromInt(node_->literal_index())));
2811 frame->EmitPush(r0); 2828 frame->EmitPush(r0);
2812 // Constant properties (2). 2829 // Constant properties (2).
2813 __ mov(r0, Operand(node_->literals())); 2830 __ mov(r0, Operand(node_->literals()));
2814 frame->EmitPush(r0); 2831 frame->EmitPush(r0);
2815 Result boilerplate = 2832 Result boilerplate =
2816 frame->CallRuntime(Runtime::kCreateArrayLiteralBoilerplate, 3); 2833 frame->CallRuntime(Runtime::kCreateArrayLiteralBoilerplate, 3);
2817 __ mov(r2, Operand(boilerplate.reg())); 2834 __ mov(r2, Operand(boilerplate.reg()));
2818 // Result is returned in r2. 2835 // Result is returned in r2.
2819 exit_.Jump(); 2836 exit_.Jump();
2820 } 2837 }
2821 2838
2822 2839
2840 #undef __
2841 #define __ ACCESS_MASM(masm_)
2842
2843
2823 void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { 2844 void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) {
2824 #ifdef DEBUG 2845 #ifdef DEBUG
2825 int original_height = frame_->height(); 2846 int original_height = frame_->height();
2826 #endif 2847 #endif
2827 VirtualFrame::SpilledScope spilled_scope; 2848 VirtualFrame::SpilledScope spilled_scope;
2828 Comment cmnt(masm_, "[ ArrayLiteral"); 2849 Comment cmnt(masm_, "[ ArrayLiteral");
2829 2850
2830 DeferredArrayLiteral* deferred = new DeferredArrayLiteral(this, node); 2851 DeferredArrayLiteral* deferred = new DeferredArrayLiteral(node);
2831 2852
2832 // Retrieve the literal array and check the allocated entry. 2853 // Retrieve the literal array and check the allocated entry.
2833 2854
2834 // Load the function of this activation. 2855 // Load the function of this activation.
2835 __ ldr(r1, frame_->Function()); 2856 __ ldr(r1, frame_->Function());
2836 2857
2837 // Load the literals array of the function. 2858 // Load the literals array of the function.
2838 __ ldr(r1, FieldMemOperand(r1, JSFunction::kLiteralsOffset)); 2859 __ ldr(r1, FieldMemOperand(r1, JSFunction::kLiteralsOffset));
2839 2860
2840 // Load the literal at the ast saved index. 2861 // Load the literal at the ast saved index.
(...skipping 2348 matching lines...) Expand 10 before | Expand all | Expand 10 after
5189 __ mov(r2, Operand(0)); 5210 __ mov(r2, Operand(0));
5190 __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); 5211 __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION);
5191 __ Jump(Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)), 5212 __ Jump(Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)),
5192 RelocInfo::CODE_TARGET); 5213 RelocInfo::CODE_TARGET);
5193 } 5214 }
5194 5215
5195 5216
5196 #undef __ 5217 #undef __
5197 5218
5198 } } // namespace v8::internal 5219 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/codegen-arm.h ('k') | src/codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698