[mlir][ods] fix defgen on empty files

This commit is contained in:
Mogball 2021-12-02 21:25:04 +00:00
parent 740057d185
commit 75dfeef9ad
1 changed files with 7 additions and 0 deletions

View File

@ -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);
});