Bug 1253137 - Baldr: add nop placeholder for branch values (r=sunfish)
authorLuke Wagner <luke@mozilla.com>
Mon, 07 Mar 2016 16:02:28 -0600
changeset 287262 970c0c8816a539d82ccaefef942000ce2d335d8c
parent 287261 d70b4f3b167c98407cc0369ccbd1a01a42acd561
child 287263 ca09c67724cb78b6d07122b5b37875fc982876b2
push id73136
push userlwagner@mozilla.com
push dateTue, 08 Mar 2016 19:48:22 +0000
treeherdermozilla-inbound@bf186476cb90 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssunfish
bugs1253137
milestone47.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 1253137 - Baldr: add nop placeholder for branch values (r=sunfish) MozReview-Commit-ID: 8r3gtn8yoOS
js/src/asmjs/AsmJS.cpp
js/src/asmjs/Wasm.cpp
js/src/asmjs/WasmIonCompile.cpp
js/src/asmjs/WasmText.cpp
--- a/js/src/asmjs/AsmJS.cpp
+++ b/js/src/asmjs/AsmJS.cpp
@@ -2699,17 +2699,18 @@ class MOZ_STACK_CLASS FunctionValidator
     }
 
     /**************************************************************** Labels */
   private:
     bool writeBr(uint32_t absolute, Expr expr = Expr::Br) {
         MOZ_ASSERT(expr == Expr::Br || expr == Expr::BrIf);
         MOZ_ASSERT(absolute < blockDepth_);
         return encoder().writeExpr(expr) &&
-               encoder().writeVarU32(blockDepth_ - 1 - absolute);
+               encoder().writeVarU32(blockDepth_ - 1 - absolute) &&
+               encoder().writeExpr(Expr::Nop);
     }
     void removeLabel(PropertyName* label, LabelMap* map) {
         LabelMap::Ptr p = map->lookup(label);
         MOZ_ASSERT(p);
         map->remove(p);
     }
 
   public:
--- a/js/src/asmjs/Wasm.cpp
+++ b/js/src/asmjs/Wasm.cpp
@@ -504,47 +504,47 @@ DecodeStore(FunctionDecoder& f, ValType 
     if (!CheckType(f, actual, storeType))
         return false;
 
     *type = ToExprType(storeType);
     return true;
 }
 
 static bool
-DecodeBr(FunctionDecoder& f, ExprType* type)
+DecodeBranch(FunctionDecoder& f, Expr expr, ExprType* type)
 {
+    MOZ_ASSERT(expr == Expr::Br || expr == Expr::BrIf);
+
     uint32_t relativeDepth;
     if (!f.d().readVarU32(&relativeDepth))
         return f.fail("expected relative depth");
 
     if (!f.branchWithType(relativeDepth, ExprType::Void))
         return f.fail("branch depth exceeds current nesting level");
 
-    *type = AnyType;
-    return true;
-}
+    Expr value;
+    if (!f.d().readExpr(&value))
+        return f.fail("expected branch value");
 
-static bool
-DecodeBrIf(FunctionDecoder& f, ExprType* type)
-{
-    uint32_t relativeDepth;
-    if (!f.d().readVarU32(&relativeDepth))
-        return f.fail("expected relative depth");
+    if (value != Expr::Nop)
+        return f.fail("NYI: branch values");
 
-    if (!f.branchWithType(relativeDepth, ExprType::Void))
-        return f.fail("branch depth exceeds current nesting level");
+    if (expr == Expr::BrIf) {
+        ExprType actual;
+        if (!DecodeExpr(f, &actual))
+            return false;
 
-    ExprType actual;
-    if (!DecodeExpr(f, &actual))
-        return false;
+        if (!CheckType(f, actual, ValType::I32))
+            return false;
 
-    if (!CheckType(f, actual, ValType::I32))
-        return false;
+        *type = ExprType::Void;
+    } else {
+        *type = AnyType;
+    }
 
-    *type = ExprType::Void;
     return true;
 }
 
 static bool
 DecodeBrTable(FunctionDecoder& f, ExprType* type)
 {
     uint32_t tableLength;
     if (!f.d().readVarU32(&tableLength))
@@ -814,19 +814,19 @@ DecodeExpr(FunctionDecoder& f, ExprType*
       case Expr::I64Store32:
         return f.fail("NYI: i64") &&
                DecodeStore(f, ValType::I64, type);
       case Expr::F32Store:
         return DecodeStore(f, ValType::F32, type);
       case Expr::F64Store:
         return DecodeStore(f, ValType::F64, type);
       case Expr::Br:
-        return DecodeBr(f, type);
+        return DecodeBranch(f, expr, type);
       case Expr::BrIf:
-        return DecodeBrIf(f, type);
+        return DecodeBranch(f, expr, type);
       case Expr::BrTable:
         return DecodeBrTable(f, type);
       case Expr::Return:
         return DecodeReturn(f, type);
       default:
         // Note: it's important not to remove this default since readExpr()
         // can return Expr values for which there is no enumerator.
         break;
--- a/js/src/asmjs/WasmIonCompile.cpp
+++ b/js/src/asmjs/WasmIonCompile.cpp
@@ -2636,38 +2636,35 @@ EmitBlock(FunctionCompiler& f, MDefiniti
             return false;
     } else {
         *def = nullptr;
     }
     return f.finishBlock();
 }
 
 static bool
-EmitBr(FunctionCompiler& f, MDefinition** def)
+EmitBranch(FunctionCompiler& f, Expr op, MDefinition** def)
 {
+    MOZ_ASSERT(op == Expr::Br || op == Expr::BrIf);
+
     uint32_t relativeDepth = f.readVarU32();
 
-    if (!f.br(relativeDepth))
-        return false;
-
-    *def = nullptr;
-    return true;
-}
-
-static bool
-EmitBrIf(FunctionCompiler& f, MDefinition** def)
-{
-    uint32_t relativeDepth = f.readVarU32();
-
-    MDefinition* condition;
-    if (!EmitExpr(f, &condition))
-        return false;
-
-    if (!f.brIf(relativeDepth, condition))
-        return false;
+    MOZ_ALWAYS_TRUE(f.readExpr() == Expr::Nop);
+
+    if (op == Expr::Br) {
+        if (!f.br(relativeDepth))
+            return false;
+    } else {
+        MDefinition* condition;
+        if (!EmitExpr(f, &condition))
+            return false;
+
+        if (!f.brIf(relativeDepth, condition))
+            return false;
+    }
 
     *def = nullptr;
     return true;
 }
 
 static bool
 EmitExpr(FunctionCompiler& f, MDefinition** def)
 {
@@ -2686,19 +2683,18 @@ EmitExpr(FunctionCompiler& f, MDefinitio
       case Expr::Block:
         return EmitBlock(f, def);
       case Expr::If:
       case Expr::IfElse:
         return EmitIfElse(f, op, def);
       case Expr::Loop:
         return EmitLoop(f, def);
       case Expr::Br:
-        return EmitBr(f, def);
       case Expr::BrIf:
-        return EmitBrIf(f, def);
+        return EmitBranch(f, op, def);
       case Expr::BrTable:
         return EmitBrTable(f, def);
       case Expr::Return:
         return EmitReturn(f, def);
 
       // Calls
       case Expr::Call:
         return EmitCall(f, exprOffset, def);
--- a/js/src/asmjs/WasmText.cpp
+++ b/js/src/asmjs/WasmText.cpp
@@ -3513,22 +3513,27 @@ EncodeBlock(Encoder& e, WasmAstBlock& b)
     }
 
     return true;
 }
 
 static bool
 EncodeBranch(Encoder& e, WasmAstBranch& br)
 {
+    MOZ_ASSERT(br.expr() == Expr::Br || br.expr() == Expr::BrIf);
+
     if (!e.writeExpr(br.expr()))
         return false;
 
     if (!e.writeVarU32(br.target().index()))
         return false;
 
+    if (!e.writeExpr(Expr::Nop))
+        return false;
+
     if (br.expr() == Expr::BrIf) {
         if (!EncodeExpr(e, br.cond()))
             return false;
     }
 
     return true;
 }