[Mlir-commits] [mlir] d7daa63 - [mlir][tblgen] Emit deprecation warning if `kEmitRawAttributes` is used
Markus Böck
llvmlistbot at llvm.org
Wed Jan 18 01:45:30 PST 2023
Author: Markus Böck
Date: 2023-01-18T10:16:08+01:00
New Revision: d7daa6364cfded615991585b7f8ed7aff66cb7be
URL: https://github.com/llvm/llvm-project/commit/d7daa6364cfded615991585b7f8ed7aff66cb7be
DIFF: https://github.com/llvm/llvm-project/commit/d7daa6364cfded615991585b7f8ed7aff66cb7be.diff
LOG: [mlir][tblgen] Emit deprecation warning if `kEmitRawAttributes` is used
As discussed in https://reviews.llvm.org/D140886, emitting a warning if the old API is used may be beneficial to encourage migration to the new fold API.
This reuse the existing `Deprecated` infrastructure within TableGen, and simply marks the `def` for `kEmitRawAttributesFolder` causing a use of it in a record (even if set within a base class) to emit a warning.
Error message as printed in the terminal:
```
Included from C:/llvm-project/mlir/python/mlir/dialects/TensorOps.td:13:
Included from C:/llvm-project/mlir/include\mlir/Dialect/Tensor/IR/TensorOps.td:12:
C:/llvm-project/mlir/include\mlir/Dialect/Tensor/IR/TensorBase.td:14:5: warning: Using deprecated def `kEmitRawAttributesFolder`
def Tensor_Dialect : Dialect {
^
note: '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
```
Differential Revision: https://reviews.llvm.org/D141604
Added:
Modified:
mlir/include/mlir/IR/DialectBase.td
mlir/include/mlir/IR/OpBase.td
mlir/lib/TableGen/Dialect.cpp
mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
mlir/test/mlir-tblgen/has-fold-invalid-values.td
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/DialectBase.td b/mlir/include/mlir/IR/DialectBase.td
index 043019e60e9b5..18ab90b6fad4f 100644
--- a/mlir/include/mlir/IR/DialectBase.td
+++ b/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 reason> {
+ string odsDeprecated = reason;
+}
+
//===----------------------------------------------------------------------===//
// Dialect definitions
//===----------------------------------------------------------------------===//
+class EmitFolderBase;
// Generate 'fold' method with 'ArrayRef<Attribute>' 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 @@ class Dialect {
bit isExtensible = 0;
// Fold API to use for operations in this dialect.
- int useFoldAPI = kEmitRawAttributesFolder;
+ EmitFolderBase useFoldAPI = kEmitRawAttributesFolder;
}
#endif // DIALECTBASE_TD
diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index a659371981cda..00b70ab3de6a3 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -40,12 +40,6 @@ class StrFunc<string r> {
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 reason> {
- string odsDeprecated = reason;
-}
-
//===----------------------------------------------------------------------===//
// Predicate definitions
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/TableGen/Dialect.cpp b/mlir/lib/TableGen/Dialect.cpp
index 8d6b047f14ffd..e41e2e7209ed9 100644
--- a/mlir/lib/TableGen/Dialect.cpp
+++ b/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 @@ bool Dialect::isExtensible() const {
}
Dialect::FolderAPI Dialect::getFolderAPI() const {
- int64_t value = def->getValueAsInt("useFoldAPI");
- if (value < static_cast<int64_t>(FolderAPI::RawAttributes) ||
- value > static_cast<int64_t>(FolderAPI::FolderAdaptor))
+ llvm::Record *value = def->getValueAsDef("useFoldAPI");
+ auto converted =
+ llvm::StringSwitch<std::optional<Dialect::FolderAPI>>(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<FolderAPI>(value);
+ return *converted;
}
bool Dialect::operator==(const Dialect &other) const {
diff --git a/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp b/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
index bfb5f330e91b0..564161fe4c1a2 100644
--- a/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
+++ b/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
@@ -106,11 +106,6 @@ static void warnOfDeprecatedUses(RecordKeeper &records) {
// 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(),
diff --git a/mlir/test/mlir-tblgen/has-fold-invalid-values.td b/mlir/test/mlir-tblgen/has-fold-invalid-values.td
index 09149a534ab60..f61284dd3822d 100644
--- a/mlir/test/mlir-tblgen/has-fold-invalid-values.td
+++ b/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<Test_Dialect, "invalid_op"> {
More information about the Mlir-commits
mailing list