Bug 1561515 - Wasm: Turn AstTernaryOperator into AstSelect. r=lth
authorRyan Hunt <rhunt@eqrion.net>
Wed, 25 Sep 2019 21:27:05 +0000
changeset 494986 7f894549b2877b0c44393a1957eafe092d92f727
parent 494985 c1a81d62ead5ea21db50b90dd116b73abbed4e03
child 494987 b01aab238aa0293e21f204be90eea391e35c71ec
push id114131
push userdluca@mozilla.com
push dateThu, 26 Sep 2019 09:47:34 +0000
treeherdermozilla-inbound@1dc1a755079a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslth
bugs1561515
milestone71.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 1561515 - Wasm: Turn AstTernaryOperator into AstSelect. r=lth NFC. The select operator will be given an array of result types, so this commit requisitions AstTernaryOperator to be a dedicated select ast node. There's no other uses of AstTernaryOperator, so this is just a rename. Differential Revision: https://phabricator.services.mozilla.com/D45865
js/src/wasm/WasmAST.h
js/src/wasm/WasmTextToBinary.cpp
--- a/js/src/wasm/WasmAST.h
+++ b/js/src/wasm/WasmAST.h
@@ -432,17 +432,17 @@ enum class AstExprKind {
   TableFill,
   TableGet,
   TableGrow,
   TableSet,
   TableSize,
 #endif
   TeeLocal,
   Store,
-  TernaryOperator,
+  Select,
   UnaryOperator,
   Unreachable,
   Wait,
   Wake,
   Fence
 };
 
 class AstExpr : public AstNode {
@@ -483,16 +483,34 @@ class AstDrop : public AstExpr {
 
  public:
   static const AstExprKind Kind = AstExprKind::Drop;
   explicit AstDrop(AstExpr& value)
       : AstExpr(AstExprKind::Drop, ExprType::Void), value_(value) {}
   AstExpr& value() const { return value_; }
 };
 
+class AstSelect : public AstExpr {
+  AstExpr* condition_;
+  AstExpr* op1_;
+  AstExpr* op2_;
+
+ public:
+  static const AstExprKind Kind = AstExprKind::Select;
+  AstSelect(AstExpr* condition, AstExpr* op1, AstExpr* op2)
+      : AstExpr(Kind, ExprType::Limit),
+        condition_(condition),
+        op1_(op1),
+        op2_(op2) {}
+
+  AstExpr* condition() const { return condition_; }
+  AstExpr* op1() const { return op1_; }
+  AstExpr* op2() const { return op2_; }
+};
+
 class AstConst : public AstExpr {
   const LitVal val_;
 
  public:
   static const AstExprKind Kind = AstExprKind::Const;
   explicit AstConst(LitVal val) : AstExpr(Kind, ExprType::Limit), val_(val) {}
   LitVal val() const { return val_; }
 };
@@ -1509,37 +1527,16 @@ class AstBinaryOperator final : public A
   explicit AstBinaryOperator(Op op, AstExpr* lhs, AstExpr* rhs)
       : AstExpr(Kind, ExprType::Limit), op_(op), lhs_(lhs), rhs_(rhs) {}
 
   Op op() const { return op_; }
   AstExpr* lhs() const { return lhs_; }
   AstExpr* rhs() const { return rhs_; }
 };
 
-class AstTernaryOperator : public AstExpr {
-  Op op_;
-  AstExpr* op0_;
-  AstExpr* op1_;
-  AstExpr* op2_;
-
- public:
-  static const AstExprKind Kind = AstExprKind::TernaryOperator;
-  AstTernaryOperator(Op op, AstExpr* op0, AstExpr* op1, AstExpr* op2)
-      : AstExpr(Kind, ExprType::Limit),
-        op_(op),
-        op0_(op0),
-        op1_(op1),
-        op2_(op2) {}
-
-  Op op() const { return op_; }
-  AstExpr* op0() const { return op0_; }
-  AstExpr* op1() const { return op1_; }
-  AstExpr* op2() const { return op2_; }
-};
-
 class AstComparisonOperator final : public AstExpr {
   Op op_;
   AstExpr* lhs_;
   AstExpr* rhs_;
 
  public:
   static const AstExprKind Kind = AstExprKind::ComparisonOperator;
   explicit AstComparisonOperator(Op op, AstExpr* lhs, AstExpr* rhs)
--- a/js/src/wasm/WasmTextToBinary.cpp
+++ b/js/src/wasm/WasmTextToBinary.cpp
@@ -122,16 +122,17 @@ class WasmToken {
     OpenParen,
     Param,
     Passive,
     Ref,
     RefFunc,
     RefNull,
     Result,
     Return,
+    Select,
     SetGlobal,
     SetLocal,
     Shared,
     SignedInteger,
     Start,
     Struct,
     Store,
     Table,
@@ -141,17 +142,16 @@ class WasmToken {
 #ifdef ENABLE_WASM_REFTYPES
     TableFill,
     TableGet,
     TableGrow,
     TableSet,
     TableSize,
 #endif
     TeeLocal,
-    TernaryOpcode,
     Text,
     Then,
     Type,
     UnaryOpcode,
     Unreachable,
     UnsignedInteger,
     ValueType,
     Wait,
@@ -210,18 +210,18 @@ class WasmToken {
     MOZ_ASSERT(kind_ == ValueType || kind_ == Const);
     u.valueType_ = valueType;
   }
   explicit WasmToken(Kind kind, Op op, const char16_t* begin,
                      const char16_t* end)
       : kind_(kind), begin_(begin), end_(end) {
     MOZ_ASSERT(begin != end);
     MOZ_ASSERT(kind_ == UnaryOpcode || kind_ == BinaryOpcode ||
-               kind_ == TernaryOpcode || kind_ == ComparisonOpcode ||
-               kind_ == ConversionOpcode || kind_ == Load || kind_ == Store);
+               kind_ == ComparisonOpcode || kind_ == ConversionOpcode ||
+               kind_ == Load || kind_ == Store);
     u.op_ = op;
   }
   explicit WasmToken(Kind kind, MiscOp op, const char16_t* begin,
                      const char16_t* end)
       : kind_(kind), begin_(begin), end_(end) {
     MOZ_ASSERT(begin != end);
     MOZ_ASSERT(kind_ == ExtraConversionOpcode);
     u.miscOp_ = op;
@@ -268,18 +268,18 @@ class WasmToken {
     return u.floatLiteralKind_;
   }
   ValType valueType() const {
     MOZ_ASSERT(kind_ == ValueType || kind_ == Const);
     return u.valueType_;
   }
   Op op() const {
     MOZ_ASSERT(kind_ == UnaryOpcode || kind_ == BinaryOpcode ||
-               kind_ == TernaryOpcode || kind_ == ComparisonOpcode ||
-               kind_ == ConversionOpcode || kind_ == Load || kind_ == Store);
+               kind_ == ComparisonOpcode || kind_ == ConversionOpcode ||
+               kind_ == Load || kind_ == Store);
     return u.op_;
   }
   MiscOp miscOp() const {
     MOZ_ASSERT(kind_ == ExtraConversionOpcode);
     return u.miscOp_;
   }
   ThreadOp threadOp() const {
     MOZ_ASSERT(kind_ == AtomicCmpXchg || kind_ == AtomicLoad ||
@@ -313,16 +313,17 @@ class WasmToken {
       case If:
       case Load:
       case Loop:
       case MemCopy:
       case MemFill:
       case MemInit:
       case MemoryGrow:
       case MemorySize:
+      case Select:
 #ifdef ENABLE_WASM_GC
       case StructNew:
       case StructGet:
       case StructSet:
       case StructNarrow:
 #endif
       case Nop:
       case RefNull:
@@ -336,17 +337,16 @@ class WasmToken {
 #ifdef ENABLE_WASM_REFTYPES
       case TableFill:
       case TableGet:
       case TableGrow:
       case TableSet:
       case TableSize:
 #endif
       case TeeLocal:
-      case TernaryOpcode:
       case UnaryOpcode:
       case Unreachable:
       case Wait:
       case Wake:
         return true;
       case Align:
       case CloseParen:
       case Data:
@@ -2197,17 +2197,17 @@ WasmToken WasmTokenStream::next() {
           return WasmToken(WasmToken::UnaryOpcode, Op::RefIsNull, begin, cur_);
         }
         return WasmToken(WasmToken::Ref, begin, cur_);
       }
       break;
 
     case 's':
       if (consume(u"select")) {
-        return WasmToken(WasmToken::TernaryOpcode, Op::Select, begin, cur_);
+        return WasmToken(WasmToken::Select, begin, cur_);
       }
       if (consume(u"set_global")) {
         return WasmToken(WasmToken::SetGlobal, begin, cur_);
       }
       if (consume(u"set_local")) {
         return WasmToken(WasmToken::SetLocal, begin, cur_);
       }
       if (consume(u"shared")) {
@@ -3090,36 +3090,16 @@ static AstComparisonOperator* ParseCompa
   AstExpr* rhs = ParseExpr(c, inParens);
   if (!rhs) {
     return nullptr;
   }
 
   return new (c.lifo) AstComparisonOperator(op, lhs, rhs);
 }
 
-static AstTernaryOperator* ParseTernaryOperator(WasmParseContext& c, Op op,
-                                                bool inParens) {
-  AstExpr* op0 = ParseExpr(c, inParens);
-  if (!op0) {
-    return nullptr;
-  }
-
-  AstExpr* op1 = ParseExpr(c, inParens);
-  if (!op1) {
-    return nullptr;
-  }
-
-  AstExpr* op2 = ParseExpr(c, inParens);
-  if (!op2) {
-    return nullptr;
-  }
-
-  return new (c.lifo) AstTernaryOperator(op, op0, op1, op2);
-}
-
 static AstConversionOperator* ParseConversionOperator(WasmParseContext& c,
                                                       Op op, bool inParens) {
   AstExpr* operand = ParseExpr(c, inParens);
   if (!operand) {
     return nullptr;
   }
 
   return new (c.lifo) AstConversionOperator(op, operand);
@@ -3139,16 +3119,35 @@ static AstDrop* ParseDrop(WasmParseConte
   AstExpr* value = ParseExpr(c, inParens);
   if (!value) {
     return nullptr;
   }
 
   return new (c.lifo) AstDrop(*value);
 }
 
+static AstSelect* ParseSelect(WasmParseContext& c, bool inParens) {
+  AstExpr* condition = ParseExpr(c, inParens);
+  if (!condition) {
+    return nullptr;
+  }
+
+  AstExpr* op1 = ParseExpr(c, inParens);
+  if (!op1) {
+    return nullptr;
+  }
+
+  AstExpr* op2 = ParseExpr(c, inParens);
+  if (!op2) {
+    return nullptr;
+  }
+
+  return new (c.lifo) AstSelect(condition, op1, op2);
+}
+
 static AstIf* ParseIf(WasmParseContext& c, bool inParens) {
   AstName name = c.ts.getIfName();
 
   AstExprType type(ExprType::Limit);
   if (!ParseBlockSignature(c, &type)) {
     return nullptr;
   }
 
@@ -4043,26 +4042,26 @@ static AstExpr* ParseExprBody(WasmParseC
     case WasmToken::GetLocal:
       return ParseGetLocal(c);
     case WasmToken::Load:
       return ParseLoad(c, token.op(), inParens);
     case WasmToken::Loop:
       return ParseBlock(c, Op::Loop, inParens);
     case WasmToken::Return:
       return ParseReturn(c, inParens);
+    case WasmToken::Select:
+      return ParseSelect(c, inParens);
     case WasmToken::SetGlobal:
       return ParseSetGlobal(c, inParens);
     case WasmToken::SetLocal:
       return ParseSetLocal(c, inParens);
     case WasmToken::Store:
       return ParseStore(c, token.op(), inParens);
     case WasmToken::TeeLocal:
       return ParseTeeLocal(c, inParens);
-    case WasmToken::TernaryOpcode:
-      return ParseTernaryOperator(c, token.op(), inParens);
     case WasmToken::UnaryOpcode:
       return ParseUnaryOperator(c, token.op(), inParens);
     case WasmToken::Nop:
       return new (c.lifo) AstNop();
     case WasmToken::MemorySize:
       return new (c.lifo) AstMemorySize();
     case WasmToken::MemoryGrow:
       return ParseMemoryGrow(c, inParens);
@@ -5469,16 +5468,21 @@ static bool ResolveBlock(Resolver& r, As
   r.popTarget(b.name());
   return true;
 }
 
 static bool ResolveDropOperator(Resolver& r, AstDrop& drop) {
   return ResolveExpr(r, drop.value());
 }
 
+static bool ResolveSelect(Resolver& r, AstSelect& b) {
+  return ResolveExpr(r, *b.condition()) && ResolveExpr(r, *b.op1()) &&
+         ResolveExpr(r, *b.op2());
+}
+
 static bool ResolveBranch(Resolver& r, AstBranch& br) {
   if (!r.resolveBranchTarget(br.target())) {
     return false;
   }
 
   if (br.maybeValue() && !ResolveExpr(r, *br.maybeValue())) {
     return false;
   }
@@ -5591,21 +5595,16 @@ static bool ResolveUnaryOperator(Resolve
 static bool ResolveMemoryGrow(Resolver& r, AstMemoryGrow& gm) {
   return ResolveExpr(r, *gm.operand());
 }
 
 static bool ResolveBinaryOperator(Resolver& r, AstBinaryOperator& b) {
   return ResolveExpr(r, *b.lhs()) && ResolveExpr(r, *b.rhs());
 }
 
-static bool ResolveTernaryOperator(Resolver& r, AstTernaryOperator& b) {
-  return ResolveExpr(r, *b.op0()) && ResolveExpr(r, *b.op1()) &&
-         ResolveExpr(r, *b.op2());
-}
-
 static bool ResolveComparisonOperator(Resolver& r, AstComparisonOperator& b) {
   return ResolveExpr(r, *b.lhs()) && ResolveExpr(r, *b.rhs());
 }
 
 static bool ResolveConversionOperator(Resolver& r, AstConversionOperator& b) {
   return ResolveExpr(r, *b.operand());
 }
 
@@ -5843,18 +5842,18 @@ static bool ResolveExpr(Resolver& r, Ast
     case AstExprKind::SetLocal:
       return ResolveSetLocal(r, expr.as<AstSetLocal>());
     case AstExprKind::Store:
       return ResolveStore(r, expr.as<AstStore>());
     case AstExprKind::BranchTable:
       return ResolveBranchTable(r, expr.as<AstBranchTable>());
     case AstExprKind::TeeLocal:
       return ResolveTeeLocal(r, expr.as<AstTeeLocal>());
-    case AstExprKind::TernaryOperator:
-      return ResolveTernaryOperator(r, expr.as<AstTernaryOperator>());
+    case AstExprKind::Select:
+      return ResolveSelect(r, expr.as<AstSelect>());
     case AstExprKind::UnaryOperator:
       return ResolveUnaryOperator(r, expr.as<AstUnaryOperator>());
     case AstExprKind::MemoryGrow:
       return ResolveMemoryGrow(r, expr.as<AstMemoryGrow>());
     case AstExprKind::AtomicCmpXchg:
       return ResolveAtomicCmpXchg(r, expr.as<AstAtomicCmpXchg>());
     case AstExprKind::AtomicLoad:
       return ResolveAtomicLoad(r, expr.as<AstAtomicLoad>());
@@ -6265,16 +6264,21 @@ static bool EncodeConst(Encoder& e, AstC
   }
   MOZ_CRASH("Bad value type");
 }
 
 static bool EncodeDrop(Encoder& e, AstDrop& drop) {
   return EncodeExpr(e, drop.value()) && e.writeOp(Op::Drop);
 }
 
+static bool EncodeSelect(Encoder& e, AstSelect& b) {
+  return EncodeExpr(e, *b.condition()) && EncodeExpr(e, *b.op1()) &&
+         EncodeExpr(e, *b.op2()) && e.writeOp(Op::Select);
+}
+
 static bool EncodeGetLocal(Encoder& e, AstGetLocal& gl) {
   return e.writeOp(Op::GetLocal) && e.writeVarU32(gl.local().index());
 }
 
 static bool EncodeSetLocal(Encoder& e, AstSetLocal& sl) {
   return EncodeExpr(e, sl.value()) && e.writeOp(Op::SetLocal) &&
          e.writeVarU32(sl.local().index());
 }
@@ -6297,21 +6301,16 @@ static bool EncodeUnaryOperator(Encoder&
   return EncodeExpr(e, *b.operand()) && e.writeOp(b.op());
 }
 
 static bool EncodeBinaryOperator(Encoder& e, AstBinaryOperator& b) {
   return EncodeExpr(e, *b.lhs()) && EncodeExpr(e, *b.rhs()) &&
          e.writeOp(b.op());
 }
 
-static bool EncodeTernaryOperator(Encoder& e, AstTernaryOperator& b) {
-  return EncodeExpr(e, *b.op0()) && EncodeExpr(e, *b.op1()) &&
-         EncodeExpr(e, *b.op2()) && e.writeOp(b.op());
-}
-
 static bool EncodeComparisonOperator(Encoder& e, AstComparisonOperator& b) {
   return EncodeExpr(e, *b.lhs()) && EncodeExpr(e, *b.rhs()) &&
          e.writeOp(b.op());
 }
 
 static bool EncodeConversionOperator(Encoder& e, AstConversionOperator& b) {
   return EncodeExpr(e, *b.operand()) && e.writeOp(b.op());
 }
@@ -6652,18 +6651,18 @@ static bool EncodeExpr(Encoder& e, AstEx
     case AstExprKind::TeeLocal:
       return EncodeTeeLocal(e, expr.as<AstTeeLocal>());
     case AstExprKind::SetGlobal:
       return EncodeSetGlobal(e, expr.as<AstSetGlobal>());
     case AstExprKind::Store:
       return EncodeStore(e, expr.as<AstStore>());
     case AstExprKind::BranchTable:
       return EncodeBranchTable(e, expr.as<AstBranchTable>());
-    case AstExprKind::TernaryOperator:
-      return EncodeTernaryOperator(e, expr.as<AstTernaryOperator>());
+    case AstExprKind::Select:
+      return EncodeSelect(e, expr.as<AstSelect>());
     case AstExprKind::UnaryOperator:
       return EncodeUnaryOperator(e, expr.as<AstUnaryOperator>());
     case AstExprKind::MemorySize:
       return EncodeMemorySize(e);
     case AstExprKind::MemoryGrow:
       return EncodeMemoryGrow(e, expr.as<AstMemoryGrow>());
     case AstExprKind::AtomicCmpXchg:
       return EncodeAtomicCmpXchg(e, expr.as<AstAtomicCmpXchg>());