Reviewers: fschneider,

Message:
Simple code review for you.

Description:
Have the flow graph builder collect definitions.

Before computing reaching definitions, the set of all definitions in a
function must be collected and they must be numbered.  Have the flow
graph builder collect definitions for stack-allocated variables into a
list, and implicitly number them with their list index.

Please review this at http://codereview.chromium.org/668257

Affected files:
  M src/data-flow.h
  M src/data-flow.cc


Index: src/data-flow.cc
diff --git a/src/data-flow.cc b/src/data-flow.cc
index 96acb9959cfd0b58edbfa175dfaa498da9e398d6..1a0cf1a18765cf4843b14b21be4ef2225e53caa3 100644
--- a/src/data-flow.cc
+++ b/src/data-flow.cc
@@ -431,11 +431,17 @@ void FlowGraphBuilder::VisitAssignment(Assignment* expr) {
   // Left-hand side can be a variable or property (or reference error) but
   // not both.
   ASSERT(var == NULL || prop == NULL);
-  if (prop != NULL) {
+  if (var != NULL) {
+    Visit(expr->value());
+    Slot* slot = var->slot();
+    if (slot != NULL &&
+        (slot->type() == Slot::LOCAL || slot->type() == Slot::PARAMETER)) {
+      definitions_.Add(expr);
+    }
+
+  } else if (prop != NULL) {
     Visit(prop->obj());
     if (!prop->key()->IsPropertyName()) Visit(prop->key());
-  }
-  if (var != NULL || prop != NULL) {
     Visit(expr->value());
   }
   graph_.AppendInstruction(expr);
@@ -492,6 +498,14 @@ void FlowGraphBuilder::VisitUnaryOperation(UnaryOperation* expr) {

 void FlowGraphBuilder::VisitCountOperation(CountOperation* expr) {
   Visit(expr->expression());
+  Variable* var = expr->expression()->AsVariableProxy()->AsVariable();
+  if (var != NULL) {
+    Slot* slot = var->slot();
+    if (slot != NULL &&
+        (slot->type() == Slot::LOCAL || slot->type() == Slot::PARAMETER)) {
+      definitions_.Add(expr);
+    }
+  }
   graph_.AppendInstruction(expr);
 }

Index: src/data-flow.h
diff --git a/src/data-flow.h b/src/data-flow.h
index 30c0336114a3bc31a6d3a78fcf1ad38b4c35b439..aec995b06a2b5685beee3773b1545d6bc0ff6a1f 100644
--- a/src/data-flow.h
+++ b/src/data-flow.h
@@ -363,7 +363,12 @@ class JoinNode: public Node {
 // traversal orders as a byproduct.
 class FlowGraphBuilder: public AstVisitor {
  public:
-  FlowGraphBuilder() : global_exit_(NULL), preorder_(4), postorder_(4) {}
+  FlowGraphBuilder()
+      : global_exit_(NULL),
+        preorder_(4),
+        postorder_(4),
+        definitions_(4) {
+  }

   void Build(FunctionLiteral* lit);

@@ -384,6 +389,11 @@ class FlowGraphBuilder: public AstVisitor {
   ZoneList<Node*> preorder_;
   ZoneList<Node*> postorder_;

+  // The flow graph builder collects a list of definitions (assignments and
+  // count operations) to stack-allocated variables to use for reaching
+  // definitions analysis.
+  ZoneList<AstNode*> definitions_;
+
   DISALLOW_COPY_AND_ASSIGN(FlowGraphBuilder);
 };



--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to