Bug 704369: Move conditional expr emit. (r=Waldo)
authorChris Leary <cdleary@mozilla.com>
Tue, 22 Nov 2011 11:45:30 -0800
changeset 83749 2cd6087dbca3801fd2be5bf43499569a86c85564
parent 83748 ddd7fd60d1fcca5da728f50023c3fd758168d8be
child 83750 e5963f5906f7c0e270b1b52744af8251c5f207d8
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs704369
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 704369: Move conditional expr emit. (r=Waldo)
js/src/frontend/BytecodeEmitter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -6641,20 +6641,61 @@ EmitSyntheticStatements(JSContext *cx, B
     PushStatement(bce, &stmtInfo, STMT_SEQ, top);
     for (ParseNode *pn2 = pn->pn_head; pn2; pn2 = pn2->pn_next) {
         if (!EmitTree(cx, bce, pn2))
             return false;
     }
     return PopStatementBCE(cx, bce);
 }
 
+static bool
+EmitConditionalExpression(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
+{
+    /* Emit the condition, then branch if false to the else part. */
+    if (!EmitTree(cx, bce, pn->pn_kid1))
+        return JS_FALSE;
+    ptrdiff_t noteIndex = NewSrcNote(cx, bce, SRC_COND);
+    if (noteIndex < 0)
+        return JS_FALSE;
+    ptrdiff_t beq = EmitJump(cx, bce, JSOP_IFEQ, 0);
+    if (beq < 0 || !EmitTree(cx, bce, pn->pn_kid2))
+        return JS_FALSE;
+
+    /* Jump around else, fixup the branch, emit else, fixup jump. */
+    ptrdiff_t jmp = EmitJump(cx, bce, JSOP_GOTO, 0);
+    if (jmp < 0)
+        return JS_FALSE;
+    CHECK_AND_SET_JUMP_OFFSET_AT(cx, bce, beq);
+
+    /*
+     * Because each branch pushes a single value, but our stack budgeting
+     * analysis ignores branches, we now have to adjust bce->stackDepth to
+     * ignore the value pushed by the first branch.  Execution will follow
+     * only one path, so we must decrement bce->stackDepth.
+     *
+     * Failing to do this will foil code, such as the try/catch/finally
+     * exception handling code generator, that samples bce->stackDepth for
+     * use at runtime (JSOP_SETSP), or in let expression and block code
+     * generation, which must use the stack depth to compute local stack
+     * indexes correctly.
+     */
+    JS_ASSERT(bce->stackDepth > 0);
+    bce->stackDepth--;
+    if (!EmitTree(cx, bce, pn->pn_kid3))
+        return JS_FALSE;
+    CHECK_AND_SET_JUMP_OFFSET_AT(cx, bce, jmp);
+    if (!SetSrcNoteOffset(cx, bce, noteIndex, 0, jmp - beq))
+        return JS_FALSE;
+    return true;
+}
+
 JSBool
 frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
 {
-    ptrdiff_t top, off, tmp, beq, jmp;
+    ptrdiff_t top, off, tmp, jmp;
     ParseNode *pn2, *pn3;
     JSAtom *atom;
     jsatomid atomIndex;
     ptrdiff_t noteIndex;
     jsbytecode *pc;
     JSOp op;
     EmitLevelManager elm(bce);
     jsint sharpnum = -1;
@@ -6830,51 +6871,17 @@ frontend::EmitTree(JSContext *cx, Byteco
       case PNK_MULASSIGN:
       case PNK_DIVASSIGN:
       case PNK_MODASSIGN:
         if (!EmitAssignment(cx, bce, pn->pn_left, pn->getOp(), pn->pn_right))
             return false;
         break;
 
       case PNK_HOOK:
-        /* Emit the condition, then branch if false to the else part. */
-        if (!EmitTree(cx, bce, pn->pn_kid1))
-            return JS_FALSE;
-        noteIndex = NewSrcNote(cx, bce, SRC_COND);
-        if (noteIndex < 0)
-            return JS_FALSE;
-        beq = EmitJump(cx, bce, JSOP_IFEQ, 0);
-        if (beq < 0 || !EmitTree(cx, bce, pn->pn_kid2))
-            return JS_FALSE;
-
-        /* Jump around else, fixup the branch, emit else, fixup jump. */
-        jmp = EmitJump(cx, bce, JSOP_GOTO, 0);
-        if (jmp < 0)
-            return JS_FALSE;
-        CHECK_AND_SET_JUMP_OFFSET_AT(cx, bce, beq);
-
-        /*
-         * Because each branch pushes a single value, but our stack budgeting
-         * analysis ignores branches, we now have to adjust bce->stackDepth to
-         * ignore the value pushed by the first branch.  Execution will follow
-         * only one path, so we must decrement bce->stackDepth.
-         *
-         * Failing to do this will foil code, such as the try/catch/finally
-         * exception handling code generator, that samples bce->stackDepth for
-         * use at runtime (JSOP_SETSP), or in let expression and block code
-         * generation, which must use the stack depth to compute local stack
-         * indexes correctly.
-         */
-        JS_ASSERT(bce->stackDepth > 0);
-        bce->stackDepth--;
-        if (!EmitTree(cx, bce, pn->pn_kid3))
-            return JS_FALSE;
-        CHECK_AND_SET_JUMP_OFFSET_AT(cx, bce, jmp);
-        if (!SetSrcNoteOffset(cx, bce, noteIndex, 0, jmp - beq))
-            return JS_FALSE;
+        ok = EmitConditionalExpression(cx, bce, pn);
         break;
 
       case PNK_OR:
       case PNK_AND:
         ok = EmitLogical(cx, bce, pn);
         break;
 
       case PNK_ADD: