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

Unified Diff: src/ast.h

Issue 1159005: Initial support for marking live code. (Closed)
Patch Set: Addressed review comments. Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index def803bbe727c3dc20b066e42b4f93741ffec68a..53ce1ab772ca97e447aad34dc5db037f437e2b16 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -152,6 +152,10 @@ class AstNode: public ZoneObject {
virtual ArrayLiteral* AsArrayLiteral() { return NULL; }
virtual CompareOperation* AsCompareOperation() { return NULL; }
+ // True if the AST node is critical (its execution is needed or externally
+ // visible in some way).
+ virtual bool IsCritical() { UNREACHABLE(); return true; }
+
int num() { return num_; }
void set_num(int n) { num_ = n; }
@@ -211,7 +215,7 @@ class Expression: public AstNode {
virtual bool IsValidLeftHandSide() { return false; }
- virtual Variable* AssignedVar() { return NULL; }
+ virtual Variable* AssignedVariable() { return NULL; }
// Symbols that cannot be parsed as array indices are considered property
// names. We do not treat symbols that can be array indexes as property
@@ -283,6 +287,19 @@ class Expression: public AstNode {
bitfields_ |= NumBitOpsField::encode(num_bit_ops);
}
+ // Functions used for dead-code elimination. Predicate is true if the
+ // expression is not dead code.
+ int is_live() const { return LiveField::decode(bitfields_); }
+ void mark_as_live() { bitfields_ |= LiveField::encode(true); }
+
+ // Mark non-live children as live and push them on a stack for further
+ // processing.
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count) {
+ }
+
private:
static const int kMaxNumBitOps = (1 << 5) - 1;
@@ -295,6 +312,7 @@ class Expression: public AstNode {
class ToInt32Field : public BitField<bool, 2, 1> {};
class NumBitOpsField : public BitField<int, 3, 5> {};
class LoopConditionField: public BitField<bool, 8, 1> {};
+ class LiveField: public BitField<bool, 9, 1> {};
};
@@ -881,6 +899,11 @@ class Literal: public Expression {
virtual bool IsLeaf() { return true; }
virtual bool IsTrivial() { return true; }
virtual bool IsPrimitive();
+ virtual bool IsCritical();
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count);
// Identity testers.
bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); }
@@ -1087,6 +1110,11 @@ class VariableProxy: public Expression {
virtual bool IsTrivial() { return is_trivial_; }
virtual bool IsPrimitive();
+ virtual bool IsCritical();
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count);
void SetIsPrimitive(bool value) { is_primitive_ = value; }
@@ -1224,6 +1252,11 @@ class Property: public Expression {
virtual bool IsValidLeftHandSide() { return true; }
virtual bool IsPrimitive();
+ virtual bool IsCritical();
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count);
Expression* obj() const { return obj_; }
Expression* key() const { return key_; }
@@ -1258,6 +1291,11 @@ class Call: public Expression {
virtual Call* AsCall() { return this; }
virtual bool IsPrimitive();
+ virtual bool IsCritical();
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count);
Expression* expression() const { return expression_; }
ZoneList<Expression*>* arguments() const { return arguments_; }
@@ -1336,6 +1374,11 @@ class UnaryOperation: public Expression {
virtual UnaryOperation* AsUnaryOperation() { return this; }
virtual bool IsPrimitive();
+ virtual bool IsCritical();
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count);
Token::Value op() const { return op_; }
Expression* expression() const { return expression_; }
@@ -1361,6 +1404,11 @@ class BinaryOperation: public Expression {
virtual BinaryOperation* AsBinaryOperation() { return this; }
virtual bool IsPrimitive();
+ virtual bool IsCritical();
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count);
// True iff the result can be safely overwritten (to avoid allocation).
// False for operations that can return one of their operands.
@@ -1412,11 +1460,16 @@ class CountOperation: public Expression {
virtual CountOperation* AsCountOperation() { return this; }
- virtual Variable* AssignedVar() {
+ virtual Variable* AssignedVariable() {
return expression()->AsVariableProxy()->AsVariable();
}
virtual bool IsPrimitive();
+ virtual bool IsCritical();
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count);
bool is_prefix() const { return is_prefix_; }
bool is_postfix() const { return !is_prefix_; }
@@ -1449,6 +1502,11 @@ class CompareOperation: public Expression {
virtual void Accept(AstVisitor* v);
virtual bool IsPrimitive();
+ virtual bool IsCritical();
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count);
Token::Value op() const { return op_; }
Expression* left() const { return left_; }
@@ -1502,10 +1560,15 @@ class Assignment: public Expression {
virtual Assignment* AsAssignment() { return this; }
virtual bool IsPrimitive();
+ virtual bool IsCritical();
+ virtual void ProcessNonLiveChildren(
+ List<AstNode*>* stack,
+ ZoneList<Expression*>* body_definitions,
+ int variable_count);
Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
- virtual Variable* AssignedVar() {
+ virtual Variable* AssignedVariable() {
return target()->AsVariableProxy()->AsVariable();
}
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698