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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9841 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 30465596
...@@ -48,16 +48,19 @@ AST_NODE_LIST(DECL_ACCEPT) ...@@ -48,16 +48,19 @@ AST_NODE_LIST(DECL_ACCEPT)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Implementation of other node functionality. // Implementation of other node functionality.
Assignment* ExpressionStatement::StatementAsSimpleAssignment() {
return (expression()->AsAssignment() != NULL && bool Expression::IsSmiLiteral() {
!expression()->AsAssignment()->is_compound()) return AsLiteral() != NULL && AsLiteral()->handle()->IsSmi();
? expression()->AsAssignment() }
: NULL;
bool Expression::IsStringLiteral() {
return AsLiteral() != NULL && AsLiteral()->handle()->IsString();
} }
CountOperation* ExpressionStatement::StatementAsCountOperation() { bool Expression::IsNullLiteral() {
return expression()->AsCountOperation(); return AsLiteral() != NULL && AsLiteral()->handle()->IsNull();
} }
......
...@@ -118,7 +118,6 @@ typedef ZoneList<Handle<Object> > ZoneObjectList; ...@@ -118,7 +118,6 @@ typedef ZoneList<Handle<Object> > ZoneObjectList;
#define DECLARE_NODE_TYPE(type) \ #define DECLARE_NODE_TYPE(type) \
virtual void Accept(AstVisitor* v); \ virtual void Accept(AstVisitor* v); \
virtual AstNode::Type node_type() const { return AstNode::k##type; } \ virtual AstNode::Type node_type() const { return AstNode::k##type; } \
virtual type* As##type() { return this; }
class AstNode: public ZoneObject { class AstNode: public ZoneObject {
...@@ -153,7 +152,8 @@ class AstNode: public ZoneObject { ...@@ -153,7 +152,8 @@ class AstNode: public ZoneObject {
// Type testing & conversion functions overridden by concrete subclasses. // Type testing & conversion functions overridden by concrete subclasses.
#define DECLARE_NODE_FUNCTIONS(type) \ #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) AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
#undef DECLARE_NODE_FUNCTIONS #undef DECLARE_NODE_FUNCTIONS
...@@ -196,9 +196,6 @@ class Statement: public AstNode { ...@@ -196,9 +196,6 @@ class Statement: public AstNode {
virtual Statement* AsStatement() { return this; } virtual Statement* AsStatement() { return this; }
virtual Assignment* StatementAsSimpleAssignment() { return NULL; }
virtual CountOperation* StatementAsCountOperation() { return NULL; }
bool IsEmpty() { return AsEmptyStatement() != NULL; } bool IsEmpty() { return AsEmptyStatement() != NULL; }
void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }
...@@ -264,7 +261,6 @@ class Expression: public AstNode { ...@@ -264,7 +261,6 @@ class Expression: public AstNode {
virtual Expression* AsExpression() { return this; } virtual Expression* AsExpression() { return this; }
virtual bool IsTrivial() { return false; }
virtual bool IsValidLeftHandSide() { return false; } virtual bool IsValidLeftHandSide() { return false; }
// Helpers for ToBoolean conversion. // Helpers for ToBoolean conversion.
...@@ -276,33 +272,24 @@ class Expression: public AstNode { ...@@ -276,33 +272,24 @@ class Expression: public AstNode {
// names because [] for string objects is handled only by keyed ICs. // names because [] for string objects is handled only by keyed ICs.
virtual bool IsPropertyName() { return false; } 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). // True iff the result can be safely overwritten (to avoid allocation).
// False for operations that can return one of their operands. // False for operations that can return one of their operands.
virtual bool ResultOverwriteAllowed() { return false; } virtual bool ResultOverwriteAllowed() { return false; }
// True iff the expression is a literal represented as a smi. // 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. // True iff the expression is a string literal.
virtual bool IsStringLiteral() { return false; } bool IsStringLiteral();
// True iff the expression is the null literal. // True iff the expression is the null literal.
virtual bool IsNullLiteral() { return false; } bool IsNullLiteral();
// Type feedback information for assignments and properties. // Type feedback information for assignments and properties.
virtual bool IsMonomorphic() { virtual bool IsMonomorphic() {
UNREACHABLE(); UNREACHABLE();
return false; return false;
} }
virtual bool IsArrayLength() {
UNREACHABLE();
return false;
}
virtual SmallMapList* GetReceiverTypes() { virtual SmallMapList* GetReceiverTypes() {
UNREACHABLE(); UNREACHABLE();
return NULL; return NULL;
...@@ -368,16 +355,6 @@ class Block: public BreakableStatement { ...@@ -368,16 +355,6 @@ class Block: public BreakableStatement {
DECLARE_NODE_TYPE(Block) 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; virtual bool IsInlineable() const;
void AddStatement(Statement* statement) { statements_.Add(statement); } void AddStatement(Statement* statement) { statements_.Add(statement); }
...@@ -612,9 +589,6 @@ class ExpressionStatement: public Statement { ...@@ -612,9 +589,6 @@ class ExpressionStatement: public Statement {
virtual bool IsInlineable() const; virtual bool IsInlineable() const;
virtual Assignment* StatementAsSimpleAssignment();
virtual CountOperation* StatementAsCountOperation();
void set_expression(Expression* e) { expression_ = e; } void set_expression(Expression* e) { expression_ = e; }
Expression* expression() const { return expression_; } Expression* expression() const { return expression_; }
...@@ -895,11 +869,6 @@ class Literal: public Expression { ...@@ -895,11 +869,6 @@ class Literal: public Expression {
DECLARE_NODE_TYPE(Literal) 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. // Check if this literal is identical to the other literal.
bool IsIdenticalTo(const Literal* other) const { bool IsIdenticalTo(const Literal* other) const {
return handle_.is_identical_to(other->handle_); return handle_.is_identical_to(other->handle_);
...@@ -1114,12 +1083,6 @@ class VariableProxy: public Expression { ...@@ -1114,12 +1083,6 @@ class VariableProxy: public Expression {
return var_ == NULL ? true : var_->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; virtual bool IsInlineable() const;
bool IsVariable(Handle<String> n) { bool IsVariable(Handle<String> n) {
...@@ -1187,7 +1150,7 @@ class Property: public Expression { ...@@ -1187,7 +1150,7 @@ class Property: public Expression {
void RecordTypeFeedback(TypeFeedbackOracle* oracle); void RecordTypeFeedback(TypeFeedbackOracle* oracle);
virtual bool IsMonomorphic() { return is_monomorphic_; } virtual bool IsMonomorphic() { return is_monomorphic_; }
virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
virtual bool IsArrayLength() { return is_array_length_; } bool IsArrayLength() { return is_array_length_; }
private: private:
Expression* obj_; Expression* obj_;
......
...@@ -4368,7 +4368,7 @@ void HGraphBuilder::VisitProperty(Property* expr) { ...@@ -4368,7 +4368,7 @@ void HGraphBuilder::VisitProperty(Property* expr) {
CHECK_ALIVE(VisitForValue(expr->obj())); CHECK_ALIVE(VisitForValue(expr->obj()));
HInstruction* instr = NULL; HInstruction* instr = NULL;
if (expr->IsArrayLength()) { if (expr->AsProperty()->IsArrayLength()) {
HValue* array = Pop(); HValue* array = Pop();
AddInstruction(new(zone()) HCheckNonSmi(array)); AddInstruction(new(zone()) HCheckNonSmi(array));
HInstruction* mapcheck = HInstruction* mapcheck =
......
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