OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_COMPILER_AST_GRAPH_BUILDER_H_ | 5 #ifndef V8_COMPILER_AST_GRAPH_BUILDER_H_ |
6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ | 6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ |
7 | 7 |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 // The AstGraphBuilder produces a high-level IR graph, based on an | 24 // The AstGraphBuilder produces a high-level IR graph, based on an |
25 // underlying AST. The produced graph can either be compiled into a | 25 // underlying AST. The produced graph can either be compiled into a |
26 // stand-alone function or be wired into another graph for the purposes | 26 // stand-alone function or be wired into another graph for the purposes |
27 // of function inlining. | 27 // of function inlining. |
28 class AstGraphBuilder : public AstVisitor { | 28 class AstGraphBuilder : public AstVisitor { |
29 public: | 29 public: |
30 AstGraphBuilder(Zone* local_zone, CompilationInfo* info, JSGraph* jsgraph, | 30 AstGraphBuilder(Zone* local_zone, CompilationInfo* info, JSGraph* jsgraph, |
31 LoopAssignmentAnalysis* loop_assignment = NULL); | 31 LoopAssignmentAnalysis* loop_assignment = NULL); |
32 | 32 |
33 // Creates a graph by visiting the entire AST. | 33 // Creates a graph by visiting the entire AST. |
34 bool CreateGraph(); | 34 bool CreateGraph(bool constant_context); |
35 | 35 |
36 // Helpers to create new control nodes. | 36 // Helpers to create new control nodes. |
37 Node* NewIfTrue() { return NewNode(common()->IfTrue()); } | 37 Node* NewIfTrue() { return NewNode(common()->IfTrue()); } |
38 Node* NewIfFalse() { return NewNode(common()->IfFalse()); } | 38 Node* NewIfFalse() { return NewNode(common()->IfFalse()); } |
39 Node* NewMerge() { return NewNode(common()->Merge(1), true); } | 39 Node* NewMerge() { return NewNode(common()->Merge(1), true); } |
40 Node* NewLoop() { return NewNode(common()->Loop(1), true); } | 40 Node* NewLoop() { return NewNode(common()->Loop(1), true); } |
41 Node* NewBranch(Node* condition, BranchHint hint = BranchHint::kNone) { | 41 Node* NewBranch(Node* condition, BranchHint hint = BranchHint::kNone) { |
42 return NewNode(common()->Branch(hint), condition); | 42 return NewNode(common()->Branch(hint), condition); |
43 } | 43 } |
44 | 44 |
45 protected: | 45 protected: |
46 #define DECLARE_VISIT(type) void Visit##type(type* node) OVERRIDE; | 46 #define DECLARE_VISIT(type) void Visit##type(type* node) OVERRIDE; |
47 // Visiting functions for AST nodes make this an AstVisitor. | 47 // Visiting functions for AST nodes make this an AstVisitor. |
48 AST_NODE_LIST(DECLARE_VISIT) | 48 AST_NODE_LIST(DECLARE_VISIT) |
49 #undef DECLARE_VISIT | 49 #undef DECLARE_VISIT |
50 | 50 |
51 // Visiting function for declarations list is overridden. | 51 // Visiting function for declarations list is overridden. |
52 void VisitDeclarations(ZoneList<Declaration*>* declarations) OVERRIDE; | 52 void VisitDeclarations(ZoneList<Declaration*>* declarations) OVERRIDE; |
53 | 53 |
54 // Get the node that represents the outer function context. | |
55 Node* GetFunctionContext(); | |
56 | |
57 // Get the node that represents the outer function closure. | |
58 Node* GetFunctionClosure(); | |
59 | |
60 private: | 54 private: |
61 class AstContext; | 55 class AstContext; |
62 class AstEffectContext; | 56 class AstEffectContext; |
63 class AstValueContext; | 57 class AstValueContext; |
64 class AstTestContext; | 58 class AstTestContext; |
65 class ContextScope; | 59 class ContextScope; |
66 class ControlScope; | 60 class ControlScope; |
67 class ControlScopeForBreakable; | 61 class ControlScopeForBreakable; |
68 class ControlScopeForIteration; | 62 class ControlScopeForIteration; |
69 class ControlScopeForCatch; | 63 class ControlScopeForCatch; |
70 class ControlScopeForFinally; | 64 class ControlScopeForFinally; |
71 class Environment; | 65 class Environment; |
72 friend class ControlBuilder; | 66 friend class ControlBuilder; |
73 | 67 |
74 Zone* local_zone_; | 68 Zone* local_zone_; |
75 CompilationInfo* info_; | 69 CompilationInfo* info_; |
76 JSGraph* jsgraph_; | 70 JSGraph* jsgraph_; |
77 Environment* environment_; | 71 Environment* environment_; |
78 AstContext* ast_context_; | 72 AstContext* ast_context_; |
79 | 73 |
80 bool CreateGraphBody(); | |
81 | |
82 // List of global declarations for functions and variables. | 74 // List of global declarations for functions and variables. |
83 ZoneVector<Handle<Object>> globals_; | 75 ZoneVector<Handle<Object>> globals_; |
84 | 76 |
85 // Stack of control scopes currently entered by the visitor. | 77 // Stack of control scopes currently entered by the visitor. |
86 ControlScope* execution_control_; | 78 ControlScope* execution_control_; |
87 | 79 |
88 // Stack of context objects pushed onto the chain by the visitor. | 80 // Stack of context objects pushed onto the chain by the visitor. |
89 ContextScope* execution_context_; | 81 ContextScope* execution_context_; |
90 | 82 |
91 // Nodes representing values in the activation record. | 83 // Nodes representing values in the activation record. |
92 SetOncePointer<Node> function_closure_; | 84 SetOncePointer<Node> function_closure_; |
93 Node* function_context_; | 85 SetOncePointer<Node> function_context_; |
94 | 86 |
95 // Temporary storage for building node input lists. | 87 // Temporary storage for building node input lists. |
96 int input_buffer_size_; | 88 int input_buffer_size_; |
97 Node** input_buffer_; | 89 Node** input_buffer_; |
98 | 90 |
99 // Merge of all control nodes that exit the function body. | 91 // Merge of all control nodes that exit the function body. |
100 Node* exit_control_; | 92 Node* exit_control_; |
101 | 93 |
102 // Result of loop assignment analysis performed before graph creation. | 94 // Result of loop assignment analysis performed before graph creation. |
103 LoopAssignmentAnalysis* loop_assignment_analysis_; | 95 LoopAssignmentAnalysis* loop_assignment_analysis_; |
(...skipping 18 matching lines...) Expand all Loading... |
122 Scope* current_scope() const; | 114 Scope* current_scope() const; |
123 Node* current_context() const; | 115 Node* current_context() const; |
124 Node* exit_control() const { return exit_control_; } | 116 Node* exit_control() const { return exit_control_; } |
125 | 117 |
126 void set_environment(Environment* env) { environment_ = env; } | 118 void set_environment(Environment* env) { environment_ = env; } |
127 void set_ast_context(AstContext* ctx) { ast_context_ = ctx; } | 119 void set_ast_context(AstContext* ctx) { ast_context_ = ctx; } |
128 void set_execution_control(ControlScope* ctrl) { execution_control_ = ctrl; } | 120 void set_execution_control(ControlScope* ctrl) { execution_control_ = ctrl; } |
129 void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; } | 121 void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; } |
130 void set_exit_control(Node* exit) { exit_control_ = exit; } | 122 void set_exit_control(Node* exit) { exit_control_ = exit; } |
131 | 123 |
| 124 bool CreateGraphBody(); |
| 125 |
| 126 // Get the node that represents the outer function context. |
| 127 Node* GetFunctionContext(); |
| 128 |
| 129 // Get the node that represents the outer function closure. |
| 130 Node* GetFunctionClosure(); |
| 131 |
132 // Node creation helpers. | 132 // Node creation helpers. |
133 Node* NewNode(const Operator* op, bool incomplete = false) { | 133 Node* NewNode(const Operator* op, bool incomplete = false) { |
134 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); | 134 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); |
135 } | 135 } |
136 | 136 |
137 Node* NewNode(const Operator* op, Node* n1) { | 137 Node* NewNode(const Operator* op, Node* n1) { |
138 return MakeNode(op, 1, &n1, false); | 138 return MakeNode(op, 1, &n1, false); |
139 } | 139 } |
140 | 140 |
141 Node* NewNode(const Operator* op, Node* n1, Node* n2) { | 141 Node* NewNode(const Operator* op, Node* n1, Node* n2) { |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 466 |
467 // Prepare environment to be used as loop header. | 467 // Prepare environment to be used as loop header. |
468 void PrepareForLoop(BitVector* assigned, bool is_osr = false); | 468 void PrepareForLoop(BitVector* assigned, bool is_osr = false); |
469 }; | 469 }; |
470 | 470 |
471 } // namespace compiler | 471 } // namespace compiler |
472 } // namespace internal | 472 } // namespace internal |
473 } // namespace v8 | 473 } // namespace v8 |
474 | 474 |
475 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ | 475 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ |
OLD | NEW |