From 7848505ebd83083e7fa0c47df72ace6c3a476394 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 19 Jun 2019 14:32:07 -0700 Subject: [PATCH] Print proper message saying variadic ops are not supported in RewriterGen 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 | 3 +++ mlir/lib/TableGen/Operator.cpp | 4 ++++ mlir/tools/mlir-tblgen/RewriterGen.cpp | 27 +++++++++++++++++---------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/mlir/include/mlir/TableGen/Operator.h b/mlir/include/mlir/TableGen/Operator.h index 4551790..3d07e2d 100644 --- a/mlir/include/mlir/TableGen/Operator.h +++ b/mlir/include/mlir/TableGen/Operator.h @@ -71,6 +71,9 @@ public: using value_iterator = NamedTypeConstraint *; using value_range = llvm::iterator_range; + // Returns true if this op has variadic operands or results. + bool isVariadic() const; + // Op result iterators. value_iterator result_begin(); value_iterator result_end(); diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp index a5dd9c25..7f9ebdc 100644 --- a/mlir/lib/TableGen/Operator.cpp +++ b/mlir/lib/TableGen/Operator.cpp @@ -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(); } diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp index 6933eee..80051b0 100644 --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -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 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 -- 2.7.4