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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 class ControlScopeForFinally; | 70 class ControlScopeForFinally; |
71 class Environment; | 71 class Environment; |
72 friend class ControlBuilder; | 72 friend class ControlBuilder; |
73 | 73 |
74 Zone* local_zone_; | 74 Zone* local_zone_; |
75 CompilationInfo* info_; | 75 CompilationInfo* info_; |
76 JSGraph* jsgraph_; | 76 JSGraph* jsgraph_; |
77 Environment* environment_; | 77 Environment* environment_; |
78 AstContext* ast_context_; | 78 AstContext* ast_context_; |
79 | 79 |
| 80 bool CreateGraphBody(); |
| 81 |
80 // List of global declarations for functions and variables. | 82 // List of global declarations for functions and variables. |
81 ZoneVector<Handle<Object>> globals_; | 83 ZoneVector<Handle<Object>> globals_; |
82 | 84 |
83 // Stack of control scopes currently entered by the visitor. | 85 // Stack of control scopes currently entered by the visitor. |
84 ControlScope* execution_control_; | 86 ControlScope* execution_control_; |
85 | 87 |
86 // Stack of context objects pushed onto the chain by the visitor. | 88 // Stack of context objects pushed onto the chain by the visitor. |
87 ContextScope* execution_context_; | 89 ContextScope* execution_context_; |
88 | 90 |
89 // Nodes representing values in the activation record. | 91 // Nodes representing values in the activation record. |
90 SetOncePointer<Node> function_closure_; | 92 SetOncePointer<Node> function_closure_; |
91 SetOncePointer<Node> function_context_; | 93 Node* function_context_; |
92 | 94 |
93 // Temporary storage for building node input lists. | 95 // Temporary storage for building node input lists. |
94 int input_buffer_size_; | 96 int input_buffer_size_; |
95 Node** input_buffer_; | 97 Node** input_buffer_; |
96 | 98 |
97 // Merge of all control nodes that exit the function body. | 99 // Merge of all control nodes that exit the function body. |
98 Node* exit_control_; | 100 Node* exit_control_; |
99 | 101 |
100 // Result of loop assignment analysis performed before graph creation. | 102 // Result of loop assignment analysis performed before graph creation. |
101 LoopAssignmentAnalysis* loop_assignment_analysis_; | 103 LoopAssignmentAnalysis* loop_assignment_analysis_; |
102 | 104 |
103 // Growth increment for the temporary buffer used to construct input lists to | 105 // Growth increment for the temporary buffer used to construct input lists to |
104 // new nodes. | 106 // new nodes. |
105 static const int kInputBufferSizeIncrement = 64; | 107 static const int kInputBufferSizeIncrement = 64; |
106 | 108 |
107 Zone* local_zone() const { return local_zone_; } | 109 Zone* local_zone() const { return local_zone_; } |
108 Environment* environment() { return environment_; } | 110 Environment* environment() const { return environment_; } |
109 AstContext* ast_context() const { return ast_context_; } | 111 AstContext* ast_context() const { return ast_context_; } |
110 ControlScope* execution_control() const { return execution_control_; } | 112 ControlScope* execution_control() const { return execution_control_; } |
111 ContextScope* execution_context() const { return execution_context_; } | 113 ContextScope* execution_context() const { return execution_context_; } |
112 CommonOperatorBuilder* common() const { return jsgraph_->common(); } | 114 CommonOperatorBuilder* common() const { return jsgraph_->common(); } |
113 CompilationInfo* info() const { return info_; } | 115 CompilationInfo* info() const { return info_; } |
114 LanguageMode language_mode() const; | 116 LanguageMode language_mode() const; |
115 JSGraph* jsgraph() { return jsgraph_; } | 117 JSGraph* jsgraph() { return jsgraph_; } |
116 Graph* graph() { return jsgraph_->graph(); } | 118 Graph* graph() { return jsgraph_->graph(); } |
117 Zone* graph_zone() { return graph()->zone(); } | 119 Zone* graph_zone() { return graph()->zone(); } |
118 JSOperatorBuilder* javascript() { return jsgraph_->javascript(); } | 120 JSOperatorBuilder* javascript() { return jsgraph_->javascript(); } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 167 |
166 Node* NewNode(const Operator* op, int value_input_count, Node** value_inputs, | 168 Node* NewNode(const Operator* op, int value_input_count, Node** value_inputs, |
167 bool incomplete = false) { | 169 bool incomplete = false) { |
168 return MakeNode(op, value_input_count, value_inputs, incomplete); | 170 return MakeNode(op, value_input_count, value_inputs, incomplete); |
169 } | 171 } |
170 | 172 |
171 // Creates a new Phi node having {count} input values. | 173 // Creates a new Phi node having {count} input values. |
172 Node* NewPhi(int count, Node* input, Node* control); | 174 Node* NewPhi(int count, Node* input, Node* control); |
173 Node* NewEffectPhi(int count, Node* input, Node* control); | 175 Node* NewEffectPhi(int count, Node* input, Node* control); |
174 | 176 |
| 177 Node* NewOuterContextParam(); |
| 178 Node* NewCurrentContextOsrValue(); |
| 179 |
175 // Helpers for merging control, effect or value dependencies. | 180 // Helpers for merging control, effect or value dependencies. |
176 Node* MergeControl(Node* control, Node* other); | 181 Node* MergeControl(Node* control, Node* other); |
177 Node* MergeEffect(Node* value, Node* other, Node* control); | 182 Node* MergeEffect(Node* value, Node* other, Node* control); |
178 Node* MergeValue(Node* value, Node* other, Node* control); | 183 Node* MergeValue(Node* value, Node* other, Node* control); |
179 | 184 |
180 // The main node creation chokepoint. Adds context, frame state, effect, | 185 // The main node creation chokepoint. Adds context, frame state, effect, |
181 // and control dependencies depending on the operator. | 186 // and control dependencies depending on the operator. |
182 Node* MakeNode(const Operator* op, int value_input_count, Node** value_inputs, | 187 Node* MakeNode(const Operator* op, int value_input_count, Node** value_inputs, |
183 bool incomplete); | 188 bool incomplete); |
184 | 189 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 Node* Lookup(Variable* variable) { | 355 Node* Lookup(Variable* variable) { |
351 DCHECK(variable->IsStackAllocated()); | 356 DCHECK(variable->IsStackAllocated()); |
352 if (variable->IsParameter()) { | 357 if (variable->IsParameter()) { |
353 return values()->at(variable->index() + 1); | 358 return values()->at(variable->index() + 1); |
354 } else { | 359 } else { |
355 DCHECK(variable->IsStackLocal()); | 360 DCHECK(variable->IsStackLocal()); |
356 return values()->at(variable->index() + parameters_count_); | 361 return values()->at(variable->index() + parameters_count_); |
357 } | 362 } |
358 } | 363 } |
359 | 364 |
| 365 Node* Context() const { return contexts_.back(); } |
| 366 void PushContext(Node* context) { contexts()->push_back(context); } |
| 367 void PopContext() { contexts()->pop_back(); } |
| 368 |
360 // Operations on the operand stack. | 369 // Operations on the operand stack. |
361 void Push(Node* node) { | 370 void Push(Node* node) { |
362 values()->push_back(node); | 371 values()->push_back(node); |
363 } | 372 } |
364 Node* Top() { | 373 Node* Top() { |
365 DCHECK(stack_height() > 0); | 374 DCHECK(stack_height() > 0); |
366 return values()->back(); | 375 return values()->back(); |
367 } | 376 } |
368 Node* Pop() { | 377 Node* Pop() { |
369 DCHECK(stack_height() > 0); | 378 DCHECK(stack_height() > 0); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 env->MarkAsUnreachable(); | 433 env->MarkAsUnreachable(); |
425 return env; | 434 return env; |
426 } | 435 } |
427 | 436 |
428 // Copies this environment at a loop header control-flow point. | 437 // Copies this environment at a loop header control-flow point. |
429 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) { | 438 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) { |
430 PrepareForLoop(assigned, is_osr); | 439 PrepareForLoop(assigned, is_osr); |
431 return Copy(); | 440 return Copy(); |
432 } | 441 } |
433 | 442 |
| 443 int ContextStackDepth() { return static_cast<int>(contexts_.size()); } |
| 444 |
434 private: | 445 private: |
435 AstGraphBuilder* builder_; | 446 AstGraphBuilder* builder_; |
436 int parameters_count_; | 447 int parameters_count_; |
437 int locals_count_; | 448 int locals_count_; |
438 NodeVector values_; | 449 NodeVector values_; |
| 450 NodeVector contexts_; |
439 Node* control_dependency_; | 451 Node* control_dependency_; |
440 Node* effect_dependency_; | 452 Node* effect_dependency_; |
441 Node* parameters_node_; | 453 Node* parameters_node_; |
442 Node* locals_node_; | 454 Node* locals_node_; |
443 Node* stack_node_; | 455 Node* stack_node_; |
444 | 456 |
445 explicit Environment(const Environment* copy); | 457 explicit Environment(const Environment* copy); |
446 Environment* Copy() { return new (zone()) Environment(this); } | 458 Environment* Copy() { return new (zone()) Environment(this); } |
447 void UpdateStateValues(Node** state_values, int offset, int count); | 459 void UpdateStateValues(Node** state_values, int offset, int count); |
448 Zone* zone() const { return builder_->local_zone(); } | 460 Zone* zone() const { return builder_->local_zone(); } |
449 Graph* graph() const { return builder_->graph(); } | 461 Graph* graph() const { return builder_->graph(); } |
450 AstGraphBuilder* builder() const { return builder_; } | 462 AstGraphBuilder* builder() const { return builder_; } |
451 CommonOperatorBuilder* common() { return builder_->common(); } | 463 CommonOperatorBuilder* common() { return builder_->common(); } |
452 NodeVector* values() { return &values_; } | 464 NodeVector* values() { return &values_; } |
| 465 NodeVector* contexts() { return &contexts_; } |
453 | 466 |
454 // Prepare environment to be used as loop header. | 467 // Prepare environment to be used as loop header. |
455 void PrepareForLoop(BitVector* assigned, bool is_osr = false); | 468 void PrepareForLoop(BitVector* assigned, bool is_osr = false); |
456 }; | 469 }; |
457 | 470 |
458 } // namespace compiler | 471 } // namespace compiler |
459 } // namespace internal | 472 } // namespace internal |
460 } // namespace v8 | 473 } // namespace v8 |
461 | 474 |
462 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ | 475 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ |
OLD | NEW |