[Mlir-commits] [mlir] 256d448 - [MLIR] [TableGen] Avoid generating an assert which is always true.
Rahul Joshi
llvmlistbot at llvm.org
Tue Jul 14 09:20:19 PDT 2020
Author: Rahul Joshi
Date: 2020-07-14T09:19:52-07:00
New Revision: 256d44811eabd838db79b6a1adfffa4f588750b7
URL: https://github.com/llvm/llvm-project/commit/256d44811eabd838db79b6a1adfffa4f588750b7
DIFF: https://github.com/llvm/llvm-project/commit/256d44811eabd838db79b6a1adfffa4f588750b7.diff
LOG: [MLIR] [TableGen] Avoid generating an assert which is always true.
- Avoid generating "assert(resultTypes.size() >= 0u)" which is always true
Differential Revision: https://reviews.llvm.org/D83735
Added:
Modified:
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Removed:
################################################################################
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index faeb21265142..08035a95a0a1 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -943,13 +943,21 @@ void OpEmitter::genSeparateArgParamBuilder() {
<< ");\n";
}
return;
- case TypeParamKind::Collective:
- body << " "
- << "assert(resultTypes.size() "
- << (op.getNumVariableLengthResults() == 0 ? "==" : ">=") << " "
- << (op.getNumResults() - op.getNumVariableLengthResults())
- << "u && \"mismatched number of results\");\n";
+ case TypeParamKind::Collective: {
+ int numResults = op.getNumResults();
+ int numVariadicResults = op.getNumVariableLengthResults();
+ int numNonVariadicResults = numResults - numVariadicResults;
+ bool hasVariadicResult = numVariadicResults != 0;
+
+ // Avoid emitting "resultTypes.size() >= 0u" which is always true.
+ if (!(hasVariadicResult && numNonVariadicResults == 0))
+ body << " "
+ << "assert(resultTypes.size() "
+ << (hasVariadicResult ? ">=" : "==") << " "
+ << numNonVariadicResults
+ << "u && \"mismatched number of results\");\n";
body << " " << builderOpState << ".addTypes(resultTypes);\n";
+ }
return;
}
llvm_unreachable("unhandled TypeParamKind");
More information about the Mlir-commits
mailing list