Reviewers: fschneider,
Description:
Add IsStackAllocated helper for variables.
Add a simple boolean helper function for Variables and Slots.
Please review this at http://codereview.chromium.org/722001
Affected files:
M src/ast.h
M src/data-flow.cc
M src/rewriter.cc
M src/variables.h
M src/variables.cc
Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index
13ef6c82a7f3992dd13b70d6da6bf63159371a3a..13502dc2a8082736289c7352ee4d625f50badf35
100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -1047,6 +1047,8 @@ class Slot: public Expression {
virtual bool IsLeaf() { return true; }
+ bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; }
+
// Accessors
Variable* var() const { return var_; }
Type type() const { return type_; }
Index: src/data-flow.cc
diff --git a/src/data-flow.cc b/src/data-flow.cc
index
1a0cf1a18765cf4843b14b21be4ef2225e53caa3..6b45da02b93040d7e64d616f86f285be7b8c7d00
100644
--- a/src/data-flow.cc
+++ b/src/data-flow.cc
@@ -433,11 +433,7 @@ void FlowGraphBuilder::VisitAssignment(Assignment*
expr) {
ASSERT(var == NULL || 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);
- }
+ if (var->IsStackAllocated()) definitions_.Add(expr);
} else if (prop != NULL) {
Visit(prop->obj());
@@ -499,12 +495,8 @@ 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);
- }
+ if (var != NULL && var->IsStackAllocated()) {
+ definitions_.Add(expr);
}
graph_.AppendInstruction(expr);
}
Index: src/rewriter.cc
diff --git a/src/rewriter.cc b/src/rewriter.cc
index
15f1ca52cbadd6b0aec769f8c6d8f419d1754613..8a3221280cf673a5489dec1bfcd2adc352e5941c
100644
--- a/src/rewriter.cc
+++ b/src/rewriter.cc
@@ -246,11 +246,8 @@ void AstOptimizer::VisitVariableProxy(VariableProxy*
node) {
}
if (FLAG_safe_int32_compiler) {
- Slot* slot = var->slot();
- if (slot != NULL) {
- node->set_side_effect_free(
- (slot->type() == Slot::LOCAL && !slot->is_arguments()) ||
- slot->type() == Slot::PARAMETER);
+ if (var->IsStackAllocated() && !var->is_arguments()) {
+ node->set_side_effect_free(true);
}
}
}
Index: src/variables.cc
diff --git a/src/variables.cc b/src/variables.cc
index
d7c25320bcc1f9da6d1df3dbc00461f78948ae1d..f46a54d6ef5daa1e0cd5b65301eb58f817bbb608
100644
--- a/src/variables.cc
+++ b/src/variables.cc
@@ -85,6 +85,12 @@ Slot* Variable::slot() const {
}
+bool Variable::IsStackAllocated() const {
+ Slot* s = slot();
+ return s != NULL && s->IsStackAllocated();
+}
+
+
Variable::Variable(Scope* scope,
Handle<String> name,
Mode mode,
Index: src/variables.h
diff --git a/src/variables.h b/src/variables.h
index
1751f1285dd7dbaf1817411c8da3ccb1e182115b..a68aa337f44ba48694d12443a61b23bb8817047f
100644
--- a/src/variables.h
+++ b/src/variables.h
@@ -146,6 +146,8 @@ class Variable: public ZoneObject {
return !is_this() && name().is_identical_to(n);
}
+ bool IsStackAllocated() const;
+
bool is_dynamic() const {
return (mode_ == DYNAMIC ||
mode_ == DYNAMIC_GLOBAL ||
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev