Bug 1459845 - Part 6: Make IfThenElseEmitter::State debug only. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Thu, 31 May 2018 15:15:50 +0900
changeset 474887 0710b2d9b60efc8459449111bc2b511a83da50df
parent 474886 901ab55af4f3c894f658a79ef25f1bf54654ee18
child 474888 0ad0b4d1b0f34ca4a8059b2f814be317ea5865d5
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1459845
milestone62.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 1459845 - Part 6: Make IfThenElseEmitter::State debug only. r=Yoric
js/src/frontend/BytecodeEmitter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -1983,17 +1983,16 @@ class MOZ_STACK_CLASS IfThenElseEmitter
     // Also used for assertion to make sure then and else blocks pushed the
     // same number of values.
     int32_t thenDepth_;
 
 #ifdef DEBUG
     // The number of values pushed in the then and else blocks.
     int32_t pushed_;
     bool calculatedPushed_;
-#endif
 
     // The state of this emitter.
     //
     // +-------+   emitCond +------+ emitElse +------+        emitEnd +-----+
     // | Start |-+--------->| Cond |--------->| Else |------>+------->| End |
     // +-------+ |          +------+          +------+       ^        +-----+
     //           |                                           |
     //           v emitThen +------+                         |
@@ -2029,56 +2028,48 @@ class MOZ_STACK_CLASS IfThenElseEmitter
 
         // After calling emitElseIf.
         ElseIf,
 
         // After calling emitEnd.
         End
     };
     State state_;
+#endif
 
   public:
     explicit IfThenElseEmitter(BytecodeEmitter* bce)
       : bce_(bce),
-        thenDepth_(0),
+        thenDepth_(0)
 #ifdef DEBUG
-        pushed_(0),
-        calculatedPushed_(false),
+      , pushed_(0)
+      , calculatedPushed_(false)
+      , state_(State::Start)
 #endif
-        state_(State::Start)
     {}
 
     ~IfThenElseEmitter()
     {}
 
   private:
-    MOZ_MUST_USE bool emitIfInternal(State nextState, SrcNoteType type) {
-        MOZ_ASSERT_IF(state_ == State::Start,
-                      nextState == State::Then ||
-                      nextState == State::ThenElse ||
-                      nextState == State::Cond);
-        MOZ_ASSERT_IF(state_ == State::ElseIf,
-                      nextState == State::Then ||
-                      nextState == State::ThenElse);
-
+    MOZ_MUST_USE bool emitIfInternal(SrcNoteType type) {
         // Emit an annotated branch-if-false around the then part.
         if (!bce_->newSrcNote(type))
             return false;
         if (!bce_->emitJump(JSOP_IFEQ, &jumpAroundThen_))
             return false;
 
         // To restore stack depth in else part, save depth of the then part.
 #ifdef DEBUG
         // If DEBUG, this is also necessary to calculate |pushed_|.
         thenDepth_ = bce_->stackDepth;
 #else
-        if (nextState == State::ThenElse || nextState == State::Cond)
+        if (type == SRC_COND || type == SRC_IF_ELSE)
             thenDepth_ = bce_->stackDepth;
 #endif
-        state_ = nextState;
         return true;
     }
 
     void calculateOrCheckPushed() {
 #ifdef DEBUG
         if (!calculatedPushed_) {
             pushed_ = bce_->stackDepth - thenDepth_;
             calculatedPushed_ = true;
@@ -2086,79 +2077,118 @@ class MOZ_STACK_CLASS IfThenElseEmitter
             MOZ_ASSERT(pushed_ == bce_->stackDepth - thenDepth_);
         }
 #endif
     }
 
   public:
     MOZ_MUST_USE bool emitThen() {
         MOZ_ASSERT(state_ == State::Start || state_ == State::ElseIf);
-        return emitIfInternal(State::Then, SRC_IF);
+        if (!emitIfInternal(SRC_IF))
+            return false;
+
+#ifdef DEBUG
+        state_ = State::Then;
+#endif
+        return true;
     }
 
     MOZ_MUST_USE bool emitCond() {
         MOZ_ASSERT(state_ == State::Start);
-        return emitIfInternal(State::Cond, SRC_COND);
+        if (!emitIfInternal(SRC_COND))
+            return false;
+
+#ifdef DEBUG
+        state_ = State::Cond;
+#endif
+        return true;
     }
 
     MOZ_MUST_USE bool emitThenElse() {
         MOZ_ASSERT(state_ == State::Start || state_ == State::ElseIf);
-        return emitIfInternal(State::ThenElse, SRC_IF_ELSE);
-    }
-
-    MOZ_MUST_USE bool emitElse() {
-        MOZ_ASSERT(state_ == State::ThenElse || state_ == State::Cond);
-
+        if (!emitIfInternal(SRC_IF_ELSE))
+            return false;
+
+#ifdef DEBUG
+        state_ = State::ThenElse;
+#endif
+        return true;
+    }
+
+  private:
+    MOZ_MUST_USE bool emitElseInternal() {
         calculateOrCheckPushed();
 
         // 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 (!bce_->emitJump(JSOP_GOTO, &jumpsAroundElse_))
             return false;
 
         // Ensure the branch-if-false comes here, then emit the else.
         if (!bce_->emitJumpTargetAndPatch(jumpAroundThen_))
             return false;
 
+        // Clear jumpAroundThen_ offset, to tell emitEnd there was an else part.
+        jumpAroundThen_ = JumpList();
+
         // Restore stack depth of the then part.
         bce_->stackDepth = thenDepth_;
         state_ = State::Else;
         return true;
     }
 
+  public:
+    MOZ_MUST_USE bool emitElse() {
+        MOZ_ASSERT(state_ == State::ThenElse || state_ == State::Cond);
+
+        if (!emitElseInternal())
+            return false;
+
+#ifdef DEBUG
+        state_ = State::Else;
+#endif
+        return true;
+    }
+
     MOZ_MUST_USE bool emitElseIf() {
         MOZ_ASSERT(state_ == State::ThenElse);
 
-        if (!emitElse())
-            return false;
-
-        // Clear jumpAroundThen_ offset that points previous JSOP_IFEQ.
-        jumpAroundThen_ = JumpList();
+        if (!emitElseInternal())
+            return false;
+
+#ifdef DEBUG
         state_ = State::ElseIf;
-
+#endif
         return true;
     }
 
     MOZ_MUST_USE bool emitEnd() {
         MOZ_ASSERT(state_ == State::Then || state_ == State::Else);
+        // If there was an else part for the last branch, jumpAroundThen_ is
+        // already fixed up when emitting the else part.
+        MOZ_ASSERT_IF(state_ == State::Then, jumpAroundThen_.offset != -1);
+        MOZ_ASSERT_IF(state_ == State::Else, jumpAroundThen_.offset == -1);
 
         calculateOrCheckPushed();
 
-        if (state_ == State::Then) {
-            // No else part, fixup the branch-if-false to come here.
+        if (jumpAroundThen_.offset != -1) {
+            // No else part for the last branch, fixup the branch-if-false to
+            // come here.
             if (!bce_->emitJumpTargetAndPatch(jumpAroundThen_))
                 return false;
         }
 
         // Patch all the jumps around else parts.
         if (!bce_->emitJumpTargetAndPatch(jumpsAroundElse_))
             return false;
 
+#ifdef DEBUG
         state_ = State::End;
+#endif
         return true;
     }
 
 #ifdef DEBUG
     // Returns the number of values pushed onto the value stack inside
     // `then_block` and `else_block`.
     // Can be used in assertion after emitting if-then-else.
     int32_t pushed() const {