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; |
(...skipping 11 matching lines...) Expand all Loading... |
81 ZoneVector<Handle<Object>> globals_; | 75 ZoneVector<Handle<Object>> globals_; |
82 | 76 |
83 // Stack of control scopes currently entered by the visitor. | 77 // Stack of control scopes currently entered by the visitor. |
84 ControlScope* execution_control_; | 78 ControlScope* execution_control_; |
85 | 79 |
86 // Stack of context objects pushed onto the chain by the visitor. | 80 // Stack of context objects pushed onto the chain by the visitor. |
87 ContextScope* execution_context_; | 81 ContextScope* execution_context_; |
88 | 82 |
89 // Nodes representing values in the activation record. | 83 // Nodes representing values in the activation record. |
90 SetOncePointer<Node> function_closure_; | 84 SetOncePointer<Node> function_closure_; |
91 Node* function_context_; | 85 SetOncePointer<Node> function_context_; |
92 | 86 |
93 // Temporary storage for building node input lists. | 87 // Temporary storage for building node input lists. |
94 int input_buffer_size_; | 88 int input_buffer_size_; |
95 Node** input_buffer_; | 89 Node** input_buffer_; |
96 | 90 |
97 // Merge of all control nodes that exit the function body. | 91 // Merge of all control nodes that exit the function body. |
98 Node* exit_control_; | 92 Node* exit_control_; |
99 | 93 |
100 // Result of loop assignment analysis performed before graph creation. | 94 // Result of loop assignment analysis performed before graph creation. |
101 LoopAssignmentAnalysis* loop_assignment_analysis_; | 95 LoopAssignmentAnalysis* loop_assignment_analysis_; |
(...skipping 18 matching lines...) Expand all Loading... |
120 Scope* current_scope() const; | 114 Scope* current_scope() const; |
121 Node* current_context() const; | 115 Node* current_context() const; |
122 Node* exit_control() const { return exit_control_; } | 116 Node* exit_control() const { return exit_control_; } |
123 | 117 |
124 void set_environment(Environment* env) { environment_ = env; } | 118 void set_environment(Environment* env) { environment_ = env; } |
125 void set_ast_context(AstContext* ctx) { ast_context_ = ctx; } | 119 void set_ast_context(AstContext* ctx) { ast_context_ = ctx; } |
126 void set_execution_control(ControlScope* ctrl) { execution_control_ = ctrl; } | 120 void set_execution_control(ControlScope* ctrl) { execution_control_ = ctrl; } |
127 void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; } | 121 void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; } |
128 void set_exit_control(Node* exit) { exit_control_ = exit; } | 122 void set_exit_control(Node* exit) { exit_control_ = exit; } |
129 | 123 |
| 124 // Create the main graph body by visiting the AST. |
130 void CreateGraphBody(); | 125 void CreateGraphBody(); |
131 | 126 |
| 127 // Create the node that represents the outer context of the function. |
| 128 void CreateFunctionContext(bool constant_context); |
| 129 |
| 130 // Get or create the node that represents the outer function closure. |
| 131 Node* GetFunctionClosure(); |
| 132 |
132 // Node creation helpers. | 133 // Node creation helpers. |
133 Node* NewNode(const Operator* op, bool incomplete = false) { | 134 Node* NewNode(const Operator* op, bool incomplete = false) { |
134 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); | 135 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); |
135 } | 136 } |
136 | 137 |
137 Node* NewNode(const Operator* op, Node* n1) { | 138 Node* NewNode(const Operator* op, Node* n1) { |
138 return MakeNode(op, 1, &n1, false); | 139 return MakeNode(op, 1, &n1, false); |
139 } | 140 } |
140 | 141 |
141 Node* NewNode(const Operator* op, Node* n1, Node* n2) { | 142 Node* NewNode(const Operator* op, Node* n1, Node* n2) { |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 467 |
467 // Prepare environment to be used as loop header. | 468 // Prepare environment to be used as loop header. |
468 void PrepareForLoop(BitVector* assigned, bool is_osr = false); | 469 void PrepareForLoop(BitVector* assigned, bool is_osr = false); |
469 }; | 470 }; |
470 | 471 |
471 } // namespace compiler | 472 } // namespace compiler |
472 } // namespace internal | 473 } // namespace internal |
473 } // namespace v8 | 474 } // namespace v8 |
474 | 475 |
475 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ | 476 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ |
OLD | NEW |