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.

Review URL: http://codereview.chromium.org/668257

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4064 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent cc9512f6
......@@ -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);
}
......
......@@ -385,7 +385,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);
......@@ -406,6 +411,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);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment