| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 nesting_stack_(NULL), | 84 nesting_stack_(NULL), |
| 85 loop_depth_(0), | 85 loop_depth_(0), |
| 86 global_count_(0), | 86 global_count_(0), |
| 87 context_(NULL), | 87 context_(NULL), |
| 88 bailout_entries_(info->HasDeoptimizationSupport() | 88 bailout_entries_(info->HasDeoptimizationSupport() |
| 89 ? info->function()->ast_node_count() : 0), | 89 ? info->function()->ast_node_count() : 0), |
| 90 stack_checks_(2), // There's always at least one. | 90 stack_checks_(2), // There's always at least one. |
| 91 type_feedback_cells_(info->HasDeoptimizationSupport() | 91 type_feedback_cells_(info->HasDeoptimizationSupport() |
| 92 ? info->function()->ast_node_count() : 0), | 92 ? info->function()->ast_node_count() : 0), |
| 93 ic_total_count_(0), | 93 ic_total_count_(0), |
| 94 has_self_optimization_header_(false) { } | 94 has_self_optimization_header_(false), |
| 95 immediate_return_enabled_(false) { } |
| 95 | 96 |
| 96 static bool MakeCode(CompilationInfo* info); | 97 static bool MakeCode(CompilationInfo* info); |
| 97 | 98 |
| 98 // Returns the platform-specific size in bytes of the self-optimization | 99 // Returns the platform-specific size in bytes of the self-optimization |
| 99 // header. | 100 // header. |
| 100 static int self_optimization_header_size(); | 101 static int self_optimization_header_size(); |
| 101 | 102 |
| 102 // Encode state and pc-offset as a BitField<type, start, size>. | 103 // Encode state and pc-offset as a BitField<type, start, size>. |
| 103 // Only use 30 bits because we encode the result as a smi. | 104 // Only use 30 bits because we encode the result as a smi. |
| 104 class StateField : public BitField<State, 0, 1> { }; | 105 class StateField : public BitField<State, 0, 1> { }; |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 bool is_native() { return info_->is_native(); } | 556 bool is_native() { return info_->is_native(); } |
| 556 bool is_classic_mode() { | 557 bool is_classic_mode() { |
| 557 return language_mode() == CLASSIC_MODE; | 558 return language_mode() == CLASSIC_MODE; |
| 558 } | 559 } |
| 559 LanguageMode language_mode() { | 560 LanguageMode language_mode() { |
| 560 return function()->language_mode(); | 561 return function()->language_mode(); |
| 561 } | 562 } |
| 562 FunctionLiteral* function() { return info_->function(); } | 563 FunctionLiteral* function() { return info_->function(); } |
| 563 Scope* scope() { return scope_; } | 564 Scope* scope() { return scope_; } |
| 564 | 565 |
| 566 bool immediate_return_enabled() { return immediate_return_enabled_; } |
| 567 |
| 565 static Register result_register(); | 568 static Register result_register(); |
| 566 static Register context_register(); | 569 static Register context_register(); |
| 567 | 570 |
| 568 // Set fields in the stack frame. Offsets are the frame pointer relative | 571 // Set fields in the stack frame. Offsets are the frame pointer relative |
| 569 // offsets defined in, e.g., StandardFrameConstants. | 572 // offsets defined in, e.g., StandardFrameConstants. |
| 570 void StoreToFrameField(int frame_offset, Register value); | 573 void StoreToFrameField(int frame_offset, Register value); |
| 571 | 574 |
| 572 // Load a value from the current context. Indices are defined as an enum | 575 // Load a value from the current context. Indices are defined as an enum |
| 573 // in v8::internal::Context. | 576 // in v8::internal::Context. |
| 574 void LoadContextField(Register dst, int context_index); | 577 void LoadContextField(Register dst, int context_index); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 virtual bool IsEffect() const { return false; } | 662 virtual bool IsEffect() const { return false; } |
| 660 | 663 |
| 661 // Returns true if we are evaluating for the value (in accu/on stack). | 664 // Returns true if we are evaluating for the value (in accu/on stack). |
| 662 virtual bool IsAccumulatorValue() const { return false; } | 665 virtual bool IsAccumulatorValue() const { return false; } |
| 663 virtual bool IsStackValue() const { return false; } | 666 virtual bool IsStackValue() const { return false; } |
| 664 | 667 |
| 665 // Returns true if we are branching on the value rather than materializing | 668 // Returns true if we are branching on the value rather than materializing |
| 666 // it. Only used for asserts. | 669 // it. Only used for asserts. |
| 667 virtual bool IsTest() const { return false; } | 670 virtual bool IsTest() const { return false; } |
| 668 | 671 |
| 672 // Returns true if we are branching on the value that can be returned. |
| 673 virtual bool IsReturnable() const { return false; } |
| 674 |
| 669 protected: | 675 protected: |
| 670 FullCodeGenerator* codegen() const { return codegen_; } | 676 FullCodeGenerator* codegen() const { return codegen_; } |
| 671 MacroAssembler* masm() const { return masm_; } | 677 MacroAssembler* masm() const { return masm_; } |
| 672 MacroAssembler* masm_; | 678 MacroAssembler* masm_; |
| 673 | 679 |
| 674 private: | 680 private: |
| 675 const ExpressionContext* old_; | 681 const ExpressionContext* old_; |
| 676 FullCodeGenerator* codegen_; | 682 FullCodeGenerator* codegen_; |
| 677 }; | 683 }; |
| 678 | 684 |
| 679 class AccumulatorValueContext : public ExpressionContext { | 685 class AccumulatorValueContext : public ExpressionContext { |
| 680 public: | 686 public: |
| 681 explicit AccumulatorValueContext(FullCodeGenerator* codegen) | 687 explicit AccumulatorValueContext(FullCodeGenerator* codegen) |
| 682 : ExpressionContext(codegen) { } | 688 : ExpressionContext(codegen) { } |
| 683 | 689 |
| 684 virtual void Plug(bool flag) const; | 690 virtual void Plug(bool flag) const; |
| 685 virtual void Plug(Register reg) const; | 691 virtual void Plug(Register reg) const; |
| 686 virtual void Plug(Label* materialize_true, Label* materialize_false) const; | 692 virtual void Plug(Label* materialize_true, Label* materialize_false) const; |
| 687 virtual void Plug(Variable* var) const; | 693 virtual void Plug(Variable* var) const; |
| 688 virtual void Plug(Handle<Object> lit) const; | 694 virtual void Plug(Handle<Object> lit) const; |
| 689 virtual void Plug(Heap::RootListIndex) const; | 695 virtual void Plug(Heap::RootListIndex) const; |
| 690 virtual void PlugTOS() const; | 696 virtual void PlugTOS() const; |
| 691 virtual void DropAndPlug(int count, Register reg) const; | 697 virtual void DropAndPlug(int count, Register reg) const; |
| 692 virtual void PrepareTest(Label* materialize_true, | 698 virtual void PrepareTest(Label* materialize_true, |
| 693 Label* materialize_false, | 699 Label* materialize_false, |
| 694 Label** if_true, | 700 Label** if_true, |
| 695 Label** if_false, | 701 Label** if_false, |
| 696 Label** fall_through) const; | 702 Label** fall_through) const; |
| 697 virtual bool IsAccumulatorValue() const { return true; } | 703 virtual bool IsAccumulatorValue() const { return true; } |
| 704 virtual bool IsReturnable() const { |
| 705 return codegen()->immediate_return_enabled(); |
| 706 } |
| 698 }; | 707 }; |
| 699 | 708 |
| 700 class StackValueContext : public ExpressionContext { | 709 class StackValueContext : public ExpressionContext { |
| 701 public: | 710 public: |
| 702 explicit StackValueContext(FullCodeGenerator* codegen) | 711 explicit StackValueContext(FullCodeGenerator* codegen) |
| 703 : ExpressionContext(codegen) { } | 712 : ExpressionContext(codegen) { } |
| 704 | 713 |
| 705 virtual void Plug(bool flag) const; | 714 virtual void Plug(bool flag) const; |
| 706 virtual void Plug(Register reg) const; | 715 virtual void Plug(Register reg) const; |
| 707 virtual void Plug(Label* materialize_true, Label* materialize_false) const; | 716 virtual void Plug(Label* materialize_true, Label* materialize_false) const; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 virtual void PlugTOS() const; | 786 virtual void PlugTOS() const; |
| 778 virtual void DropAndPlug(int count, Register reg) const; | 787 virtual void DropAndPlug(int count, Register reg) const; |
| 779 virtual void PrepareTest(Label* materialize_true, | 788 virtual void PrepareTest(Label* materialize_true, |
| 780 Label* materialize_false, | 789 Label* materialize_false, |
| 781 Label** if_true, | 790 Label** if_true, |
| 782 Label** if_false, | 791 Label** if_false, |
| 783 Label** fall_through) const; | 792 Label** fall_through) const; |
| 784 virtual bool IsEffect() const { return true; } | 793 virtual bool IsEffect() const { return true; } |
| 785 }; | 794 }; |
| 786 | 795 |
| 796 class ImmediateReturnEnabled { |
| 797 public: |
| 798 explicit ImmediateReturnEnabled(FullCodeGenerator* codegen) |
| 799 : codegen_(codegen), old_(codegen->immediate_return_enabled_) { |
| 800 codegen_->immediate_return_enabled_ = true; |
| 801 } |
| 802 virtual ~ImmediateReturnEnabled() { |
| 803 codegen_->immediate_return_enabled_ = old_; |
| 804 } |
| 805 |
| 806 private: |
| 807 FullCodeGenerator* codegen_; |
| 808 bool old_; |
| 809 }; |
| 810 |
| 811 class ImmediateReturnDisabled { |
| 812 public: |
| 813 explicit ImmediateReturnDisabled(FullCodeGenerator* codegen) |
| 814 : codegen_(codegen), old_(codegen->immediate_return_enabled_) { |
| 815 codegen_->immediate_return_enabled_ = false; |
| 816 } |
| 817 virtual ~ImmediateReturnDisabled() { |
| 818 codegen_->immediate_return_enabled_ = old_; |
| 819 } |
| 820 |
| 821 private: |
| 822 FullCodeGenerator* codegen_; |
| 823 bool old_; |
| 824 }; |
| 825 |
| 787 MacroAssembler* masm_; | 826 MacroAssembler* masm_; |
| 788 CompilationInfo* info_; | 827 CompilationInfo* info_; |
| 789 Scope* scope_; | 828 Scope* scope_; |
| 790 Label return_label_; | 829 Label return_label_; |
| 791 NestedStatement* nesting_stack_; | 830 NestedStatement* nesting_stack_; |
| 792 int loop_depth_; | 831 int loop_depth_; |
| 793 int global_count_; | 832 int global_count_; |
| 794 const ExpressionContext* context_; | 833 const ExpressionContext* context_; |
| 795 ZoneList<BailoutEntry> bailout_entries_; | 834 ZoneList<BailoutEntry> bailout_entries_; |
| 796 ZoneList<BailoutEntry> stack_checks_; | 835 ZoneList<BailoutEntry> stack_checks_; |
| 797 ZoneList<TypeFeedbackCellEntry> type_feedback_cells_; | 836 ZoneList<TypeFeedbackCellEntry> type_feedback_cells_; |
| 798 int ic_total_count_; | 837 int ic_total_count_; |
| 799 bool has_self_optimization_header_; | 838 bool has_self_optimization_header_; |
| 800 Handle<FixedArray> handler_table_; | 839 Handle<FixedArray> handler_table_; |
| 801 Handle<JSGlobalPropertyCell> profiling_counter_; | 840 Handle<JSGlobalPropertyCell> profiling_counter_; |
| 841 bool immediate_return_enabled_; |
| 802 | 842 |
| 803 friend class NestedStatement; | 843 friend class NestedStatement; |
| 804 | 844 |
| 805 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator); | 845 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator); |
| 806 }; | 846 }; |
| 807 | 847 |
| 808 | 848 |
| 809 // A map from property names to getter/setter pairs allocated in the zone. | 849 // A map from property names to getter/setter pairs allocated in the zone. |
| 810 class AccessorTable: public TemplateHashMap<Literal, | 850 class AccessorTable: public TemplateHashMap<Literal, |
| 811 ObjectLiteral::Accessors, | 851 ObjectLiteral::Accessors, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 824 } | 864 } |
| 825 | 865 |
| 826 private: | 866 private: |
| 827 Zone* zone_; | 867 Zone* zone_; |
| 828 }; | 868 }; |
| 829 | 869 |
| 830 | 870 |
| 831 } } // namespace v8::internal | 871 } } // namespace v8::internal |
| 832 | 872 |
| 833 #endif // V8_FULL_CODEGEN_H_ | 873 #endif // V8_FULL_CODEGEN_H_ |
| OLD | NEW |