OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_HYDROGEN_H_ | 5 #ifndef V8_HYDROGEN_H_ |
6 #define V8_HYDROGEN_H_ | 6 #define V8_HYDROGEN_H_ |
7 | 7 |
8 #include "v8.h" | 8 #include "v8.h" |
9 | 9 |
10 #include "accessors.h" | 10 #include "accessors.h" |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 PretenureFlag pretenure_flag_; | 1035 PretenureFlag pretenure_flag_; |
1036 }; | 1036 }; |
1037 | 1037 |
1038 | 1038 |
1039 class HGraphBuilder { | 1039 class HGraphBuilder { |
1040 public: | 1040 public: |
1041 explicit HGraphBuilder(CompilationInfo* info) | 1041 explicit HGraphBuilder(CompilationInfo* info) |
1042 : info_(info), | 1042 : info_(info), |
1043 graph_(NULL), | 1043 graph_(NULL), |
1044 current_block_(NULL), | 1044 current_block_(NULL), |
| 1045 scope_(info->scope()), |
1045 position_(HSourcePosition::Unknown()), | 1046 position_(HSourcePosition::Unknown()), |
1046 start_position_(0) {} | 1047 start_position_(0) {} |
1047 virtual ~HGraphBuilder() {} | 1048 virtual ~HGraphBuilder() {} |
1048 | 1049 |
| 1050 Scope* scope() const { return scope_; } |
| 1051 void set_scope(Scope* scope) { scope_ = scope; } |
| 1052 |
1049 HBasicBlock* current_block() const { return current_block_; } | 1053 HBasicBlock* current_block() const { return current_block_; } |
1050 void set_current_block(HBasicBlock* block) { current_block_ = block; } | 1054 void set_current_block(HBasicBlock* block) { current_block_ = block; } |
1051 HEnvironment* environment() const { | 1055 HEnvironment* environment() const { |
1052 return current_block()->last_environment(); | 1056 return current_block()->last_environment(); |
1053 } | 1057 } |
1054 Zone* zone() const { return info_->zone(); } | 1058 Zone* zone() const { return info_->zone(); } |
1055 HGraph* graph() const { return graph_; } | 1059 HGraph* graph() const { return graph_; } |
1056 Isolate* isolate() const { return graph_->isolate(); } | 1060 Isolate* isolate() const { return graph_->isolate(); } |
1057 CompilationInfo* top_info() { return info_; } | 1061 CompilationInfo* top_info() { return info_; } |
1058 | 1062 |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 int current_probe); | 1853 int current_probe); |
1850 | 1854 |
1851 template <class I> | 1855 template <class I> |
1852 I* AddInstructionTyped(I* instr) { | 1856 I* AddInstructionTyped(I* instr) { |
1853 return I::cast(AddInstruction(instr)); | 1857 return I::cast(AddInstruction(instr)); |
1854 } | 1858 } |
1855 | 1859 |
1856 CompilationInfo* info_; | 1860 CompilationInfo* info_; |
1857 HGraph* graph_; | 1861 HGraph* graph_; |
1858 HBasicBlock* current_block_; | 1862 HBasicBlock* current_block_; |
| 1863 Scope* scope_; |
1859 HSourcePosition position_; | 1864 HSourcePosition position_; |
1860 int start_position_; | 1865 int start_position_; |
1861 }; | 1866 }; |
1862 | 1867 |
1863 | 1868 |
1864 template<> | 1869 template<> |
1865 inline HDeoptimize* HGraphBuilder::Add<HDeoptimize>( | 1870 inline HDeoptimize* HGraphBuilder::Add<HDeoptimize>( |
1866 const char* reason, Deoptimizer::BailoutType type) { | 1871 const char* reason, Deoptimizer::BailoutType type) { |
1867 if (type == Deoptimizer::SOFT) { | 1872 if (type == Deoptimizer::SOFT) { |
1868 isolate()->counters()->soft_deopts_requested()->Increment(); | 1873 isolate()->counters()->soft_deopts_requested()->Increment(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1976 } | 1981 } |
1977 | 1982 |
1978 class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { | 1983 class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { |
1979 public: | 1984 public: |
1980 // A class encapsulating (lazily-allocated) break and continue blocks for | 1985 // A class encapsulating (lazily-allocated) break and continue blocks for |
1981 // a breakable statement. Separated from BreakAndContinueScope so that it | 1986 // a breakable statement. Separated from BreakAndContinueScope so that it |
1982 // can have a separate lifetime. | 1987 // can have a separate lifetime. |
1983 class BreakAndContinueInfo V8_FINAL BASE_EMBEDDED { | 1988 class BreakAndContinueInfo V8_FINAL BASE_EMBEDDED { |
1984 public: | 1989 public: |
1985 explicit BreakAndContinueInfo(BreakableStatement* target, | 1990 explicit BreakAndContinueInfo(BreakableStatement* target, |
| 1991 Scope* scope, |
1986 int drop_extra = 0) | 1992 int drop_extra = 0) |
1987 : target_(target), | 1993 : target_(target), |
1988 break_block_(NULL), | 1994 break_block_(NULL), |
1989 continue_block_(NULL), | 1995 continue_block_(NULL), |
| 1996 scope_(scope), |
1990 drop_extra_(drop_extra) { | 1997 drop_extra_(drop_extra) { |
1991 } | 1998 } |
1992 | 1999 |
1993 BreakableStatement* target() { return target_; } | 2000 BreakableStatement* target() { return target_; } |
1994 HBasicBlock* break_block() { return break_block_; } | 2001 HBasicBlock* break_block() { return break_block_; } |
1995 void set_break_block(HBasicBlock* block) { break_block_ = block; } | 2002 void set_break_block(HBasicBlock* block) { break_block_ = block; } |
1996 HBasicBlock* continue_block() { return continue_block_; } | 2003 HBasicBlock* continue_block() { return continue_block_; } |
1997 void set_continue_block(HBasicBlock* block) { continue_block_ = block; } | 2004 void set_continue_block(HBasicBlock* block) { continue_block_ = block; } |
| 2005 Scope* scope() { return scope_; } |
1998 int drop_extra() { return drop_extra_; } | 2006 int drop_extra() { return drop_extra_; } |
1999 | 2007 |
2000 private: | 2008 private: |
2001 BreakableStatement* target_; | 2009 BreakableStatement* target_; |
2002 HBasicBlock* break_block_; | 2010 HBasicBlock* break_block_; |
2003 HBasicBlock* continue_block_; | 2011 HBasicBlock* continue_block_; |
| 2012 Scope* scope_; |
2004 int drop_extra_; | 2013 int drop_extra_; |
2005 }; | 2014 }; |
2006 | 2015 |
2007 // A helper class to maintain a stack of current BreakAndContinueInfo | 2016 // A helper class to maintain a stack of current BreakAndContinueInfo |
2008 // structures mirroring BreakableStatement nesting. | 2017 // structures mirroring BreakableStatement nesting. |
2009 class BreakAndContinueScope V8_FINAL BASE_EMBEDDED { | 2018 class BreakAndContinueScope V8_FINAL BASE_EMBEDDED { |
2010 public: | 2019 public: |
2011 BreakAndContinueScope(BreakAndContinueInfo* info, | 2020 BreakAndContinueScope(BreakAndContinueInfo* info, |
2012 HOptimizedGraphBuilder* owner) | 2021 HOptimizedGraphBuilder* owner) |
2013 : info_(info), owner_(owner), next_(owner->break_scope()) { | 2022 : info_(info), owner_(owner), next_(owner->break_scope()) { |
2014 owner->set_break_scope(this); | 2023 owner->set_break_scope(this); |
2015 } | 2024 } |
2016 | 2025 |
2017 ~BreakAndContinueScope() { owner_->set_break_scope(next_); } | 2026 ~BreakAndContinueScope() { owner_->set_break_scope(next_); } |
2018 | 2027 |
2019 BreakAndContinueInfo* info() { return info_; } | 2028 BreakAndContinueInfo* info() { return info_; } |
2020 HOptimizedGraphBuilder* owner() { return owner_; } | 2029 HOptimizedGraphBuilder* owner() { return owner_; } |
2021 BreakAndContinueScope* next() { return next_; } | 2030 BreakAndContinueScope* next() { return next_; } |
2022 | 2031 |
2023 // Search the break stack for a break or continue target. | 2032 // Search the break stack for a break or continue target. |
2024 enum BreakType { BREAK, CONTINUE }; | 2033 enum BreakType { BREAK, CONTINUE }; |
2025 HBasicBlock* Get(BreakableStatement* stmt, BreakType type, int* drop_extra); | 2034 HBasicBlock* Get(BreakableStatement* stmt, BreakType type, |
| 2035 Scope** scope, int* drop_extra); |
2026 | 2036 |
2027 private: | 2037 private: |
2028 BreakAndContinueInfo* info_; | 2038 BreakAndContinueInfo* info_; |
2029 HOptimizedGraphBuilder* owner_; | 2039 HOptimizedGraphBuilder* owner_; |
2030 BreakAndContinueScope* next_; | 2040 BreakAndContinueScope* next_; |
2031 }; | 2041 }; |
2032 | 2042 |
2033 explicit HOptimizedGraphBuilder(CompilationInfo* info); | 2043 explicit HOptimizedGraphBuilder(CompilationInfo* info); |
2034 | 2044 |
2035 virtual bool BuildGraph() V8_OVERRIDE; | 2045 virtual bool BuildGraph() V8_OVERRIDE; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 void VisitVoid(UnaryOperation* expr); | 2135 void VisitVoid(UnaryOperation* expr); |
2126 void VisitTypeof(UnaryOperation* expr); | 2136 void VisitTypeof(UnaryOperation* expr); |
2127 void VisitNot(UnaryOperation* expr); | 2137 void VisitNot(UnaryOperation* expr); |
2128 | 2138 |
2129 void VisitComma(BinaryOperation* expr); | 2139 void VisitComma(BinaryOperation* expr); |
2130 void VisitLogicalExpression(BinaryOperation* expr); | 2140 void VisitLogicalExpression(BinaryOperation* expr); |
2131 void VisitArithmeticExpression(BinaryOperation* expr); | 2141 void VisitArithmeticExpression(BinaryOperation* expr); |
2132 | 2142 |
2133 bool PreProcessOsrEntry(IterationStatement* statement); | 2143 bool PreProcessOsrEntry(IterationStatement* statement); |
2134 void VisitLoopBody(IterationStatement* stmt, | 2144 void VisitLoopBody(IterationStatement* stmt, |
2135 HBasicBlock* loop_entry, | 2145 HBasicBlock* loop_entry); |
2136 BreakAndContinueInfo* break_info); | |
2137 | 2146 |
2138 // Create a back edge in the flow graph. body_exit is the predecessor | 2147 // Create a back edge in the flow graph. body_exit is the predecessor |
2139 // block and loop_entry is the successor block. loop_successor is the | 2148 // block and loop_entry is the successor block. loop_successor is the |
2140 // block where control flow exits the loop normally (e.g., via failure of | 2149 // block where control flow exits the loop normally (e.g., via failure of |
2141 // the condition) and break_block is the block where control flow breaks | 2150 // the condition) and break_block is the block where control flow breaks |
2142 // from the loop. All blocks except loop_entry can be NULL. The return | 2151 // from the loop. All blocks except loop_entry can be NULL. The return |
2143 // value is the new successor block which is the join of loop_successor | 2152 // value is the new successor block which is the join of loop_successor |
2144 // and break_block, or NULL. | 2153 // and break_block, or NULL. |
2145 HBasicBlock* CreateLoop(IterationStatement* statement, | 2154 HBasicBlock* CreateLoop(IterationStatement* statement, |
2146 HBasicBlock* loop_entry, | 2155 HBasicBlock* loop_entry, |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2810 } | 2819 } |
2811 | 2820 |
2812 private: | 2821 private: |
2813 HGraphBuilder* builder_; | 2822 HGraphBuilder* builder_; |
2814 }; | 2823 }; |
2815 | 2824 |
2816 | 2825 |
2817 } } // namespace v8::internal | 2826 } } // namespace v8::internal |
2818 | 2827 |
2819 #endif // V8_HYDROGEN_H_ | 2828 #endif // V8_HYDROGEN_H_ |
OLD | NEW |