[Mlir-commits] [mlir] bed8212 - [mlir][ods][NFC] Move enum attribute definitions from OpBase.td to EnumAttr.td

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Apr 15 09:51:19 PDT 2022


Author: jfurtek
Date: 2022-04-15T16:51:14Z
New Revision: bed8212157bbf298cddf2e156940452e5067ea05

URL: https://github.com/llvm/llvm-project/commit/bed8212157bbf298cddf2e156940452e5067ea05
DIFF: https://github.com/llvm/llvm-project/commit/bed8212157bbf298cddf2e156940452e5067ea05.diff

LOG: [mlir][ods][NFC] Move enum attribute definitions from OpBase.td to EnumAttr.td

This diff moves `EnumAttr` tablegen definitions (specifically, `IntEnumAttr` and
`BitEnumAttr`-related classes) from `OpBase.td` to `EnumAttr.td`. No
functionality is changed.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123551

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticBase.td
    mlir/include/mlir/Dialect/GPU/ParallelLoopMapperAttr.td
    mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
    mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
    mlir/include/mlir/IR/EnumAttr.td
    mlir/include/mlir/IR/OpBase.td
    mlir/test/mlir-tblgen/op-attribute.td
    mlir/unittests/TableGen/enums.td

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticBase.td b/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticBase.td
index 704edbb587bd3..38bcbf0ad2206 100644
--- a/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticBase.td
+++ b/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticBase.td
@@ -9,6 +9,7 @@
 #ifndef ARITHMETIC_BASE
 #define ARITHMETIC_BASE
 
+include "mlir/IR/EnumAttr.td"
 include "mlir/IR/OpBase.td"
 
 def Arithmetic_Dialect : Dialect {

diff  --git a/mlir/include/mlir/Dialect/GPU/ParallelLoopMapperAttr.td b/mlir/include/mlir/Dialect/GPU/ParallelLoopMapperAttr.td
index daf2d6c6286b2..52ef8b5bb98c8 100644
--- a/mlir/include/mlir/Dialect/GPU/ParallelLoopMapperAttr.td
+++ b/mlir/include/mlir/Dialect/GPU/ParallelLoopMapperAttr.td
@@ -15,6 +15,7 @@
 #define PARALLEL_LOOP_MAPPER_ATTR
 
 include "mlir/Dialect/GPU/GPUBase.td"
+include "mlir/IR/EnumAttr.td"
 
 def BlockX : I64EnumAttrCase<"BlockX", 0>;
 def BlockY : I64EnumAttrCase<"BlockY", 1>;

diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
index 6b0945e1d7b9f..cb6719c226cae 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
@@ -14,6 +14,7 @@
 #ifndef LLVMIR_OP_BASE
 #define LLVMIR_OP_BASE
 
+include "mlir/IR/EnumAttr.td"
 include "mlir/IR/OpBase.td"
 include "mlir/Interfaces/SideEffectInterfaces.td"
 

diff  --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
index 76daf9e387c2f..bc54e948800f8 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
@@ -13,6 +13,7 @@
 #ifndef VECTOR_OPS
 #define VECTOR_OPS
 
+include "mlir/IR/EnumAttr.td"
 include "mlir/Interfaces/ControlFlowInterfaces.td"
 include "mlir/Interfaces/InferTypeOpInterface.td"
 include "mlir/Interfaces/SideEffectInterfaces.td"

diff  --git a/mlir/include/mlir/IR/EnumAttr.td b/mlir/include/mlir/IR/EnumAttr.td
index 8fe6739c75f79..d5bc51a3aab94 100644
--- a/mlir/include/mlir/IR/EnumAttr.td
+++ b/mlir/include/mlir/IR/EnumAttr.td
@@ -11,6 +11,252 @@
 
 include "mlir/IR/AttrTypeBase.td"
 
+//===----------------------------------------------------------------------===//
+// Enum attribute kinds
+
+// Additional information for an enum attribute case.
+class EnumAttrCaseInfo<string sym, int intVal, string strVal> {
+  // The C++ enumerant symbol.
+  string symbol = sym;
+
+  // The C++ enumerant value.
+  // If less than zero, there will be no explicit discriminator values assigned
+  // to enumerators in the generated enum class.
+  int value = intVal;
+
+  // The string representation of the enumerant. May be the same as symbol.
+  string str = strVal;
+}
+
+// An enum attribute case stored with IntegerAttr, which has an integer value,
+// its representation as a string and a C++ symbol name which may be 
diff erent.
+class IntEnumAttrCaseBase<I intType, string sym, string strVal, int intVal> :
+    EnumAttrCaseInfo<sym, intVal, strVal>,
+    SignlessIntegerAttrBase<intType, "case " # strVal> {
+  let predicate =
+    CPred<"$_self.cast<::mlir::IntegerAttr>().getInt() == " # intVal>;
+}
+
+// Cases of integer enum attributes with a specific type. By default, the string
+// representation is the same as the C++ symbol name.
+class I32EnumAttrCase<string sym, int val, string str = sym>
+    : IntEnumAttrCaseBase<I32, sym, str, val>;
+class I64EnumAttrCase<string sym, int val, string str = sym>
+    : IntEnumAttrCaseBase<I64, sym, str, val>;
+
+// A bit enum case stored with an IntegerAttr. `val` here is *not* the ordinal
+// number of a bit that is set. It is an integer value with bits set to match
+// the case.
+class BitEnumAttrCaseBase<I intType, string sym, int val, string str = sym> :
+    EnumAttrCaseInfo<sym, val, str>,
+    SignlessIntegerAttrBase<intType, "case " #str>;
+
+// A bit enum case stored with a 32-bit IntegerAttr. `val` here is *not* the
+// ordinal number of a bit that is set. It is a 32-bit integer value with bits
+// set to match the case. 
+class I32BitEnumAttrCase<string sym, int val, string str = sym>
+    : BitEnumAttrCaseBase<I32, sym, val, str>;
+
+// A bit enum case stored with a 64-bit IntegerAttr. `val` here is *not* the
+// ordinal number of a bit that is set. It is a 64-bit integer value with bits
+// bits set to match the case.
+class I64BitEnumAttrCase<string sym, int val, string str = sym>
+    : BitEnumAttrCaseBase<I64, sym, val, str>;
+
+// The special bit enum case for I32 with no bits set (i.e. value = 0).
+class I32BitEnumAttrCaseNone<string sym, string str = sym>
+    : I32BitEnumAttrCase<sym, 0, str>;
+
+// The special bit enum case for I64 with no bits set (i.e. value = 0).
+class I64BitEnumAttrCaseNone<string sym, string str = sym>
+    : I64BitEnumAttrCase<sym, 0, str>;
+
+// A bit enum case for a single bit, specified by a bit position.
+// The pos argument refers to the index of the bit, and is limited
+// to be in the range [0, bitwidth).
+class BitEnumAttrCaseBit<I intType, string sym, int pos, string str = sym>
+    : BitEnumAttrCaseBase<intType, sym, !shl(1, pos), str> {
+  assert !and(!ge(pos, 0), !lt(pos, intType.bitwidth)),
+      "bit position larger than underlying storage";
+}
+
+// A bit enum case for a single bit in a 32-bit enum, specified by the
+// bit position.
+class I32BitEnumAttrCaseBit<string sym, int pos, string str = sym>
+    : BitEnumAttrCaseBit<I32, sym, pos, str>;
+
+// A bit enum case for a single bit in a 64-bit enum, specified by the
+// bit position.
+class I64BitEnumAttrCaseBit<string sym, int pos, string str = sym>
+    : BitEnumAttrCaseBit<I64, sym, pos, str>;
+
+
+// A bit enum case for a group/list of previously declared cases, providing
+// a convenient alias for that group.
+class BitEnumAttrCaseGroup<I intType, string sym,
+                           list<BitEnumAttrCaseBase> cases, string str = sym>
+    : BitEnumAttrCaseBase<intType, sym,
+          !foldl(0, cases, value, bitcase, !or(value, bitcase.value)),
+          str>;
+
+// A 32-bit enum case for a group/list of previously declared cases, providing
+// a convenient alias for that group.
+class I32BitEnumAttrCaseGroup<string sym, list<BitEnumAttrCaseBase> cases,
+                              string str = sym>
+    : BitEnumAttrCaseGroup<I32, sym, cases, str>;
+
+// A 64-bit enum case for a group/list of previously declared cases, providing
+// a convenient alias for that group.
+class I64BitEnumAttrCaseGroup<string sym, list<BitEnumAttrCaseBase> cases,
+                              string str = sym>
+    : BitEnumAttrCaseGroup<I64, sym, cases, str>;
+
+// Additional information for an enum attribute.
+class EnumAttrInfo<
+    string name, list<EnumAttrCaseInfo> cases, Attr baseClass> :
+      Attr<baseClass.predicate, baseClass.summary> {
+  // The C++ enum class name
+  string className = name;
+
+  // List of all accepted cases
+  list<EnumAttrCaseInfo> enumerants = cases;
+
+  // The following fields are only used by the EnumsGen backend to generate
+  // an enum class definition and conversion utility functions.
+
+  // The underlying type for the C++ enum class. An empty string mean the
+  // underlying type is not explicitly specified.
+  string underlyingType = "";
+
+  // The name of the utility function that converts a value of the underlying
+  // type to the corresponding symbol. It will have the following signature:
+  //
+  // ```c++
+  // llvm::Optional<<qualified-enum-class-name>> <fn-name>(<underlying-type>);
+  // ```
+  string underlyingToSymbolFnName = "symbolize" # name;
+
+  // The name of the utility function that converts a string to the
+  // corresponding symbol. It will have the following signature:
+  //
+  // ```c++
+  // llvm::Optional<<qualified-enum-class-name>> <fn-name>(llvm::StringRef);
+  // ```
+  string stringToSymbolFnName = "symbolize" # name;
+
+  // The name of the utility function that converts a symbol to the
+  // corresponding string. It will have the following signature:
+  //
+  // ```c++
+  // <return-type> <fn-name>(<qualified-enum-class-name>);
+  // ```
+  string symbolToStringFnName = "stringify" # name;
+  string symbolToStringFnRetType = "::llvm::StringRef";
+
+  // The name of the utility function that returns the max enum value used
+  // within the enum class. It will have the following signature:
+  //
+  // ```c++
+  // static constexpr unsigned <fn-name>();
+  // ```
+  string maxEnumValFnName = "getMaxEnumValFor" # name;
+
+  // Generate specialized Attribute class
+  bit genSpecializedAttr = 1;
+  // The underlying Attribute class, which holds the enum value
+  Attr baseAttrClass = baseClass;
+  // The name of specialized Enum Attribute class
+  string specializedAttrClassName = name # Attr;
+
+  // Override Attr class fields for specialized class
+  let predicate = !if(genSpecializedAttr,
+    CPred<"$_self.isa<" # cppNamespace # "::" # specializedAttrClassName # ">()">,
+    baseAttrClass.predicate);
+  let storageType = !if(genSpecializedAttr,
+    cppNamespace # "::" # specializedAttrClassName,
+    baseAttrClass.storageType);
+  let returnType = !if(genSpecializedAttr,
+    cppNamespace # "::" # className,
+    baseAttrClass.returnType);
+  let constBuilderCall = !if(genSpecializedAttr,
+    cppNamespace # "::" # specializedAttrClassName # "::get($_builder.getContext(), $0)",
+    baseAttrClass.constBuilderCall);
+  let valueType = baseAttrClass.valueType;
+}
+
+// An enum attribute backed by IntegerAttr.
+//
+// Op attributes of this kind are stored as IntegerAttr. Extra verification will
+// be generated on the integer though: only the values of the allowed cases are
+// permitted as the integer value.
+class IntEnumAttrBase<I intType, list<IntEnumAttrCaseBase> cases, string summary> :
+    SignlessIntegerAttrBase<intType, summary> {
+  let predicate = And<[
+    SignlessIntegerAttrBase<intType, summary>.predicate,
+    Or<!foreach(case, cases, case.predicate)>]>;
+}
+
+class IntEnumAttr<I intType, string name, string summary,
+                  list<IntEnumAttrCaseBase> cases> :
+  EnumAttrInfo<name, cases,
+    IntEnumAttrBase<intType, cases,
+      !if(!empty(summary), "allowed " # intType.summary # " cases: " #
+          !interleave(!foreach(case, cases, case.value), ", "),
+          summary)>>;
+
+class I32EnumAttr<string name, string summary, list<I32EnumAttrCase> cases> :
+    IntEnumAttr<I32, name, summary, cases> {
+  let underlyingType = "uint32_t";
+}
+class I64EnumAttr<string name, string summary, list<I64EnumAttrCase> cases> :
+    IntEnumAttr<I64, name, summary, cases> {
+  let underlyingType = "uint64_t";
+}
+
+// A bit enum stored with an IntegerAttr.
+//
+// Op attributes of this kind are stored as IntegerAttr. Extra verification will
+// be generated on the integer to make sure only allowed bits are set. Besides,
+// helper methods are generated to parse a string separated with a specified
+// delimiter to a symbol and vice versa.
+class BitEnumAttrBase<I intType, list<BitEnumAttrCaseBase> cases,
+                      string summary>
+    : SignlessIntegerAttrBase<intType, summary> {
+  let predicate = And<[
+    SignlessIntegerAttrBase<intType, summary>.predicate,
+    // Make sure we don't have unknown bit set.
+    CPred<"!($_self.cast<::mlir::IntegerAttr>().getValue().getZExtValue() & (~("
+          # !interleave(!foreach(case, cases, case.value # "u"), "|") #
+          ")))">
+  ]>;
+}
+
+class BitEnumAttr<I intType, string name, string summary,
+                  list<BitEnumAttrCaseBase> cases>
+    : EnumAttrInfo<name, cases, BitEnumAttrBase<intType, cases, summary>> {
+  // Determine "valid" bits from enum cases for error checking
+  int validBits = !foldl(0, cases, value, bitcase, !or(value, bitcase.value));
+
+  // We need to return a string because we may concatenate symbols for multiple
+  // bits together.
+  let symbolToStringFnRetType = "std::string";
+
+  // The delimiter used to separate bit enum cases in strings.
+  string separator = "|";
+}
+
+class I32BitEnumAttr<string name, string summary,
+                     list<BitEnumAttrCaseBase> cases>
+    : BitEnumAttr<I32, name, summary, cases> {
+  let underlyingType = "uint32_t";
+}
+
+class I64BitEnumAttr<string name, string summary,
+                     list<BitEnumAttrCaseBase> cases>
+    : BitEnumAttr<I64, name, summary, cases> {
+  let underlyingType = "uint64_t";
+}
+
 // A C++ enum as an attribute parameter. The parameter implements a parser and
 // printer for the enum by dispatching calls to `stringToSymbol` and
 // `symbolToString`.

diff  --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index d38d16a00710c..2c9633e8bad89 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -1213,252 +1213,6 @@ def UnitAttr : Attr<CPred<"$_self.isa<::mlir::UnitAttr>()">, "unit attribute"> {
   let isOptional = 1;
 }
 
-//===----------------------------------------------------------------------===//
-// Enum attribute kinds
-
-// Additional information for an enum attribute case.
-class EnumAttrCaseInfo<string sym, int intVal, string strVal> {
-  // The C++ enumerant symbol.
-  string symbol = sym;
-
-  // The C++ enumerant value.
-  // If less than zero, there will be no explicit discriminator values assigned
-  // to enumerators in the generated enum class.
-  int value = intVal;
-
-  // The string representation of the enumerant. May be the same as symbol.
-  string str = strVal;
-}
-
-// An enum attribute case stored with IntegerAttr, which has an integer value,
-// its representation as a string and a C++ symbol name which may be 
diff erent.
-class IntEnumAttrCaseBase<I intType, string sym, string strVal, int intVal> :
-    EnumAttrCaseInfo<sym, intVal, strVal>,
-    SignlessIntegerAttrBase<intType, "case " # strVal> {
-  let predicate =
-    CPred<"$_self.cast<::mlir::IntegerAttr>().getInt() == " # intVal>;
-}
-
-// Cases of integer enum attributes with a specific type. By default, the string
-// representation is the same as the C++ symbol name.
-class I32EnumAttrCase<string sym, int val, string str = sym>
-    : IntEnumAttrCaseBase<I32, sym, str, val>;
-class I64EnumAttrCase<string sym, int val, string str = sym>
-    : IntEnumAttrCaseBase<I64, sym, str, val>;
-
-// A bit enum case stored with an IntegerAttr. `val` here is *not* the ordinal
-// number of a bit that is set. It is an integer value with bits set to match
-// the case.
-class BitEnumAttrCaseBase<I intType, string sym, int val, string str = sym> :
-    EnumAttrCaseInfo<sym, val, str>,
-    SignlessIntegerAttrBase<intType, "case " #str>;
-
-// A bit enum case stored with a 32-bit IntegerAttr. `val` here is *not* the
-// ordinal number of a bit that is set. It is a 32-bit integer value with bits
-// set to match the case. 
-class I32BitEnumAttrCase<string sym, int val, string str = sym>
-    : BitEnumAttrCaseBase<I32, sym, val, str>;
-
-// A bit enum case stored with a 64-bit IntegerAttr. `val` here is *not* the
-// ordinal number of a bit that is set. It is a 64-bit integer value with bits
-// bits set to match the case.
-class I64BitEnumAttrCase<string sym, int val, string str = sym>
-    : BitEnumAttrCaseBase<I64, sym, val, str>;
-
-// The special bit enum case for I32 with no bits set (i.e. value = 0).
-class I32BitEnumAttrCaseNone<string sym, string str = sym>
-    : I32BitEnumAttrCase<sym, 0, str>;
-
-// The special bit enum case for I64 with no bits set (i.e. value = 0).
-class I64BitEnumAttrCaseNone<string sym, string str = sym>
-    : I64BitEnumAttrCase<sym, 0, str>;
-
-// A bit enum case for a single bit, specified by a bit position.
-// The pos argument refers to the index of the bit, and is limited
-// to be in the range [0, bitwidth).
-class BitEnumAttrCaseBit<I intType, string sym, int pos, string str = sym>
-    : BitEnumAttrCaseBase<intType, sym, !shl(1, pos), str> {
-  assert !and(!ge(pos, 0), !lt(pos, intType.bitwidth)),
-      "bit position larger than underlying storage";
-}
-
-// A bit enum case for a single bit in a 32-bit enum, specified by the
-// bit position.
-class I32BitEnumAttrCaseBit<string sym, int pos, string str = sym>
-    : BitEnumAttrCaseBit<I32, sym, pos, str>;
-
-// A bit enum case for a single bit in a 64-bit enum, specified by the
-// bit position.
-class I64BitEnumAttrCaseBit<string sym, int pos, string str = sym>
-    : BitEnumAttrCaseBit<I64, sym, pos, str>;
-
-
-// A bit enum case for a group/list of previously declared cases, providing
-// a convenient alias for that group.
-class BitEnumAttrCaseGroup<I intType, string sym,
-                           list<BitEnumAttrCaseBase> cases, string str = sym>
-    : BitEnumAttrCaseBase<intType, sym,
-          !foldl(0, cases, value, bitcase, !or(value, bitcase.value)),
-          str>;
-
-// A 32-bit enum case for a group/list of previously declared cases, providing
-// a convenient alias for that group.
-class I32BitEnumAttrCaseGroup<string sym, list<BitEnumAttrCaseBase> cases,
-                              string str = sym>
-    : BitEnumAttrCaseGroup<I32, sym, cases, str>;
-
-// A 64-bit enum case for a group/list of previously declared cases, providing
-// a convenient alias for that group.
-class I64BitEnumAttrCaseGroup<string sym, list<BitEnumAttrCaseBase> cases,
-                              string str = sym>
-    : BitEnumAttrCaseGroup<I64, sym, cases, str>;
-
-// Additional information for an enum attribute.
-class EnumAttrInfo<
-    string name, list<EnumAttrCaseInfo> cases, Attr baseClass> :
-      Attr<baseClass.predicate, baseClass.summary> {
-  // The C++ enum class name
-  string className = name;
-
-  // List of all accepted cases
-  list<EnumAttrCaseInfo> enumerants = cases;
-
-  // The following fields are only used by the EnumsGen backend to generate
-  // an enum class definition and conversion utility functions.
-
-  // The underlying type for the C++ enum class. An empty string mean the
-  // underlying type is not explicitly specified.
-  string underlyingType = "";
-
-  // The name of the utility function that converts a value of the underlying
-  // type to the corresponding symbol. It will have the following signature:
-  //
-  // ```c++
-  // llvm::Optional<<qualified-enum-class-name>> <fn-name>(<underlying-type>);
-  // ```
-  string underlyingToSymbolFnName = "symbolize" # name;
-
-  // The name of the utility function that converts a string to the
-  // corresponding symbol. It will have the following signature:
-  //
-  // ```c++
-  // llvm::Optional<<qualified-enum-class-name>> <fn-name>(llvm::StringRef);
-  // ```
-  string stringToSymbolFnName = "symbolize" # name;
-
-  // The name of the utility function that converts a symbol to the
-  // corresponding string. It will have the following signature:
-  //
-  // ```c++
-  // <return-type> <fn-name>(<qualified-enum-class-name>);
-  // ```
-  string symbolToStringFnName = "stringify" # name;
-  string symbolToStringFnRetType = "::llvm::StringRef";
-
-  // The name of the utility function that returns the max enum value used
-  // within the enum class. It will have the following signature:
-  //
-  // ```c++
-  // static constexpr unsigned <fn-name>();
-  // ```
-  string maxEnumValFnName = "getMaxEnumValFor" # name;
-
-  // Generate specialized Attribute class
-  bit genSpecializedAttr = 1;
-  // The underlying Attribute class, which holds the enum value
-  Attr baseAttrClass = baseClass;
-  // The name of specialized Enum Attribute class
-  string specializedAttrClassName = name # Attr;
-
-  // Override Attr class fields for specialized class
-  let predicate = !if(genSpecializedAttr,
-    CPred<"$_self.isa<" # cppNamespace # "::" # specializedAttrClassName # ">()">,
-    baseAttrClass.predicate);
-  let storageType = !if(genSpecializedAttr,
-    cppNamespace # "::" # specializedAttrClassName,
-    baseAttrClass.storageType);
-  let returnType = !if(genSpecializedAttr,
-    cppNamespace # "::" # className,
-    baseAttrClass.returnType);
-  let constBuilderCall = !if(genSpecializedAttr,
-    cppNamespace # "::" # specializedAttrClassName # "::get($_builder.getContext(), $0)",
-    baseAttrClass.constBuilderCall);
-  let valueType = baseAttrClass.valueType;
-}
-
-// An enum attribute backed by IntegerAttr.
-//
-// Op attributes of this kind are stored as IntegerAttr. Extra verification will
-// be generated on the integer though: only the values of the allowed cases are
-// permitted as the integer value.
-class IntEnumAttrBase<I intType, list<IntEnumAttrCaseBase> cases, string summary> :
-    SignlessIntegerAttrBase<intType, summary> {
-  let predicate = And<[
-    SignlessIntegerAttrBase<intType, summary>.predicate,
-    Or<!foreach(case, cases, case.predicate)>]>;
-}
-
-class IntEnumAttr<I intType, string name, string summary,
-                  list<IntEnumAttrCaseBase> cases> :
-  EnumAttrInfo<name, cases,
-    IntEnumAttrBase<intType, cases,
-      !if(!empty(summary), "allowed " # intType.summary # " cases: " #
-          !interleave(!foreach(case, cases, case.value), ", "),
-          summary)>>;
-
-class I32EnumAttr<string name, string summary, list<I32EnumAttrCase> cases> :
-    IntEnumAttr<I32, name, summary, cases> {
-  let underlyingType = "uint32_t";
-}
-class I64EnumAttr<string name, string summary, list<I64EnumAttrCase> cases> :
-    IntEnumAttr<I64, name, summary, cases> {
-  let underlyingType = "uint64_t";
-}
-
-// A bit enum stored with an IntegerAttr.
-//
-// Op attributes of this kind are stored as IntegerAttr. Extra verification will
-// be generated on the integer to make sure only allowed bits are set. Besides,
-// helper methods are generated to parse a string separated with a specified
-// delimiter to a symbol and vice versa.
-class BitEnumAttrBase<I intType, list<BitEnumAttrCaseBase> cases,
-                      string summary>
-    : SignlessIntegerAttrBase<intType, summary> {
-  let predicate = And<[
-    SignlessIntegerAttrBase<intType, summary>.predicate,
-    // Make sure we don't have unknown bit set.
-    CPred<"!($_self.cast<::mlir::IntegerAttr>().getValue().getZExtValue() & (~("
-          # !interleave(!foreach(case, cases, case.value # "u"), "|") #
-          ")))">
-  ]>;
-}
-
-class BitEnumAttr<I intType, string name, string summary,
-                  list<BitEnumAttrCaseBase> cases>
-    : EnumAttrInfo<name, cases, BitEnumAttrBase<intType, cases, summary>> {
-  // Determine "valid" bits from enum cases for error checking
-  int validBits = !foldl(0, cases, value, bitcase, !or(value, bitcase.value));
-
-  // We need to return a string because we may concatenate symbols for multiple
-  // bits together.
-  let symbolToStringFnRetType = "std::string";
-
-  // The delimiter used to separate bit enum cases in strings.
-  string separator = "|";
-}
-
-class I32BitEnumAttr<string name, string summary,
-                     list<BitEnumAttrCaseBase> cases>
-    : BitEnumAttr<I32, name, summary, cases> {
-  let underlyingType = "uint32_t";
-}
-
-class I64BitEnumAttr<string name, string summary,
-                     list<BitEnumAttrCaseBase> cases>
-    : BitEnumAttr<I64, name, summary, cases> {
-  let underlyingType = "uint64_t";
-}
-
 //===----------------------------------------------------------------------===//
 // Composite attribute kinds
 

diff  --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td
index 7058102b91e39..771d1b038b44f 100644
--- a/mlir/test/mlir-tblgen/op-attribute.td
+++ b/mlir/test/mlir-tblgen/op-attribute.td
@@ -3,6 +3,7 @@
 // RUN: mlir-tblgen -print-records -I %S/../../include %s | FileCheck %s --check-prefix=RECORD
 
 include "mlir/IR/AttrTypeBase.td"
+include "mlir/IR/EnumAttr.td"
 include "mlir/IR/OpBase.td"
 
 def Test_Dialect : Dialect {

diff  --git a/mlir/unittests/TableGen/enums.td b/mlir/unittests/TableGen/enums.td
index dcc2313e93fef..2baaeb0a50248 100644
--- a/mlir/unittests/TableGen/enums.td
+++ b/mlir/unittests/TableGen/enums.td
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+include "mlir/IR/EnumAttr.td"
 include "mlir/IR/OpBase.td"
 
 def CaseA: I32EnumAttrCase<"CaseA", 0>;


        


More information about the Mlir-commits mailing list