Skip to content
Permalink
Browse files
2010-07-22 Oliver Hunt <oliver@apple.com>
        Reviewed by Gavin Barraclough.

        Do more constant folding
        https://bugs.webkit.org/show_bug.cgi?id=42867

        Constant fold a few more operations.  SunSpider says this is
        a win but I suspect that's just code motion at play.

        * parser/ASTBuilder.h:
        (JSC::ASTBuilder::makeModNode):
        (JSC::ASTBuilder::makeURightShiftNode):
        (JSC::ASTBuilder::makeBitOrNode):
        (JSC::ASTBuilder::makeBitAndNode):
        (JSC::ASTBuilder::makeBitXOrNode):
        (JSC::ASTBuilder::makeBinaryNode):

Canonical link: https://commits.webkit.org/54779@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@63946 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ojhunt committed Jul 23, 2010
1 parent bb4b656 commit b3d0418cff2db04e3fadc3c64502641e78984cef
Showing with 66 additions and 5 deletions.
  1. +18 −0 JavaScriptCore/ChangeLog
  2. +48 −5 JavaScriptCore/parser/ASTBuilder.h
@@ -1,3 +1,21 @@
2010-07-22 Oliver Hunt <oliver@apple.com>

Reviewed by Gavin Barraclough.

Do more constant folding
https://bugs.webkit.org/show_bug.cgi?id=42867

Constant fold a few more operations. SunSpider says this is
a win but I suspect that's just code motion at play.

* parser/ASTBuilder.h:
(JSC::ASTBuilder::makeModNode):
(JSC::ASTBuilder::makeURightShiftNode):
(JSC::ASTBuilder::makeBitOrNode):
(JSC::ASTBuilder::makeBitAndNode):
(JSC::ASTBuilder::makeBitXOrNode):
(JSC::ASTBuilder::makeBinaryNode):

2010-07-22 Kent Hansen <kent.hansen@nokia.com>

Reviewed by Kent Tamura.
@@ -124,10 +124,15 @@ class ASTBuilder {
ExpressionNode* makeBitwiseNotNode(ExpressionNode*);
ExpressionNode* makeMultNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeDivNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeModNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeAddNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeSubNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeBitXOrNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeBitAndNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeBitOrNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeLeftShiftNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeRightShiftNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);
ExpressionNode* makeURightShiftNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments);

ExpressionNode* createLogicalNot(ExpressionNode* expr) { return new (m_globalData) LogicalNotNode(m_globalData, expr); }
ExpressionNode* createUnaryPlus(ExpressionNode* expr) { return new (m_globalData) UnaryPlusNode(m_globalData, expr); }
@@ -690,6 +695,16 @@ ExpressionNode* ASTBuilder::makeDivNode(ExpressionNode* expr1, ExpressionNode* e
return new (m_globalData) DivNode(m_globalData, expr1, expr2, rightHasAssignments);
}

ExpressionNode* ASTBuilder::makeModNode(ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
{
expr1 = expr1->stripUnaryPlus();
expr2 = expr2->stripUnaryPlus();

if (expr1->isNumber() && expr2->isNumber())
return createNumber(fmod(static_cast<NumberNode*>(expr1)->value(), static_cast<NumberNode*>(expr2)->value()));
return new (m_globalData) ModNode(m_globalData, expr1, expr2, rightHasAssignments);
}

ExpressionNode* ASTBuilder::makeAddNode(ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
{
if (expr1->isNumber() && expr2->isNumber())
@@ -721,6 +736,34 @@ ExpressionNode* ASTBuilder::makeRightShiftNode(ExpressionNode* expr1, Expression
return new (m_globalData) RightShiftNode(m_globalData, expr1, expr2, rightHasAssignments);
}

ExpressionNode* ASTBuilder::makeURightShiftNode(ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
{
if (expr1->isNumber() && expr2->isNumber())
return createNumber(toUInt32(static_cast<NumberNode*>(expr1)->value()) >> (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f));
return new (m_globalData) UnsignedRightShiftNode(m_globalData, expr1, expr2, rightHasAssignments);
}

ExpressionNode* ASTBuilder::makeBitOrNode(ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
{
if (expr1->isNumber() && expr2->isNumber())
return createNumber(toInt32(static_cast<NumberNode*>(expr1)->value()) | toInt32(static_cast<NumberNode*>(expr2)->value()));
return new (m_globalData) BitOrNode(m_globalData, expr1, expr2, rightHasAssignments);
}

ExpressionNode* ASTBuilder::makeBitAndNode(ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
{
if (expr1->isNumber() && expr2->isNumber())
return createNumber(toInt32(static_cast<NumberNode*>(expr1)->value()) & toInt32(static_cast<NumberNode*>(expr2)->value()));
return new (m_globalData) BitAndNode(m_globalData, expr1, expr2, rightHasAssignments);
}

ExpressionNode* ASTBuilder::makeBitXOrNode(ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
{
if (expr1->isNumber() && expr2->isNumber())
return createNumber(toInt32(static_cast<NumberNode*>(expr1)->value()) ^ toInt32(static_cast<NumberNode*>(expr2)->value()));
return new (m_globalData) BitXOrNode(m_globalData, expr1, expr2, rightHasAssignments);
}

ExpressionNode* ASTBuilder::makeFunctionCallNode(ExpressionNode* func, ArgumentsNode* args, int start, int divot, int end)
{
if (!func->isLocation())
@@ -763,13 +806,13 @@ ExpressionNode* ASTBuilder::makeBinaryNode(int token, pair<ExpressionNode*, Bina
return new (m_globalData) LogicalOpNode(m_globalData, lhs.first, rhs.first, OpLogicalAnd);

case BITOR:
return new (m_globalData) BitOrNode(m_globalData, lhs.first, rhs.first, rhs.second.hasAssignment);
return makeBitOrNode(lhs.first, rhs.first, rhs.second.hasAssignment);

case BITXOR:
return new (m_globalData) BitXOrNode(m_globalData, lhs.first, rhs.first, rhs.second.hasAssignment);
return makeBitXOrNode(lhs.first, rhs.first, rhs.second.hasAssignment);

case BITAND:
return new (m_globalData) BitAndNode(m_globalData, lhs.first, rhs.first, rhs.second.hasAssignment);
return makeBitAndNode(lhs.first, rhs.first, rhs.second.hasAssignment);

case EQEQ:
return new (m_globalData) EqualNode(m_globalData, lhs.first, rhs.first, rhs.second.hasAssignment);
@@ -814,7 +857,7 @@ ExpressionNode* ASTBuilder::makeBinaryNode(int token, pair<ExpressionNode*, Bina
return makeRightShiftNode(lhs.first, rhs.first, rhs.second.hasAssignment);

case URSHIFT:
return new (m_globalData) UnsignedRightShiftNode(m_globalData, lhs.first, rhs.first, rhs.second.hasAssignment);
return makeURightShiftNode(lhs.first, rhs.first, rhs.second.hasAssignment);

case PLUS:
return makeAddNode(lhs.first, rhs.first, rhs.second.hasAssignment);
@@ -829,7 +872,7 @@ ExpressionNode* ASTBuilder::makeBinaryNode(int token, pair<ExpressionNode*, Bina
return makeDivNode(lhs.first, rhs.first, rhs.second.hasAssignment);

case MOD:
return new (m_globalData) ModNode(m_globalData, lhs.first, rhs.first, rhs.second.hasAssignment);
return makeModNode(lhs.first, rhs.first, rhs.second.hasAssignment);
}
CRASH();
return 0;

0 comments on commit b3d0418

Please sign in to comment.