| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 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 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 void Print(); | 652 void Print(); |
| 653 #endif | 653 #endif |
| 654 | 654 |
| 655 private: | 655 private: |
| 656 // Entry and exit nodes. | 656 // Entry and exit nodes. |
| 657 CfgNode* entry_; | 657 CfgNode* entry_; |
| 658 CfgNode* exit_; | 658 CfgNode* exit_; |
| 659 }; | 659 }; |
| 660 | 660 |
| 661 | 661 |
| 662 // An implementation of a set of locations (currently slot locations). | 662 // An implementation of a set of locations (currently slot locations), most |
| 663 // of the operations are destructive. |
| 663 class LocationSet BASE_EMBEDDED { | 664 class LocationSet BASE_EMBEDDED { |
| 664 public: | 665 public: |
| 665 // Construct an empty location set. | 666 // Construct an empty location set. |
| 666 LocationSet() : parameters_(0), locals_(0) {} | 667 LocationSet() : parameters_(0), locals_(0) {} |
| 667 | 668 |
| 668 // Raw accessors. | 669 // Raw accessors. |
| 669 uintptr_t parameters() { return parameters_; } | 670 uintptr_t parameters() { return parameters_; } |
| 670 uintptr_t locals() { return locals_; } | 671 uintptr_t locals() { return locals_; } |
| 671 | 672 |
| 673 // Make this the empty set. |
| 674 void Empty() { |
| 675 parameters_ = locals_ = 0; |
| 676 } |
| 677 |
| 672 // Insert an element. | 678 // Insert an element. |
| 673 void AddElement(SlotLocation* location) { | 679 void AddElement(SlotLocation* location) { |
| 674 if (location->type() == Slot::PARAMETER) { | 680 if (location->type() == Slot::PARAMETER) { |
| 675 // Parameter indexes begin with -1 ('this'). | 681 // Parameter indexes begin with -1 ('this'). |
| 676 ASSERT(location->index() < kPointerSize - 1); | 682 ASSERT(location->index() < kPointerSize - 1); |
| 677 parameters_ |= (1 << (location->index() + 1)); | 683 parameters_ |= (1 << (location->index() + 1)); |
| 678 } else { | 684 } else { |
| 679 ASSERT(location->type() == Slot::LOCAL); | 685 ASSERT(location->type() == Slot::LOCAL); |
| 680 ASSERT(location->index() < kPointerSize); | 686 ASSERT(location->index() < kPointerSize); |
| 681 locals_ |= (1 << location->index()); | 687 locals_ |= (1 << location->index()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 698 return (locals_ & (1 << location->index())); | 704 return (locals_ & (1 << location->index())); |
| 699 } | 705 } |
| 700 } | 706 } |
| 701 | 707 |
| 702 private: | 708 private: |
| 703 uintptr_t parameters_; | 709 uintptr_t parameters_; |
| 704 uintptr_t locals_; | 710 uintptr_t locals_; |
| 705 }; | 711 }; |
| 706 | 712 |
| 707 | 713 |
| 708 // An ExpressionBuilder traverses an expression and returns an open CFG | 714 // An ExpressionCfgBuilder traverses an expression and returns an open CFG |
| 709 // fragment (currently a possibly empty list of instructions represented by | 715 // fragment (currently a possibly empty list of instructions represented by |
| 710 // a singleton instruction block) and the expression's value. | 716 // a singleton instruction block) and the expression's value. |
| 711 // | 717 // |
| 712 // Failure is to build the CFG is indicated by a NULL CFG. | 718 // Failure to build the CFG is indicated by a NULL CFG. |
| 713 class ExpressionBuilder : public AstVisitor { | 719 class ExpressionCfgBuilder : public AstVisitor { |
| 714 public: | 720 public: |
| 715 ExpressionBuilder() : value_(NULL), graph_(NULL), destination_(NULL) {} | 721 ExpressionCfgBuilder() : destination_(NULL), value_(NULL), graph_(NULL) {} |
| 716 | 722 |
| 717 // Result accessors. | 723 // Result accessors. |
| 718 Value* value() { return value_; } | 724 Value* value() { return value_; } |
| 719 Cfg* graph() { return graph_; } | 725 Cfg* graph() { return graph_; } |
| 720 LocationSet* assigned_vars() { return &assigned_vars_; } | 726 LocationSet* assigned_vars() { return &assigned_vars_; } |
| 721 | 727 |
| 722 // Build the cfg for an expression and remember its value. The | 728 // Build the cfg for an expression and remember its value. The |
| 723 // destination is a 'hint' where the value should go which may be ignored. | 729 // destination is a 'hint' where the value should go which may be ignored. |
| 724 // NULL is used to indicate no preference. | 730 // NULL is used to indicate no preference. |
| 725 // | 731 // |
| 726 // Concretely, if the expression needs to generate a temporary for its | 732 // Concretely, if the expression needs to generate a temporary for its |
| 727 // value, it should use the passed destination or generate one if NULL. | 733 // value, it should use the passed destination or generate one if NULL. |
| 728 void Build(Expression* expr, Location* destination) { | 734 void Build(Expression* expr, Location* destination) { |
| 729 value_ = NULL; | 735 value_ = NULL; |
| 730 graph_ = new Cfg(); | 736 graph_ = new Cfg(); |
| 737 assigned_vars_.Empty(); |
| 731 destination_ = destination; | 738 destination_ = destination; |
| 732 Visit(expr); | 739 Visit(expr); |
| 733 } | 740 } |
| 734 | 741 |
| 735 // AST node visitors. | 742 // AST node visitors. |
| 736 #define DECLARE_VISIT(type) void Visit##type(type* node); | 743 #define DECLARE_VISIT(type) void Visit##type(type* node); |
| 737 AST_NODE_LIST(DECLARE_VISIT) | 744 AST_NODE_LIST(DECLARE_VISIT) |
| 738 #undef DECLARE_VISIT | 745 #undef DECLARE_VISIT |
| 739 | 746 |
| 740 private: | 747 private: |
| 741 // State for the visitor. Output parameters. | 748 // State for the visitor. Input parameters: |
| 749 Location* destination_; |
| 750 |
| 751 // Output parameters: |
| 742 Value* value_; | 752 Value* value_; |
| 743 Cfg* graph_; | 753 Cfg* graph_; |
| 744 LocationSet assigned_vars_; | 754 LocationSet assigned_vars_; |
| 745 | |
| 746 // Input parameters. | |
| 747 Location* destination_; | |
| 748 }; | 755 }; |
| 749 | 756 |
| 750 | 757 |
| 751 // A StatementBuilder maintains a CFG fragment accumulator. When it visits | 758 // A StatementCfgBuilder maintains a CFG fragment accumulator. When it |
| 752 // a statement, it concatenates the CFG for the statement to the end of the | 759 // visits a statement, it concatenates the CFG for the statement to the end |
| 753 // accumulator. | 760 // of the accumulator. |
| 754 class StatementBuilder : public AstVisitor { | 761 class StatementCfgBuilder : public AstVisitor { |
| 755 public: | 762 public: |
| 756 StatementBuilder() : graph_(new Cfg()) {} | 763 StatementCfgBuilder() : graph_(new Cfg()) {} |
| 757 | 764 |
| 758 Cfg* graph() { return graph_; } | 765 Cfg* graph() { return graph_; } |
| 759 | 766 |
| 760 void VisitStatements(ZoneList<Statement*>* stmts); | 767 void VisitStatements(ZoneList<Statement*>* stmts); |
| 761 | 768 |
| 762 // AST node visitors. | 769 // AST node visitors. |
| 763 #define DECLARE_VISIT(type) void Visit##type(type* node); | 770 #define DECLARE_VISIT(type) void Visit##type(type* node); |
| 764 AST_NODE_LIST(DECLARE_VISIT) | 771 AST_NODE_LIST(DECLARE_VISIT) |
| 765 #undef DECLARE_VISIT | 772 #undef DECLARE_VISIT |
| 766 | 773 |
| 767 private: | 774 private: |
| 775 // State for the visitor. Input/output parameter: |
| 768 Cfg* graph_; | 776 Cfg* graph_; |
| 769 }; | 777 }; |
| 770 | 778 |
| 771 | 779 |
| 772 } } // namespace v8::internal | 780 } } // namespace v8::internal |
| 773 | 781 |
| 774 #endif // V8_CFG_H_ | 782 #endif // V8_CFG_H_ |
| OLD | NEW |