From 2d723d4ad51c1e369810b543e1ac9ac1dfe0bfc8 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Mon, 16 Mar 2020 13:55:16 -0700 Subject: [PATCH] [mlir] Avoid the use of auto in templates to fix MSVC build MSVC is unable to deduce template types when the type involves auto. --- mlir/tools/mlir-tblgen/DialectGen.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp index c0009d6e1231b..695ce3de9b933 100644 --- a/mlir/tools/mlir-tblgen/DialectGen.cpp +++ b/mlir/tools/mlir-tblgen/DialectGen.cpp @@ -36,14 +36,23 @@ static llvm::cl::opt selectedDialect("dialect", llvm::cl::desc("The dialect to gen for"), llvm::cl::cat(dialectGenCat), llvm::cl::CommaSeparated); +/// Utility iterator used for filtering records for a specific dialect. +namespace { +using DialectFilterIterator = + llvm::filter_iterator::iterator, + std::function>; +} // end anonymous namespace + /// Given a set of records for a T, filter the ones that correspond to /// the given dialect. template -static auto filterForDialect(ArrayRef records, - Dialect &dialect) { - return llvm::make_filter_range(records, [&](const llvm::Record *record) { +static iterator_range +filterForDialect(ArrayRef records, Dialect &dialect) { + auto filterFn = [&](const llvm::Record *record) { return T(record).getDialect() == dialect; - }); + }; + return {DialectFilterIterator(records.begin(), records.end(), filterFn), + DialectFilterIterator(records.end(), records.end(), filterFn)}; } //===----------------------------------------------------------------------===// @@ -93,12 +102,10 @@ static const char *const constantMaterializerDecl = R"( )"; /// Generate the declaration for the given dialect class. -static void emitDialectDecl( - Dialect &dialect, - FunctionTraits)>::result_t - dialectAttrs, - FunctionTraits)>::result_t dialectTypes, - raw_ostream &os) { +static void emitDialectDecl(Dialect &dialect, + iterator_range dialectAttrs, + iterator_range dialectTypes, + raw_ostream &os) { // Emit the start of the decl. std::string cppName = dialect.getCppClassName(); os << llvm::formatv(dialectDeclBeginStr, cppName, dialect.getName());