2008-06-14 Cameron Zwarich <cwzwarich@uwaterloo.ca>
authorcwzwarich@webkit.org <cwzwarich@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Jun 2008 07:52:27 +0000 (07:52 +0000)
committercwzwarich@webkit.org <cwzwarich@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Jun 2008 07:52:27 +0000 (07:52 +0000)
        Reviewed by Oliver.

        Bug 19484: More instructions needs to use temporary registers
        <https://bugs.webkit.org/show_bug.cgi?id=19484>

        Make code generation for AddNode and SubNode use temporaries when
        necessary.

        JavaScriptCore:

        * kjs/grammar.y:
        * kjs/nodes.cpp:
        (KJS::AddNode::emitCode):
        (KJS::SubNode::emitCode):
        * kjs/nodes.h:
        (KJS::AddNode::):
        (KJS::SubNode::):

        LayoutTests:

        * fast/js/codegen-temporaries-expected.txt:
        * fast/js/resources/codegen-temporaries.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@34535 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/grammar.y
JavaScriptCore/kjs/nodes.cpp
JavaScriptCore/kjs/nodes.h
LayoutTests/ChangeLog
LayoutTests/fast/js/codegen-temporaries-expected.txt
LayoutTests/fast/js/resources/codegen-temporaries.js

index f861b2276420a75d65f4f02972370ea052c6fbcf..18bc53bd7bb623980f1800ae3f8ac331afd18ca5 100644 (file)
@@ -1,3 +1,21 @@
+2008-06-14  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
+
+        Reviewed by Oliver.
+
+        Bug 19484: More instructions needs to use temporary registers
+        <https://bugs.webkit.org/show_bug.cgi?id=19484>
+
+        Make code generation for AddNode and SubNode use temporaries when
+        necessary.
+
+        * kjs/grammar.y:
+        * kjs/nodes.cpp:
+        (KJS::AddNode::emitCode):
+        (KJS::SubNode::emitCode):
+        * kjs/nodes.h:
+        (KJS::AddNode::):
+        (KJS::SubNode::):
+
 2008-06-13  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
 
         Reviewed by Maciej.
index 0020d6a85e6a175edcbf5a119b26101fc02a87cd..3fab0d2a226e7be778643b10f831601894889821 100644 (file)
@@ -63,7 +63,7 @@ static inline bool allowAutomaticSemicolon(KJS::Lexer&, int);
 using namespace KJS;
 using namespace std;
 
-static AddNode* makeAddNode(ExpressionNode*, ExpressionNode*);
+static AddNode* makeAddNode(ExpressionNode*, ExpressionNode*, bool rightHasAssignments);
 static LessNode* makeLessNode(ExpressionNode*, ExpressionNode*);
 static ExpressionNode* makeAssignNode(ExpressionNode* loc, Operator, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments);
 static ExpressionNode* makePrefixNode(ExpressionNode* expr, Operator);
@@ -477,16 +477,16 @@ MultiplicativeExprNoBF:
 
 AdditiveExpr:
     MultiplicativeExpr
-  | AdditiveExpr '+' MultiplicativeExpr { $$ = createNodeFeatureInfo<ExpressionNode*>(makeAddNode($1.m_node, $3.m_node), $1.m_featureInfo | $3.m_featureInfo); }
-  | AdditiveExpr '-' MultiplicativeExpr { $$ = createNodeFeatureInfo<ExpressionNode*>(new SubNode($1.m_node, $3.m_node), $1.m_featureInfo | $3.m_featureInfo); }
+  | AdditiveExpr '+' MultiplicativeExpr { $$ = createNodeFeatureInfo<ExpressionNode*>(makeAddNode($1.m_node, $3.m_node, $3.m_featureInfo & AssignFeature), $1.m_featureInfo | $3.m_featureInfo); }
+  | AdditiveExpr '-' MultiplicativeExpr { $$ = createNodeFeatureInfo<ExpressionNode*>(new SubNode($1.m_node, $3.m_node, $3.m_featureInfo & AssignFeature), $1.m_featureInfo | $3.m_featureInfo); }
 ;
 
 AdditiveExprNoBF:
     MultiplicativeExprNoBF
   | AdditiveExprNoBF '+' MultiplicativeExpr
-                                        { $$ = createNodeFeatureInfo<ExpressionNode*>(makeAddNode($1.m_node, $3.m_node), $1.m_featureInfo | $3.m_featureInfo); }
+                                        { $$ = createNodeFeatureInfo<ExpressionNode*>(makeAddNode($1.m_node, $3.m_node, $3.m_featureInfo & AssignFeature), $1.m_featureInfo | $3.m_featureInfo); }
   | AdditiveExprNoBF '-' MultiplicativeExpr
-                                        { $$ = createNodeFeatureInfo<ExpressionNode*>(new SubNode($1.m_node, $3.m_node), $1.m_featureInfo | $3.m_featureInfo); }
+                                        { $$ = createNodeFeatureInfo<ExpressionNode*>(new SubNode($1.m_node, $3.m_node, $3.m_featureInfo & AssignFeature), $1.m_featureInfo | $3.m_featureInfo); }
 ;
 
 ShiftExpr:
@@ -1094,9 +1094,9 @@ SourceElement:
  
 %%
 
-static AddNode* makeAddNode(ExpressionNode* left, ExpressionNode* right)
+static AddNode* makeAddNode(ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments)
 {
-    return new AddNode(left, right);
+    return new AddNode(left, right, rightHasAssignments);
 }
 
 static LessNode* makeLessNode(ExpressionNode* left, ExpressionNode* right)
index 585d8d5ba28a77abf23db9524452f479c191b467..950e99d4f57ba05e27312cef87aab87b43001eae 100644 (file)
@@ -823,14 +823,14 @@ RegisterID* ModNode::emitCode(CodeGenerator& generator, RegisterID* dst)
 
 RegisterID* AddNode::emitCode(CodeGenerator& generator, RegisterID* dst)
 {
-    RefPtr<RegisterID> src1 = generator.emitNode(m_term1.get());
+    RefPtr<RegisterID> src1 = generator.emitNodeForLeftHandSide(m_term1.get(), m_rightHasAssignments, m_term2.get()->isConstant());
     RegisterID* src2 = generator.emitNode(m_term2.get());
     return generator.emitAdd(generator.finalDestination(dst, src1.get()), src1.get(), src2);
 }
 
 RegisterID* SubNode::emitCode(CodeGenerator& generator, RegisterID* dst)
 {
-    RefPtr<RegisterID> src1 = generator.emitNode(m_term1.get());
+    RefPtr<RegisterID> src1 = generator.emitNodeForLeftHandSide(m_term1.get(), m_rightHasAssignments, m_term2.get()->isConstant());
     RegisterID* src2 = generator.emitNode(m_term2.get());
     return generator.emitSub(generator.finalDestination(dst, src1.get()), src1.get(), src2);
 }
index 27a63a2d17f1cd08e97a2714cec707384f650ed0..424a1a40db87c4f0ff269fe47b85d7d4424531e8 100644 (file)
@@ -1250,9 +1250,10 @@ namespace KJS {
 
     class AddNode : public ExpressionNode {
     public:
-        AddNode(ExpressionNode* term1, ExpressionNode* term2) KJS_FAST_CALL
+        AddNode(ExpressionNode* term1, ExpressionNode* term2, bool rightHasAssignments) KJS_FAST_CALL
             : m_term1(term1)
             , m_term2(term2)
+            , m_rightHasAssignments(rightHasAssignments)
         {
         }
 
@@ -1261,23 +1262,26 @@ namespace KJS {
         virtual Precedence precedence() const { return PrecAdditive; }
 
     protected:
-        AddNode(ExpressionNode* term1, ExpressionNode* term2, JSType expectedReturn) KJS_FAST_CALL
+        AddNode(ExpressionNode* term1, ExpressionNode* term2, JSType expectedReturn, bool rightHasAssignments) KJS_FAST_CALL
             : ExpressionNode(expectedReturn)
             , m_term1(term1)
             , m_term2(term2)
+            , m_rightHasAssignments(rightHasAssignments)
         {
         }
 
         RefPtr<ExpressionNode> m_term1;
         RefPtr<ExpressionNode> m_term2;
+        bool m_rightHasAssignments;
     };
 
     class SubNode : public ExpressionNode {
     public:
-        SubNode(ExpressionNode* term1, ExpressionNode* term2) KJS_FAST_CALL
+        SubNode(ExpressionNode* term1, ExpressionNode* term2, bool rightHasAssignments) KJS_FAST_CALL
             : ExpressionNode(NumberType)
             , m_term1(term1)
             , m_term2(term2)
+            , m_rightHasAssignments(rightHasAssignments)
         {
         }
 
@@ -1288,6 +1292,7 @@ namespace KJS {
     private:
         RefPtr<ExpressionNode> m_term1;
         RefPtr<ExpressionNode> m_term2;
+        bool m_rightHasAssignments;
     };
 
     class LeftShiftNode : public ExpressionNode {
index 6196f09424d9010a9d4d2a5e507bb9e199dfdac2..cd30a69c018d46ef5af0e688638a3e03f2a16dc6 100644 (file)
@@ -1,3 +1,15 @@
+2008-06-14  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
+
+        Reviewed by Oliver.
+
+        Tests for:
+
+        Bug 19484: More instructions needs to use temporary registers
+        <https://bugs.webkit.org/show_bug.cgi?id=19484>
+
+        * fast/js/codegen-temporaries-expected.txt:
+        * fast/js/resources/codegen-temporaries.js:
+
 2008-06-13  Adam Barth  <abarth@webkit.org>
 
         Reviewed by Eric Seidel.
index 01b0c6fd975c94d4d23320b6707fa265905473d8..3cc82eba8a6c9feb5c0d5b15b9aaf83a34843d6c 100644 (file)
@@ -42,6 +42,12 @@ PASS bracket_test3() is 0
 PASS bracket_test4() is 0
 PASS bracket_test5() is 1
 PASS bracket_test6() is 1
+PASS add_test1() is 3
+PASS add_test2() is 3
+PASS add_test3() is 3
+PASS sub_test1() is -1
+PASS sub_test2() is -1
+PASS sub_test3() is -1
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 9b17df46050a763f0b8554d4fada17d870ad984e..d92e265aa2833409ea6ce8c1d5839085a8b5839a 100644 (file)
@@ -350,4 +350,52 @@ function bracket_test6()
 
 shouldBe("bracket_test6()", "1");
 
+function add_test1()
+{
+    var a = 1;
+    return a + (a = 2);
+}
+
+shouldBe("add_test1()", "3");
+
+function add_test2()
+{
+    var a = 1;
+    return a + ++a;
+}
+
+shouldBe("add_test2()", "3");
+
+function add_test3()
+{
+    var a = 1;
+    return a + (a += 1);
+}
+
+shouldBe("add_test3()", "3");
+
+function sub_test1()
+{
+    var a = 1;
+    return a - (a = 2);
+}
+
+shouldBe("sub_test1()", "-1");
+
+function sub_test2()
+{
+    var a = 1;
+    return a - ++a;
+}
+
+shouldBe("sub_test2()", "-1");
+
+function sub_test3()
+{
+    var a = 1;
+    return a - (a += 1);
+}
+
+shouldBe("sub_test3()", "-1");
+
 successfullyParsed = true;