Revision: 9841
Author:   [email protected]
Date:     Mon Oct 31 04:11:26 2011
Log:      Eliminate some virtual function from AST classes.

1. Remove unused dead functions.

2. Replace the virtual As-* type cast functions with non-virtual version
that uses node_type().

Result is around 13K reduction in binary size.
Review URL: http://codereview.chromium.org/8335006
http://code.google.com/p/v8/source/detail?r=9841

Modified:
 /branches/bleeding_edge/src/ast.cc
 /branches/bleeding_edge/src/ast.h
 /branches/bleeding_edge/src/hydrogen.cc

=======================================
--- /branches/bleeding_edge/src/ast.cc  Wed Oct 19 04:41:22 2011
+++ /branches/bleeding_edge/src/ast.cc  Mon Oct 31 04:11:26 2011
@@ -48,16 +48,19 @@
// ----------------------------------------------------------------------------
 // Implementation of other node functionality.

-Assignment* ExpressionStatement::StatementAsSimpleAssignment() {
-  return (expression()->AsAssignment() != NULL &&
-          !expression()->AsAssignment()->is_compound())
-      ? expression()->AsAssignment()
-      : NULL;
+
+bool Expression::IsSmiLiteral() {
+  return AsLiteral() != NULL && AsLiteral()->handle()->IsSmi();
 }


-CountOperation* ExpressionStatement::StatementAsCountOperation() {
-  return expression()->AsCountOperation();
+bool Expression::IsStringLiteral() {
+  return AsLiteral() != NULL && AsLiteral()->handle()->IsString();
+}
+
+
+bool Expression::IsNullLiteral() {
+  return AsLiteral() != NULL && AsLiteral()->handle()->IsNull();
 }


=======================================
--- /branches/bleeding_edge/src/ast.h   Tue Oct 25 01:33:08 2011
+++ /branches/bleeding_edge/src/ast.h   Mon Oct 31 04:11:26 2011
@@ -118,7 +118,6 @@
 #define DECLARE_NODE_TYPE(type)                                         \
   virtual void Accept(AstVisitor* v);                                   \
   virtual AstNode::Type node_type() const { return AstNode::k##type; }  \
-  virtual type* As##type() { return this; }


 class AstNode: public ZoneObject {
@@ -153,7 +152,8 @@

   // Type testing & conversion functions overridden by concrete subclasses.
 #define DECLARE_NODE_FUNCTIONS(type)                  \
-  virtual type* As##type() { return NULL; }
+  bool Is##type() { return node_type() == AstNode::k##type; }          \
+ type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; }
   AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
 #undef DECLARE_NODE_FUNCTIONS

@@ -195,9 +195,6 @@
   Statement() : statement_pos_(RelocInfo::kNoPosition) {}

   virtual Statement* AsStatement()  { return this; }
-
-  virtual Assignment* StatementAsSimpleAssignment() { return NULL; }
-  virtual CountOperation* StatementAsCountOperation() { return NULL; }

   bool IsEmpty() { return AsEmptyStatement() != NULL; }

@@ -264,7 +261,6 @@

   virtual Expression* AsExpression()  { return this; }

-  virtual bool IsTrivial() { return false; }
   virtual bool IsValidLeftHandSide() { return false; }

   // Helpers for ToBoolean conversion.
@@ -275,34 +271,25 @@
   // names.  We do not treat symbols that can be array indexes as property
   // names because [] for string objects is handled only by keyed ICs.
   virtual bool IsPropertyName() { return false; }
-
-  // Mark the expression as being compiled as an expression
-  // statement. This is used to transform postfix increments to
-  // (faster) prefix increments.
-  virtual void MarkAsStatement() { /* do nothing */ }

   // True iff the result can be safely overwritten (to avoid allocation).
   // False for operations that can return one of their operands.
   virtual bool ResultOverwriteAllowed() { return false; }

   // True iff the expression is a literal represented as a smi.
-  virtual bool IsSmiLiteral() { return false; }
+  bool IsSmiLiteral();

   // True iff the expression is a string literal.
-  virtual bool IsStringLiteral() { return false; }
+  bool IsStringLiteral();

   // True iff the expression is the null literal.
-  virtual bool IsNullLiteral() { return false; }
+  bool IsNullLiteral();

   // Type feedback information for assignments and properties.
   virtual bool IsMonomorphic() {
     UNREACHABLE();
     return false;
   }
-  virtual bool IsArrayLength() {
-    UNREACHABLE();
-    return false;
-  }
   virtual SmallMapList* GetReceiverTypes() {
     UNREACHABLE();
     return NULL;
@@ -368,16 +355,6 @@

   DECLARE_NODE_TYPE(Block)

-  virtual Assignment* StatementAsSimpleAssignment() {
-    if (statements_.length() != 1) return NULL;
-    return statements_[0]->StatementAsSimpleAssignment();
-  }
-
-  virtual CountOperation* StatementAsCountOperation() {
-    if (statements_.length() != 1) return NULL;
-    return statements_[0]->StatementAsCountOperation();
-  }
-
   virtual bool IsInlineable() const;

   void AddStatement(Statement* statement) { statements_.Add(statement); }
@@ -612,9 +589,6 @@

   virtual bool IsInlineable() const;

-  virtual Assignment* StatementAsSimpleAssignment();
-  virtual CountOperation* StatementAsCountOperation();
-
   void set_expression(Expression* e) { expression_ = e; }
   Expression* expression() const { return expression_; }

@@ -894,11 +868,6 @@
       : Expression(isolate), handle_(handle) { }

   DECLARE_NODE_TYPE(Literal)
-
-  virtual bool IsTrivial() { return true; }
-  virtual bool IsSmiLiteral() { return handle_->IsSmi(); }
-  virtual bool IsStringLiteral() { return handle_->IsString(); }
-  virtual bool IsNullLiteral() { return handle_->IsNull(); }

   // Check if this literal is identical to the other literal.
   bool IsIdenticalTo(const Literal* other) const {
@@ -1113,12 +1082,6 @@
   virtual bool IsValidLeftHandSide() {
     return var_ == NULL ? true : var_->IsValidLeftHandSide();
   }
-
-  virtual bool IsTrivial() {
-    // Reading from a mutable variable is a side effect, but the
-    // variable for 'this' is immutable.
-    return is_this_ || is_trivial_;
-  }

   virtual bool IsInlineable() const;

@@ -1187,7 +1150,7 @@
   void RecordTypeFeedback(TypeFeedbackOracle* oracle);
   virtual bool IsMonomorphic() { return is_monomorphic_; }
   virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
-  virtual bool IsArrayLength() { return is_array_length_; }
+  bool IsArrayLength() { return is_array_length_; }

  private:
   Expression* obj_;
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Fri Oct 28 05:37:29 2011
+++ /branches/bleeding_edge/src/hydrogen.cc     Mon Oct 31 04:11:26 2011
@@ -4368,7 +4368,7 @@
   CHECK_ALIVE(VisitForValue(expr->obj()));

   HInstruction* instr = NULL;
-  if (expr->IsArrayLength()) {
+  if (expr->AsProperty()->IsArrayLength()) {
     HValue* array = Pop();
     AddInstruction(new(zone()) HCheckNonSmi(array));
     HInstruction* mapcheck =

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

Reply via email to