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

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

Issue 656123005: Implement loop variable assignment analysis. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added unit tests. Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler/ast-graph-builder.h ('k') | src/compiler/ast-loop-assignment-analyzer.h » ('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 #include "src/compiler/ast-graph-builder.h" 5 #include "src/compiler/ast-graph-builder.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/compiler/ast-loop-assignment-analyzer.h"
8 #include "src/compiler/control-builders.h" 9 #include "src/compiler/control-builders.h"
9 #include "src/compiler/machine-operator.h" 10 #include "src/compiler/machine-operator.h"
11 #include "src/compiler/node-properties-inl.h"
10 #include "src/compiler/node-properties.h" 12 #include "src/compiler/node-properties.h"
11 #include "src/compiler/node-properties-inl.h"
12 #include "src/full-codegen.h" 13 #include "src/full-codegen.h"
13 #include "src/parser.h" 14 #include "src/parser.h"
14 #include "src/scopes.h" 15 #include "src/scopes.h"
15 16
16 namespace v8 { 17 namespace v8 {
17 namespace internal { 18 namespace internal {
18 namespace compiler { 19 namespace compiler {
19 20
20 AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info, 21 AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info,
21 JSGraph* jsgraph) 22 JSGraph* jsgraph)
22 : StructuredGraphBuilder(local_zone, jsgraph->graph(), jsgraph->common()), 23 : StructuredGraphBuilder(local_zone, jsgraph->graph(), jsgraph->common()),
23 info_(info), 24 info_(info),
24 jsgraph_(jsgraph), 25 jsgraph_(jsgraph),
25 globals_(0, local_zone), 26 globals_(0, local_zone),
26 breakable_(NULL), 27 breakable_(NULL),
27 execution_context_(NULL) { 28 execution_context_(NULL),
29 loop_assignment_analysis_(NULL) {
28 InitializeAstVisitor(local_zone); 30 InitializeAstVisitor(local_zone);
29 } 31 }
30 32
31 33
32 Node* AstGraphBuilder::GetFunctionClosure() { 34 Node* AstGraphBuilder::GetFunctionClosure() {
33 if (!function_closure_.is_set()) { 35 if (!function_closure_.is_set()) {
34 // Parameter -1 is special for the function closure 36 // Parameter -1 is special for the function closure
35 const Operator* op = common()->Parameter(-1); 37 const Operator* op = common()->Parameter(-1);
36 Node* node = NewNode(op, graph()->start()); 38 Node* node = NewNode(op, graph()->start());
37 function_closure_.set(node); 39 function_closure_.set(node);
(...skipping 14 matching lines...) Expand all
52 54
53 55
54 bool AstGraphBuilder::CreateGraph() { 56 bool AstGraphBuilder::CreateGraph() {
55 Scope* scope = info()->scope(); 57 Scope* scope = info()->scope();
56 DCHECK(graph() != NULL); 58 DCHECK(graph() != NULL);
57 59
58 // Set up the basic structure of the graph. 60 // Set up the basic structure of the graph.
59 int parameter_count = info()->num_parameters(); 61 int parameter_count = info()->num_parameters();
60 graph()->SetStart(graph()->NewNode(common()->Start(parameter_count))); 62 graph()->SetStart(graph()->NewNode(common()->Start(parameter_count)));
61 63
64 if (FLAG_loop_assignment_analysis) {
65 // TODO(turbofan): use a temporary zone for the loop assignment analysis.
66 AstLoopAssignmentAnalyzer analyzer(zone(), info());
67 loop_assignment_analysis_ = analyzer.Analyze();
68 }
69
62 // Initialize the top-level environment. 70 // Initialize the top-level environment.
63 Environment env(this, scope, graph()->start()); 71 Environment env(this, scope, graph()->start());
64 set_environment(&env); 72 set_environment(&env);
65 73
66 // Build node to initialize local function context. 74 // Build node to initialize local function context.
67 Node* closure = GetFunctionClosure(); 75 Node* closure = GetFunctionClosure();
68 Node* outer = GetFunctionContext(); 76 Node* outer = GetFunctionContext();
69 Node* inner = BuildLocalFunctionContext(outer, closure); 77 Node* inner = BuildLocalFunctionContext(outer, closure);
70 78
71 // Push top-level function scope for the function body. 79 // Push top-level function scope for the function body.
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 CaseClause* clause = clauses->at(i); 580 CaseClause* clause = clauses->at(i);
573 compare_switch.BeginCase(i); 581 compare_switch.BeginCase(i);
574 VisitStatements(clause->statements()); 582 VisitStatements(clause->statements());
575 compare_switch.EndCase(); 583 compare_switch.EndCase();
576 } 584 }
577 585
578 compare_switch.EndSwitch(); 586 compare_switch.EndSwitch();
579 } 587 }
580 588
581 589
590 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop(
591 IterationStatement* stmt) {
592 if (loop_assignment_analysis_ == NULL) return NULL;
593 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt);
594 }
595
596
582 void AstGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { 597 void AstGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) {
583 LoopBuilder while_loop(this); 598 LoopBuilder while_loop(this);
584 while_loop.BeginLoop(); 599 while_loop.BeginLoop(GetVariablesAssignedInLoop(stmt));
585 VisitIterationBody(stmt, &while_loop, 0); 600 VisitIterationBody(stmt, &while_loop, 0);
586 while_loop.EndBody(); 601 while_loop.EndBody();
587 VisitForTest(stmt->cond()); 602 VisitForTest(stmt->cond());
588 Node* condition = environment()->Pop(); 603 Node* condition = environment()->Pop();
589 while_loop.BreakUnless(condition); 604 while_loop.BreakUnless(condition);
590 while_loop.EndLoop(); 605 while_loop.EndLoop();
591 } 606 }
592 607
593 608
594 void AstGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { 609 void AstGraphBuilder::VisitWhileStatement(WhileStatement* stmt) {
595 LoopBuilder while_loop(this); 610 LoopBuilder while_loop(this);
596 while_loop.BeginLoop(); 611 while_loop.BeginLoop(GetVariablesAssignedInLoop(stmt));
597 VisitForTest(stmt->cond()); 612 VisitForTest(stmt->cond());
598 Node* condition = environment()->Pop(); 613 Node* condition = environment()->Pop();
599 while_loop.BreakUnless(condition); 614 while_loop.BreakUnless(condition);
600 VisitIterationBody(stmt, &while_loop, 0); 615 VisitIterationBody(stmt, &while_loop, 0);
601 while_loop.EndBody(); 616 while_loop.EndBody();
602 while_loop.EndLoop(); 617 while_loop.EndLoop();
603 } 618 }
604 619
605 620
606 void AstGraphBuilder::VisitForStatement(ForStatement* stmt) { 621 void AstGraphBuilder::VisitForStatement(ForStatement* stmt) {
607 LoopBuilder for_loop(this); 622 LoopBuilder for_loop(this);
608 VisitIfNotNull(stmt->init()); 623 VisitIfNotNull(stmt->init());
609 for_loop.BeginLoop(); 624 for_loop.BeginLoop(GetVariablesAssignedInLoop(stmt));
610 if (stmt->cond() != NULL) { 625 if (stmt->cond() != NULL) {
611 VisitForTest(stmt->cond()); 626 VisitForTest(stmt->cond());
612 Node* condition = environment()->Pop(); 627 Node* condition = environment()->Pop();
613 for_loop.BreakUnless(condition); 628 for_loop.BreakUnless(condition);
614 } else { 629 } else {
615 for_loop.BreakUnless(jsgraph()->TrueConstant()); 630 for_loop.BreakUnless(jsgraph()->TrueConstant());
616 } 631 }
617 VisitIterationBody(stmt, &for_loop, 0); 632 VisitIterationBody(stmt, &for_loop, 0);
618 for_loop.EndBody(); 633 for_loop.EndBody();
619 VisitIfNotNull(stmt->next()); 634 VisitIfNotNull(stmt->next());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 environment()->Pop(); 690 environment()->Pop();
676 have_no_properties.Else(); 691 have_no_properties.Else();
677 { 692 {
678 // Construct the rest of the environment. 693 // Construct the rest of the environment.
679 environment()->Push(cache_type); 694 environment()->Push(cache_type);
680 environment()->Push(cache_array); 695 environment()->Push(cache_array);
681 environment()->Push(cache_length); 696 environment()->Push(cache_length);
682 environment()->Push(jsgraph()->ZeroConstant()); 697 environment()->Push(jsgraph()->ZeroConstant());
683 // PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); 698 // PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
684 LoopBuilder for_loop(this); 699 LoopBuilder for_loop(this);
685 for_loop.BeginLoop(); 700 for_loop.BeginLoop(GetVariablesAssignedInLoop(stmt));
686 // Check loop termination condition. 701 // Check loop termination condition.
687 Node* index = environment()->Peek(0); 702 Node* index = environment()->Peek(0);
688 Node* exit_cond = 703 Node* exit_cond =
689 NewNode(javascript()->LessThan(), index, cache_length); 704 NewNode(javascript()->LessThan(), index, cache_length);
690 // TODO(jarin): provide real bailout id. 705 // TODO(jarin): provide real bailout id.
691 PrepareFrameState(exit_cond, BailoutId::None()); 706 PrepareFrameState(exit_cond, BailoutId::None());
692 for_loop.BreakUnless(exit_cond); 707 for_loop.BreakUnless(exit_cond);
693 // TODO(dcarney): this runtime call should be a handful of 708 // TODO(dcarney): this runtime call should be a handful of
694 // simplified instructions that 709 // simplified instructions that
695 // basically produce 710 // basically produce
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 DCHECK(NodeProperties::GetFrameStateInput(node)->opcode() == 2143 DCHECK(NodeProperties::GetFrameStateInput(node)->opcode() ==
2129 IrOpcode::kDead); 2144 IrOpcode::kDead);
2130 NodeProperties::ReplaceFrameStateInput( 2145 NodeProperties::ReplaceFrameStateInput(
2131 node, environment()->Checkpoint(ast_id, combine)); 2146 node, environment()->Checkpoint(ast_id, combine));
2132 } 2147 }
2133 } 2148 }
2134 2149
2135 } 2150 }
2136 } 2151 }
2137 } // namespace v8::internal::compiler 2152 } // namespace v8::internal::compiler
OLDNEW
« no previous file with comments | « src/compiler/ast-graph-builder.h ('k') | src/compiler/ast-loop-assignment-analyzer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698