Bug 1308383 - Part 1: Cleanup BytecodeEmitter::emitIf. r=shu
authorTooru Fujisawa <arai_a@mac.com>
Tue, 01 Nov 2016 16:53:49 +0900
changeset 347245 b419577e090926d77b7ccc670a12af662e10c80b
parent 347244 c721e1f2ca20da5ab3089c1903ad97c20e4dd1f6
child 347246 25fe60b5746b4a6ab6bcdea940c1520980915d36
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1308383
milestone52.0a1
Bug 1308383 - Part 1: Cleanup BytecodeEmitter::emitIf. r=shu
js/src/frontend/BytecodeEmitter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -4622,16 +4622,18 @@ BytecodeEmitter::emitDestructuringOpsArr
                     return false;
                 if (!emitConditionallyExecutedDestructuringLHS(member, flav)) // ... OBJ?
                     return false;
 
                 if (!emitJump(JSOP_GOTO, &end))
                     return false;
                 if (!emitJumpTargetAndPatch(beq))
                     return false;
+                if (!setSrcNoteOffset(noteIndex, 0, end.offset - beq.offset))
+                    return false;
                 stackDepth = depth;
             }
 
             // If iterator is not completed, create a new array with the rest
             // of the iterator.
             if (!emitUint32Operand(JSOP_NEWARRAY, 0))             // ... OBJ? ITER ARRAY
                 return false;
             if (!emitNumberOp(0))                                 // ... OBJ? ITER ARRAY INDEX
@@ -4641,18 +4643,16 @@ BytecodeEmitter::emitDestructuringOpsArr
             if (!emit1(JSOP_POP))                                 // ... OBJ? ARRAY
                 return false;
             if (!emitConditionallyExecutedDestructuringLHS(member, flav)) // ... OBJ?
                 return false;
 
             if (!isHead) {
                 if (!emitJumpTargetAndPatch(end))
                     return false;
-                if (!setSrcNoteOffset(noteIndex, 0, end.offset - beq.offset))
-                    return false;
             }
             needToPopIterator = false;
             MOZ_ASSERT(!member->pn_next);
             break;
         }
 
         ParseNode* pndefault = nullptr;
         ParseNode* subpattern = member;
@@ -4728,16 +4728,18 @@ BytecodeEmitter::emitDestructuringOpsArr
                 return false;
         }
 
         JumpList end;
         if (!emitJump(JSOP_GOTO, &end))
             return false;
         if (!emitJumpTargetAndPatch(beq))
             return false;
+        if (!setSrcNoteOffset(noteIndex, 0, end.offset - beq.offset))
+            return false;
 
         stackDepth = depth;
         if (!emitAtomOp(cx->names().value, JSOP_GETPROP))         // ... OBJ? ITER VALUE
             return false;
 
         if (pndefault) {
             if (!emitDefault(pndefault))                          // ... OBJ? ITER VALUE
                 return false;
@@ -4757,18 +4759,16 @@ BytecodeEmitter::emitDestructuringOpsArr
                 return false;
         } else if (hasNextSpread) {
             if (!emit1(JSOP_FALSE))                               // ... OBJ? ITER DONE?
                 return false;
         }
 
         if (!emitJumpTargetAndPatch(end))
             return false;
-        if (!setSrcNoteOffset(noteIndex, 0, end.offset - beq.offset))
-            return false;
     }
 
     if (needToPopIterator) {
         if (!emit1(JSOP_POP))                                     // ... OBJ?
             return false;
     }
 
     return true;
@@ -5642,95 +5642,74 @@ BytecodeEmitter::emitTry(ParseNode* pn)
         return false;
 
     return true;
 }
 
 bool
 BytecodeEmitter::emitIf(ParseNode* pn)
 {
-    /* Initialize so we can detect else-if chains and avoid recursion. */
-    bool emittingElse = false;
-
     JumpList jumpsAroundElse;
     JumpList beq;
-    JumpList jmp; // else-if chains
     unsigned noteIndex = -1;
 
   if_again:
     /* Emit code for the condition before pushing stmtInfo. */
     if (!emitConditionallyExecutedTree(pn->pn_kid1))
         return false;
 
-    if (emittingElse) {
-        /*
-         * We came here from the goto further below that detects else-if
-         * chains, so we must mutate stmtInfo back into a StmtType::IF record.
-         * Also we need a note offset for SRC_IF_ELSE to help IonMonkey.
-         */
-        emittingElse = false;
-        if (!setSrcNoteOffset(noteIndex, 0, jmp.offset - beq.offset))
-            return false;
-    }
-
     /* Emit an annotated branch-if-false around the then part. */
     ParseNode* pn3 = pn->pn_kid3;
     if (!newSrcNote(pn3 ? SRC_IF_ELSE : SRC_IF, &noteIndex))
         return false;
     beq = JumpList();
     if (!emitJump(JSOP_IFEQ, &beq))
         return false;
 
     /* Emit code for the then and optional else parts. */
     if (!emitConditionallyExecutedTree(pn->pn_kid2))
         return false;
 
     if (pn3) {
-        emittingElse = true;
-
         /*
          * Emit a jump from the end of our then part around the else part. The
          * patchJumpsToTarget call at the bottom of this function will fix up
          * the offset with jumpsAroundElse value.
          */
         if (!emitJump(JSOP_GOTO, &jumpsAroundElse))
             return false;
-        jmp = jumpsAroundElse;
 
         /* Ensure the branch-if-false comes here, then emit the else. */
         if (!emitJumpTargetAndPatch(beq))
             return false;
+        /*
+         * Annotate SRC_IF_ELSE with the offset from branch to jump, for
+         * IonMonkey's benefit.  We can't just "back up" from the pc
+         * of the else clause, because we don't know whether an extended
+         * jump was required to leap from the end of the then clause over
+         * the else clause.
+         */
+        if (!setSrcNoteOffset(noteIndex, 0, jumpsAroundElse.offset - beq.offset))
+            return false;
         if (pn3->isKind(PNK_IF)) {
             pn = pn3;
             goto if_again;
         }
 
         if (!emitConditionallyExecutedTree(pn3))
             return false;
-
-        /*
-         * Annotate SRC_IF_ELSE with the offset from branch to jump, for
-         * IonMonkey's benefit.  We can't just "back up" from the pc
-         * of the else clause, because we don't know whether an extended
-         * jump was required to leap from the end of the then clause over
-         * the else clause.
-         */
-        if (!setSrcNoteOffset(noteIndex, 0, jmp.offset - beq.offset))
-            return false;
     } else {
         /* No else part, fixup the branch-if-false to come here. */
         if (!emitJumpTargetAndPatch(beq))
             return false;
     }
 
     // Patch all the jumps around else parts.
-    JumpTarget here;
-    if (!emitJumpTarget(&here))
-        return false;
-    patchJumpsToTarget(jumpsAroundElse, here);
+    if (!emitJumpTargetAndPatch(jumpsAroundElse))
+        return false;
 
     return true;
 }
 
 bool
 BytecodeEmitter::emitHoistedFunctionsInList(ParseNode* list)
 {
     MOZ_ASSERT(list->pn_xflags & PNX_FUNCDEFS);