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(); | |
Michael Starzinger
2015/02/17 10:34:37
nit: Please move this down to below all the fields
| |
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 // Node representing the control dependency for dead code. | 99 // Node representing the control dependency for dead code. |
98 SetOncePointer<Node> dead_control_; | 100 SetOncePointer<Node> dead_control_; |
99 | 101 |
100 // Merge of all control nodes that exit the function body. | 102 // Merge of all control nodes that exit the function body. |
101 Node* exit_control_; | 103 Node* exit_control_; |
102 | 104 |
103 // Result of loop assignment analysis performed before graph creation. | 105 // Result of loop assignment analysis performed before graph creation. |
104 LoopAssignmentAnalysis* loop_assignment_analysis_; | 106 LoopAssignmentAnalysis* loop_assignment_analysis_; |
105 | 107 |
106 // Growth increment for the temporary buffer used to construct input lists to | 108 // Growth increment for the temporary buffer used to construct input lists to |
107 // new nodes. | 109 // new nodes. |
108 static const int kInputBufferSizeIncrement = 64; | 110 static const int kInputBufferSizeIncrement = 64; |
109 | 111 |
110 Zone* local_zone() const { return local_zone_; } | 112 Zone* local_zone() const { return local_zone_; } |
111 Environment* environment() { return environment_; } | 113 Environment* environment() const { return environment_; } |
112 AstContext* ast_context() const { return ast_context_; } | 114 AstContext* ast_context() const { return ast_context_; } |
113 ControlScope* execution_control() const { return execution_control_; } | 115 ControlScope* execution_control() const { return execution_control_; } |
114 ContextScope* execution_context() const { return execution_context_; } | 116 ContextScope* execution_context() const { return execution_context_; } |
115 CommonOperatorBuilder* common() const { return jsgraph_->common(); } | 117 CommonOperatorBuilder* common() const { return jsgraph_->common(); } |
116 CompilationInfo* info() const { return info_; } | 118 CompilationInfo* info() const { return info_; } |
117 LanguageMode language_mode() const; | 119 LanguageMode language_mode() const; |
118 JSGraph* jsgraph() { return jsgraph_; } | 120 JSGraph* jsgraph() { return jsgraph_; } |
119 Graph* graph() { return jsgraph_->graph(); } | 121 Graph* graph() { return jsgraph_->graph(); } |
120 Zone* graph_zone() { return graph()->zone(); } | 122 Zone* graph_zone() { return graph()->zone(); } |
121 JSOperatorBuilder* javascript() { return jsgraph_->javascript(); } | 123 JSOperatorBuilder* javascript() { return jsgraph_->javascript(); } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 | 171 |
170 Node* NewNode(const Operator* op, int value_input_count, Node** value_inputs, | 172 Node* NewNode(const Operator* op, int value_input_count, Node** value_inputs, |
171 bool incomplete = false) { | 173 bool incomplete = false) { |
172 return MakeNode(op, value_input_count, value_inputs, incomplete); | 174 return MakeNode(op, value_input_count, value_inputs, incomplete); |
173 } | 175 } |
174 | 176 |
175 // Creates a new Phi node having {count} input values. | 177 // Creates a new Phi node having {count} input values. |
176 Node* NewPhi(int count, Node* input, Node* control); | 178 Node* NewPhi(int count, Node* input, Node* control); |
177 Node* NewEffectPhi(int count, Node* input, Node* control); | 179 Node* NewEffectPhi(int count, Node* input, Node* control); |
178 | 180 |
181 Node* NewOuterContextParam(); | |
182 Node* NewCurrentContextOsrValue(); | |
183 | |
179 // Helpers for merging control, effect or value dependencies. | 184 // Helpers for merging control, effect or value dependencies. |
180 Node* MergeControl(Node* control, Node* other); | 185 Node* MergeControl(Node* control, Node* other); |
181 Node* MergeEffect(Node* value, Node* other, Node* control); | 186 Node* MergeEffect(Node* value, Node* other, Node* control); |
182 Node* MergeValue(Node* value, Node* other, Node* control); | 187 Node* MergeValue(Node* value, Node* other, Node* control); |
183 | 188 |
184 // The main node creation chokepoint. Adds context, frame state, effect, | 189 // The main node creation chokepoint. Adds context, frame state, effect, |
185 // and control dependencies depending on the operator. | 190 // and control dependencies depending on the operator. |
186 Node* MakeNode(const Operator* op, int value_input_count, Node** value_inputs, | 191 Node* MakeNode(const Operator* op, int value_input_count, Node** value_inputs, |
187 bool incomplete); | 192 bool incomplete); |
188 | 193 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 Node* Lookup(Variable* variable) { | 360 Node* Lookup(Variable* variable) { |
356 DCHECK(variable->IsStackAllocated()); | 361 DCHECK(variable->IsStackAllocated()); |
357 if (variable->IsParameter()) { | 362 if (variable->IsParameter()) { |
358 return values()->at(variable->index() + 1); | 363 return values()->at(variable->index() + 1); |
359 } else { | 364 } else { |
360 DCHECK(variable->IsStackLocal()); | 365 DCHECK(variable->IsStackLocal()); |
361 return values()->at(variable->index() + parameters_count_); | 366 return values()->at(variable->index() + parameters_count_); |
362 } | 367 } |
363 } | 368 } |
364 | 369 |
370 Node* Context() const { return contexts_[contexts_.size() - 1]; } | |
Michael Starzinger
2015/02/17 10:34:37
Can use contexts()->back() here instead.
titzer
2015/02/17 10:44:17
Done.
| |
371 void PushContext(Node* context) { contexts()->push_back(context); } | |
372 void PopContext() { contexts()->pop_back(); } | |
373 | |
365 // Operations on the operand stack. | 374 // Operations on the operand stack. |
366 void Push(Node* node) { | 375 void Push(Node* node) { |
367 values()->push_back(node); | 376 values()->push_back(node); |
368 } | 377 } |
369 Node* Top() { | 378 Node* Top() { |
370 DCHECK(stack_height() > 0); | 379 DCHECK(stack_height() > 0); |
371 return values()->back(); | 380 return values()->back(); |
372 } | 381 } |
373 Node* Pop() { | 382 Node* Pop() { |
374 DCHECK(stack_height() > 0); | 383 DCHECK(stack_height() > 0); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 env->MarkAsUnreachable(); | 438 env->MarkAsUnreachable(); |
430 return env; | 439 return env; |
431 } | 440 } |
432 | 441 |
433 // Copies this environment at a loop header control-flow point. | 442 // Copies this environment at a loop header control-flow point. |
434 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) { | 443 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) { |
435 PrepareForLoop(assigned, is_osr); | 444 PrepareForLoop(assigned, is_osr); |
436 return Copy(); | 445 return Copy(); |
437 } | 446 } |
438 | 447 |
448 int ContextStackDepth() { return static_cast<int>(contexts_.size()); } | |
449 | |
439 private: | 450 private: |
440 AstGraphBuilder* builder_; | 451 AstGraphBuilder* builder_; |
441 int parameters_count_; | 452 int parameters_count_; |
442 int locals_count_; | 453 int locals_count_; |
443 NodeVector values_; | 454 NodeVector values_; |
455 NodeVector contexts_; | |
444 Node* control_dependency_; | 456 Node* control_dependency_; |
445 Node* effect_dependency_; | 457 Node* effect_dependency_; |
446 Node* parameters_node_; | 458 Node* parameters_node_; |
447 Node* locals_node_; | 459 Node* locals_node_; |
448 Node* stack_node_; | 460 Node* stack_node_; |
449 | 461 |
450 explicit Environment(const Environment* copy); | 462 explicit Environment(const Environment* copy); |
451 Environment* Copy() { return new (zone()) Environment(this); } | 463 Environment* Copy() { return new (zone()) Environment(this); } |
452 void UpdateStateValues(Node** state_values, int offset, int count); | 464 void UpdateStateValues(Node** state_values, int offset, int count); |
453 Zone* zone() const { return builder_->local_zone(); } | 465 Zone* zone() const { return builder_->local_zone(); } |
454 Graph* graph() const { return builder_->graph(); } | 466 Graph* graph() const { return builder_->graph(); } |
455 AstGraphBuilder* builder() const { return builder_; } | 467 AstGraphBuilder* builder() const { return builder_; } |
456 CommonOperatorBuilder* common() { return builder_->common(); } | 468 CommonOperatorBuilder* common() { return builder_->common(); } |
457 NodeVector* values() { return &values_; } | 469 NodeVector* values() { return &values_; } |
470 NodeVector* contexts() { return &contexts_; } | |
458 | 471 |
459 // Prepare environment to be used as loop header. | 472 // Prepare environment to be used as loop header. |
460 void PrepareForLoop(BitVector* assigned, bool is_osr = false); | 473 void PrepareForLoop(BitVector* assigned, bool is_osr = false); |
461 }; | 474 }; |
462 | 475 |
463 } // namespace compiler | 476 } // namespace compiler |
464 } // namespace internal | 477 } // namespace internal |
465 } // namespace v8 | 478 } // namespace v8 |
466 | 479 |
467 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ | 480 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ |
OLD | NEW |