Print proper message saying variadic ops are not supported in RewriterGen
authorLei Zhang <antiagainst@google.com>
Wed, 19 Jun 2019 21:32:07 +0000 (14:32 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Thu, 20 Jun 2019 06:08:52 +0000 (23:08 -0700)
Support for ops with variadic operands/results will come later; but right now
a proper message helps to avoid deciphering confusing error messages later in
the compilation stage.

PiperOrigin-RevId: 254071820

mlir/include/mlir/TableGen/Operator.h
mlir/lib/TableGen/Operator.cpp
mlir/tools/mlir-tblgen/RewriterGen.cpp

index 4551790..3d07e2d 100644 (file)
@@ -71,6 +71,9 @@ public:
   using value_iterator = NamedTypeConstraint *;
   using value_range = llvm::iterator_range<value_iterator>;
 
+  // Returns true if this op has variadic operands or results.
+  bool isVariadic() const;
+
   // Op result iterators.
   value_iterator result_begin();
   value_iterator result_end();
index a5dd9c2..7f9ebdc 100644 (file)
@@ -89,6 +89,10 @@ StringRef tblgen::Operator::getExtraClassDeclaration() const {
 
 const llvm::Record &tblgen::Operator::getDef() const { return def; }
 
+bool tblgen::Operator::isVariadic() const {
+  return getNumVariadicOperands() != 0 || getNumVariadicResults() != 0;
+}
+
 auto tblgen::Operator::result_begin() -> value_iterator {
   return results.begin();
 }
index 6933eee..80051b0 100644 (file)
@@ -262,6 +262,12 @@ std::string PatternEmitter::handleConstantAttr(Attribute attr,
 // Helper function to match patterns.
 void PatternEmitter::emitOpMatch(DagNode tree, int depth) {
   Operator &op = tree.getDialectOp(opMap);
+  if (op.isVariadic()) {
+    PrintFatalError(loc, formatv("matching op '{0}' with variadic "
+                                 "operands/results is unsupported right now",
+                                 op.getOperationName()));
+  }
+
   int indent = 4 + 2 * depth;
   // Skip the operand matching at depth 0 as the pattern rewriter already does.
   if (depth != 0) {
@@ -473,10 +479,6 @@ void PatternEmitter::emit(StringRef rewriteName) {
   const Operator &rootOp = pattern.getSourceRootOp();
   auto rootName = rootOp.getOperationName();
 
-  if (rootOp.getNumVariadicResults() != 0)
-    PrintFatalError(
-        loc, "replacing op with variadic results not supported right now");
-
   // Collect the set of result operations.
   llvm::SmallPtrSet<const Operator *, 4> results;
   for (unsigned i = 0, e = pattern.getNumResults(); i != e; ++i)
@@ -675,6 +677,17 @@ std::string PatternEmitter::emitOpCreate(DagNode tree, int resultIndex,
   Operator &resultOp = tree.getDialectOp(opMap);
   auto numOpArgs = resultOp.getNumArgs();
 
+  if (resultOp.getNumResults() > 1) {
+    PrintFatalError(
+        loc, formatv("generating multiple-result op '{0}' is unsupported now",
+                     resultOp.getOperationName()));
+  }
+  if (resultOp.isVariadic()) {
+    PrintFatalError(loc, formatv("generating op '{0}' with variadic "
+                                 "operands/results is unsupported now",
+                                 resultOp.getOperationName()));
+  }
+
   if (numOpArgs != tree.getNumArgs()) {
     PrintFatalError(loc, formatv("resultant op '{0}' argument number mismatch: "
                                  "{1} in pattern vs. {2} in definition",
@@ -682,12 +695,6 @@ std::string PatternEmitter::emitOpCreate(DagNode tree, int resultIndex,
                                  numOpArgs));
   }
 
-  if (resultOp.getNumResults() > 1) {
-    PrintFatalError(
-        loc, formatv("generating multiple-result op '{0}' is unsupported now",
-                     resultOp.getOperationName()));
-  }
-
   // A map to collect all nested DAG child nodes' names, with operand index as
   // the key. This includes both bound and unbound child nodes. Bound child
   // nodes will additionally be tracked in `symbolResolver` so they can be