Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/compiler/ast-graph-builder.h

Issue 949743002: [turbofan] Variable liveness analysis for deopt (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address review comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/compiler/liveness-analyzer.h"
10 #include "src/compiler/state-values-utils.h" 11 #include "src/compiler/state-values-utils.h"
11 12
12 namespace v8 { 13 namespace v8 {
13 namespace internal { 14 namespace internal {
14 15
15 class BitVector; 16 class BitVector;
16 17
17 namespace compiler { 18 namespace compiler {
18 19
19 class ControlBuilder; 20 class ControlBuilder;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 // Merge of all control nodes that exit the function body. 96 // Merge of all control nodes that exit the function body.
96 Node* exit_control_; 97 Node* exit_control_;
97 98
98 // Result of loop assignment analysis performed before graph creation. 99 // Result of loop assignment analysis performed before graph creation.
99 LoopAssignmentAnalysis* loop_assignment_analysis_; 100 LoopAssignmentAnalysis* loop_assignment_analysis_;
100 101
101 // Cache for StateValues nodes for frame states. 102 // Cache for StateValues nodes for frame states.
102 StateValuesCache state_values_cache_; 103 StateValuesCache state_values_cache_;
103 104
105 // Analyzer of local variable liveness.
106 LivenessAnalyzer liveness_analyzer_;
107
104 // 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
105 // new nodes. 109 // new nodes.
106 static const int kInputBufferSizeIncrement = 64; 110 static const int kInputBufferSizeIncrement = 64;
107 111
108 Zone* local_zone() const { return local_zone_; } 112 Zone* local_zone() const { return local_zone_; }
109 Environment* environment() const { return environment_; } 113 Environment* environment() const { return environment_; }
110 AstContext* ast_context() const { return ast_context_; } 114 AstContext* ast_context() const { return ast_context_; }
111 ControlScope* execution_control() const { return execution_control_; } 115 ControlScope* execution_control() const { return execution_control_; }
112 ContextScope* execution_context() const { return execution_context_; } 116 ContextScope* execution_context() const { return execution_context_; }
113 CommonOperatorBuilder* common() const { return jsgraph_->common(); } 117 CommonOperatorBuilder* common() const { return jsgraph_->common(); }
114 CompilationInfo* info() const { return info_; } 118 CompilationInfo* info() const { return info_; }
115 LanguageMode language_mode() const; 119 LanguageMode language_mode() const;
116 JSGraph* jsgraph() { return jsgraph_; } 120 JSGraph* jsgraph() { return jsgraph_; }
117 Graph* graph() { return jsgraph_->graph(); } 121 Graph* graph() { return jsgraph_->graph(); }
118 Zone* graph_zone() { return graph()->zone(); } 122 Zone* graph_zone() { return graph()->zone(); }
119 JSOperatorBuilder* javascript() { return jsgraph_->javascript(); } 123 JSOperatorBuilder* javascript() { return jsgraph_->javascript(); }
120 ZoneVector<Handle<Object>>* globals() { return &globals_; } 124 ZoneVector<Handle<Object>>* globals() { return &globals_; }
121 Scope* current_scope() const; 125 Scope* current_scope() const;
122 Node* current_context() const; 126 Node* current_context() const;
123 Node* exit_control() const { return exit_control_; } 127 Node* exit_control() const { return exit_control_; }
128 LivenessAnalyzer* liveness_analyzer() { return &liveness_analyzer_; }
124 129
125 void set_environment(Environment* env) { environment_ = env; } 130 void set_environment(Environment* env) { environment_ = env; }
126 void set_ast_context(AstContext* ctx) { ast_context_ = ctx; } 131 void set_ast_context(AstContext* ctx) { ast_context_ = ctx; }
127 void set_execution_control(ControlScope* ctrl) { execution_control_ = ctrl; } 132 void set_execution_control(ControlScope* ctrl) { execution_control_ = ctrl; }
128 void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; } 133 void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; }
129 void set_exit_control(Node* exit) { exit_control_ = exit; } 134 void set_exit_control(Node* exit) { exit_control_ = exit; }
130 135
131 // Create the main graph body by visiting the AST. 136 // Create the main graph body by visiting the AST.
132 void CreateGraphBody(bool stack_check); 137 void CreateGraphBody(bool stack_check);
133 138
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 void PrepareFrameStateAfterAndBefore(Node* node, BailoutId ast_id, 210 void PrepareFrameStateAfterAndBefore(Node* node, BailoutId ast_id,
206 OutputFrameStateCombine combine, 211 OutputFrameStateCombine combine,
207 Node* frame_state_before); 212 Node* frame_state_before);
208 213
209 BitVector* GetVariablesAssignedInLoop(IterationStatement* stmt); 214 BitVector* GetVariablesAssignedInLoop(IterationStatement* stmt);
210 215
211 // Check if the given statement is an OSR entry. 216 // Check if the given statement is an OSR entry.
212 // If so, record the stack height into the compilation and return {true}. 217 // If so, record the stack height into the compilation and return {true}.
213 bool CheckOsrEntry(IterationStatement* stmt); 218 bool CheckOsrEntry(IterationStatement* stmt);
214 219
220 // Computes local variable liveness and replaces dead variables in
221 // frame states with the undefined values.
222 void ClearNonLiveSlotsInFrameStates();
223
215 // Helper to wrap a Handle<T> into a Unique<T>. 224 // Helper to wrap a Handle<T> into a Unique<T>.
216 template <class T> 225 template <class T>
217 Unique<T> MakeUnique(Handle<T> object) { 226 Unique<T> MakeUnique(Handle<T> object) {
218 return Unique<T>::CreateUninitialized(object); 227 return Unique<T>::CreateUninitialized(object);
219 } 228 }
220 229
221 Node** EnsureInputBufferSize(int size); 230 Node** EnsureInputBufferSize(int size);
222 231
223 // Named and keyed loads require a VectorSlotPair for successful lowering. 232 // Named and keyed loads require a VectorSlotPair for successful lowering.
224 VectorSlotPair CreateVectorSlotPair(FeedbackVectorICSlot slot) const; 233 VectorSlotPair CreateVectorSlotPair(FeedbackVectorICSlot slot) const;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 public: 374 public:
366 Environment(AstGraphBuilder* builder, Scope* scope, Node* control_dependency); 375 Environment(AstGraphBuilder* builder, Scope* scope, Node* control_dependency);
367 376
368 int parameters_count() const { return parameters_count_; } 377 int parameters_count() const { return parameters_count_; }
369 int locals_count() const { return locals_count_; } 378 int locals_count() const { return locals_count_; }
370 int stack_height() { 379 int stack_height() {
371 return static_cast<int>(values()->size()) - parameters_count_ - 380 return static_cast<int>(values()->size()) - parameters_count_ -
372 locals_count_; 381 locals_count_;
373 } 382 }
374 383
375 // Operations on parameter or local variables. The parameter indices are 384 // Operations on parameter or local variables.
376 // shifted by 1 (receiver is parameter index -1 but environment index 0). 385 void Bind(Variable* variable, Node* node);
377 void Bind(Variable* variable, Node* node) { 386 Node* Lookup(Variable* variable);
378 DCHECK(variable->IsStackAllocated()); 387 void MarkAllLocalsLive();
379 if (variable->IsParameter()) {
380 values()->at(variable->index() + 1) = node;
381 } else {
382 DCHECK(variable->IsStackLocal());
383 values()->at(variable->index() + parameters_count_) = node;
384 }
385 }
386 Node* Lookup(Variable* variable) {
387 DCHECK(variable->IsStackAllocated());
388 if (variable->IsParameter()) {
389 return values()->at(variable->index() + 1);
390 } else {
391 DCHECK(variable->IsStackLocal());
392 return values()->at(variable->index() + parameters_count_);
393 }
394 }
395 388
396 Node* Context() const { return contexts_.back(); } 389 Node* Context() const { return contexts_.back(); }
397 void PushContext(Node* context) { contexts()->push_back(context); } 390 void PushContext(Node* context) { contexts()->push_back(context); }
398 void PopContext() { contexts()->pop_back(); } 391 void PopContext() { contexts()->pop_back(); }
399 392
400 // Operations on the operand stack. 393 // Operations on the operand stack.
401 void Push(Node* node) { 394 void Push(Node* node) {
402 values()->push_back(node); 395 values()->push_back(node);
403 } 396 }
404 Node* Top() { 397 Node* Top() {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // Copies this environment to a potentially unreachable control-flow point. 460 // Copies this environment to a potentially unreachable control-flow point.
468 Environment* CopyAsUnreachable() { 461 Environment* CopyAsUnreachable() {
469 Environment* env = Copy(); 462 Environment* env = Copy();
470 env->MarkAsUnreachable(); 463 env->MarkAsUnreachable();
471 return env; 464 return env;
472 } 465 }
473 466
474 // Copies this environment at a loop header control-flow point. 467 // Copies this environment at a loop header control-flow point.
475 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) { 468 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) {
476 PrepareForLoop(assigned, is_osr); 469 PrepareForLoop(assigned, is_osr);
477 return Copy(); 470 return CopyAndShareLiveness();
478 } 471 }
479 472
480 int ContextStackDepth() { return static_cast<int>(contexts_.size()); } 473 int ContextStackDepth() { return static_cast<int>(contexts_.size()); }
481 474
482 private: 475 private:
483 AstGraphBuilder* builder_; 476 AstGraphBuilder* builder_;
484 int parameters_count_; 477 int parameters_count_;
485 int locals_count_; 478 int locals_count_;
479 LivenessAnalyzerBlock* liveness_block_;
486 NodeVector values_; 480 NodeVector values_;
487 NodeVector contexts_; 481 NodeVector contexts_;
488 Node* control_dependency_; 482 Node* control_dependency_;
489 Node* effect_dependency_; 483 Node* effect_dependency_;
490 Node* parameters_node_; 484 Node* parameters_node_;
491 Node* locals_node_; 485 Node* locals_node_;
492 Node* stack_node_; 486 Node* stack_node_;
493 487
494 explicit Environment(const Environment* copy); 488 explicit Environment(Environment* copy);
495 Environment* Copy() { return new (zone()) Environment(this); } 489 Environment* Copy() { return new (zone()) Environment(this); }
490 Environment* CopyAndShareLiveness();
496 void UpdateStateValues(Node** state_values, int offset, int count); 491 void UpdateStateValues(Node** state_values, int offset, int count);
497 void UpdateStateValuesWithCache(Node** state_values, int offset, int count); 492 void UpdateStateValuesWithCache(Node** state_values, int offset, int count);
498 Zone* zone() const { return builder_->local_zone(); } 493 Zone* zone() const { return builder_->local_zone(); }
499 Graph* graph() const { return builder_->graph(); } 494 Graph* graph() const { return builder_->graph(); }
500 AstGraphBuilder* builder() const { return builder_; } 495 AstGraphBuilder* builder() const { return builder_; }
501 CommonOperatorBuilder* common() { return builder_->common(); } 496 CommonOperatorBuilder* common() { return builder_->common(); }
502 NodeVector* values() { return &values_; } 497 NodeVector* values() { return &values_; }
503 NodeVector* contexts() { return &contexts_; } 498 NodeVector* contexts() { return &contexts_; }
499 LivenessAnalyzerBlock* liveness_block() { return liveness_block_; }
504 500
505 // Prepare environment to be used as loop header. 501 // Prepare environment to be used as loop header.
506 void PrepareForLoop(BitVector* assigned, bool is_osr = false); 502 void PrepareForLoop(BitVector* assigned, bool is_osr = false);
507 }; 503 };
508 504
509 } // namespace compiler 505 } // namespace compiler
510 } // namespace internal 506 } // namespace internal
511 } // namespace v8 507 } // namespace v8
512 508
513 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ 509 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698