Index: mlir/include/mlir/IR/DialectBase.td =================================================================== --- mlir/include/mlir/IR/DialectBase.td +++ mlir/include/mlir/IR/DialectBase.td @@ -13,17 +13,28 @@ #ifndef DIALECTBASE_TD #define DIALECTBASE_TD +// Helper for marking deprecated classes or defs. To mark a def as deprecated, +// mix in the `Deprecate` class with a reason. +class Deprecated { + string odsDeprecated = reason; +} + //===----------------------------------------------------------------------===// // Dialect definitions //===----------------------------------------------------------------------===// +class EmitFolderBase; // Generate 'fold' method with 'ArrayRef' parameter. // New code should prefer using 'kEmitFoldAdaptorFolder' and // consider 'kEmitRawAttributesFolder' deprecated and to be // removed in the future. -defvar kEmitRawAttributesFolder = 0; +def kEmitRawAttributesFolder : EmitFolderBase, Deprecated< + "'useFoldAPI' of 'kEmitRawAttributesFolder' (default) has been deprecated " + # "and is pending removal. Please switch to 'kEmitFoldAdaptorFolder'. See " + # "https://discourse.llvm.org/t/psa-new-improved-fold-method-signature-has-landed-please-update-your-downstream-projects/67618" +> {} // Generate 'fold' method with 'FoldAdaptor' parameter. -defvar kEmitFoldAdaptorFolder = 1; +def kEmitFoldAdaptorFolder : EmitFolderBase {} class Dialect { // The name of the dialect. @@ -95,7 +106,7 @@ bit isExtensible = 0; // Fold API to use for operations in this dialect. - int useFoldAPI = kEmitRawAttributesFolder; + EmitFolderBase useFoldAPI = kEmitRawAttributesFolder; } #endif // DIALECTBASE_TD Index: mlir/include/mlir/IR/OpBase.td =================================================================== --- mlir/include/mlir/IR/OpBase.td +++ mlir/include/mlir/IR/OpBase.td @@ -40,12 +40,6 @@ string result = r; } -// Helper for marking deprecated classes or defs. To mark a def as deprecated, -// mix in the `Deprecate` class with a reason. -class Deprecated { - string odsDeprecated = reason; -} - //===----------------------------------------------------------------------===// // Predicate definitions //===----------------------------------------------------------------------===// Index: mlir/lib/TableGen/Dialect.cpp =================================================================== --- mlir/lib/TableGen/Dialect.cpp +++ mlir/lib/TableGen/Dialect.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "mlir/TableGen/Dialect.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" @@ -103,13 +104,18 @@ } Dialect::FolderAPI Dialect::getFolderAPI() const { - int64_t value = def->getValueAsInt("useFoldAPI"); - if (value < static_cast(FolderAPI::RawAttributes) || - value > static_cast(FolderAPI::FolderAdaptor)) + llvm::Record *value = def->getValueAsDef("useFoldAPI"); + auto converted = + llvm::StringSwitch>(value->getName()) + .Case("kEmitRawAttributesFolder", FolderAPI::RawAttributes) + .Case("kEmitFoldAdaptorFolder", FolderAPI::FolderAdaptor) + .Default(std::nullopt); + + if (!converted) llvm::PrintFatalError(def->getLoc(), "Invalid value for dialect field `useFoldAPI`"); - return static_cast(value); + return *converted; } bool Dialect::operator==(const Dialect &other) const { Index: mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp =================================================================== --- mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp +++ mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp @@ -78,11 +78,6 @@ // Skip anonymous defs. if (jt.second->isAnonymous()) continue; - // Skip all outside main file to avoid flagging redundantly. - unsigned buf = - SrcMgr.FindBufferContainingLoc(jt.second->getLoc().front()); - if (buf != SrcMgr.getMainFileID()) - continue; if (findUse(*jt.second, it.second->getDefInit(), hasUse)) { PrintWarning(jt.second->getLoc(), Index: mlir/test/mlir-tblgen/has-fold-invalid-values.td =================================================================== --- mlir/test/mlir-tblgen/has-fold-invalid-values.td +++ mlir/test/mlir-tblgen/has-fold-invalid-values.td @@ -2,10 +2,12 @@ include "mlir/IR/OpBase.td" +def Bad : EmitFolderBase; + def Test_Dialect : Dialect { let name = "test"; let cppNamespace = "NS"; - let useFoldAPI = 3; + let useFoldAPI = Bad; } def InvalidValue_Op : Op {