[Mlir-commits] [mlir] 75dfeef - [mlir][ods] fix defgen on empty files

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Dec 2 13:26:14 PST 2021


Author: Mogball
Date: 2021-12-02T21:25:59Z
New Revision: 75dfeef9adba180480040311ab8beae2f369a1b3

URL: https://github.com/llvm/llvm-project/commit/75dfeef9adba180480040311ab8beae2f369a1b3
DIFF: https://github.com/llvm/llvm-project/commit/75dfeef9adba180480040311ab8beae2f369a1b3.diff

LOG: [mlir][ods] fix defgen on empty files

Added: 
    

Modified: 
    mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index 372b6690eeaea..8e245fcc82068 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -43,9 +43,15 @@ std::string mlir::tblgen::getParameterAccessorName(StringRef name) {
 static void collectAllDefs(StringRef selectedDialect,
                            std::vector<llvm::Record *> records,
                            SmallVectorImpl<AttrOrTypeDef> &resultDefs) {
+  // Nothing to do if no defs were found.
+  if (records.empty())
+    return;
+
   auto defs = llvm::map_range(
       records, [&](const llvm::Record *rec) { return AttrOrTypeDef(rec); });
   if (selectedDialect.empty()) {
+    // If a dialect was not specified, ensure that all found defs belong to the
+    // same dialect.
     if (!llvm::is_splat(
             llvm::map_range(defs, [](auto def) { return def.getDialect(); }))) {
       llvm::PrintFatalError("defs belonging to more than one dialect. Must "
@@ -53,6 +59,7 @@ static void collectAllDefs(StringRef selectedDialect,
     }
     resultDefs.assign(defs.begin(), defs.end());
   } else {
+    // Otherwise, generate the defs that belong to the selected dialect.
     auto dialectDefs = llvm::make_filter_range(defs, [&](auto def) {
       return def.getDialect().getName().equals(selectedDialect);
     });


        


More information about the Mlir-commits mailing list