[Mlir-commits] [mlir] 308f58c - [mlir][attrtypedef] Sort by def order in file. (#71083)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Nov 2 18:02:12 PDT 2023
Author: Jacques Pienaar
Date: 2023-11-02T18:02:08-07:00
New Revision: 308f58cedac17c9acc8686713ee652a8d4020adb
URL: https://github.com/llvm/llvm-project/commit/308f58cedac17c9acc8686713ee652a8d4020adb
DIFF: https://github.com/llvm/llvm-project/commit/308f58cedac17c9acc8686713ee652a8d4020adb.diff
LOG: [mlir][attrtypedef] Sort by def order in file. (#71083)
Enables having attribute that has another from same file as member.
Added:
Modified:
mlir/test/mlir-tblgen/attrdefs.td
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
Removed:
################################################################################
diff --git a/mlir/test/mlir-tblgen/attrdefs.td b/mlir/test/mlir-tblgen/attrdefs.td
index d7228368e71eb05..0fb6958799b2ecf 100644
--- a/mlir/test/mlir-tblgen/attrdefs.td
+++ b/mlir/test/mlir-tblgen/attrdefs.td
@@ -14,9 +14,9 @@ include "mlir/IR/OpBase.td"
// DEF: #ifdef GET_ATTRDEF_LIST
// DEF: #undef GET_ATTRDEF_LIST
+// DEF: ::test::IndexAttr,
// DEF: ::test::SimpleAAttr,
// DEF: ::test::CompoundAAttr,
-// DEF: ::test::IndexAttr,
// DEF: ::test::SingleParameterAttr
// DEF-LABEL: ::mlir::OptionalParseResult generatedAttributeParser(
@@ -24,13 +24,13 @@ include "mlir/IR/OpBase.td"
// DEF-SAME: ::llvm::StringRef *mnemonic, ::mlir::Type type,
// DEF-SAME: ::mlir::Attribute &value) {
// DEF: return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
+// DEF: .Case(::test::IndexAttr::getMnemonic()
+// DEF-NEXT: value = ::test::IndexAttr::parse(parser, type);
+// DEF-NEXT: return ::mlir::success(!!value);
// DEF: .Case(::test::CompoundAAttr::getMnemonic()
// DEF-NEXT: value = ::test::CompoundAAttr::parse(parser, type);
// DEF-NEXT: return ::mlir::success(!!value);
// DEF-NEXT: })
-// DEF-NEXT: .Case(::test::IndexAttr::getMnemonic()
-// DEF-NEXT: value = ::test::IndexAttr::parse(parser, type);
-// DEF-NEXT: return ::mlir::success(!!value);
// DEF: .Default([&](llvm::StringRef keyword,
// DEF-NEXT: *mnemonic = keyword;
// DEF-NEXT: return std::nullopt;
@@ -44,6 +44,24 @@ def Test_Dialect: Dialect {
class TestAttr<string name> : AttrDef<Test_Dialect, name> { }
+def C_IndexAttr : TestAttr<"Index"> {
+ let mnemonic = "index";
+
+ let parameters = (
+ ins
+ StringRefParameter<"Label for index">:$label
+ );
+ let hasCustomAssemblyFormat = 1;
+
+// DECL-LABEL: class IndexAttr : public ::mlir::Attribute
+// DECL: static constexpr ::llvm::StringLiteral getMnemonic() {
+// DECL: return {"index"};
+// DECL: }
+// DECL: static ::mlir::Attribute parse(
+// DECL-SAME: ::mlir::AsmParser &odsParser, ::mlir::Type odsType);
+// DECL: void print(::mlir::AsmPrinter &odsPrinter) const;
+}
+
def A_SimpleAttrA : TestAttr<"SimpleA"> {
// DECL: class SimpleAAttr : public ::mlir::Attribute
}
@@ -100,24 +118,6 @@ def B_CompoundAttrA : TestAttr<"CompoundA"> {
// DEF-NEXT: return getImpl()->inner;
}
-def C_IndexAttr : TestAttr<"Index"> {
- let mnemonic = "index";
-
- let parameters = (
- ins
- StringRefParameter<"Label for index">:$label
- );
- let hasCustomAssemblyFormat = 1;
-
-// DECL-LABEL: class IndexAttr : public ::mlir::Attribute
-// DECL: static constexpr ::llvm::StringLiteral getMnemonic() {
-// DECL: return {"index"};
-// DECL: }
-// DECL: static ::mlir::Attribute parse(
-// DECL-SAME: ::mlir::AsmParser &odsParser, ::mlir::Type odsType);
-// DECL: void print(::mlir::AsmPrinter &odsPrinter) const;
-}
-
def D_SingleParameterAttr : TestAttr<"SingleParameter"> {
let parameters = (
ins
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index 51f24de2442b957..8889dff7a587242 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -587,7 +587,12 @@ class DefGenerator {
DefGenerator(std::vector<llvm::Record *> &&defs, raw_ostream &os,
StringRef defType, StringRef valueType, bool isAttrGenerator)
: defRecords(std::move(defs)), os(os), defType(defType),
- valueType(valueType), isAttrGenerator(isAttrGenerator) {}
+ valueType(valueType), isAttrGenerator(isAttrGenerator) {
+ // Sort by occurrence in file.
+ llvm::sort(defRecords, [](llvm::Record *lhs, llvm::Record *rhs) {
+ return lhs->getID() < rhs->getID();
+ });
+ }
/// Emit the list of def type names.
void emitTypeDefList(ArrayRef<AttrOrTypeDef> defs);
More information about the Mlir-commits
mailing list