[mlir][ods] BitEnumAttr: Actually use the 'str' for the all unset case
authorJeff Niu <jeff@modular.com>
Thu, 8 Dec 2022 19:45:18 +0000 (11:45 -0800)
committerJeff Niu <jeff@modular.com>
Thu, 8 Dec 2022 20:30:30 +0000 (12:30 -0800)
Reviewed By: rriddle

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

mlir/test/mlir-tblgen/enums-gen.td
mlir/tools/mlir-tblgen/EnumsGen.cpp

index 977647c..55181b9 100644 (file)
@@ -5,7 +5,7 @@ include "mlir/IR/EnumAttr.td"
 include "mlir/IR/OpBase.td"
 
 // Test bit enums
-def None: I32BitEnumAttrCaseNone<"None">;
+def None: I32BitEnumAttrCaseNone<"None", "none">;
 def Bit0: I32BitEnumAttrCaseBit<"Bit0", 0, "tagged">;
 def Bit1: I32BitEnumAttrCaseBit<"Bit1", 1>;
 def Bit2: I32BitEnumAttrCaseBit<"Bit2", 2>;
@@ -60,14 +60,14 @@ def MyBitEnum: I32BitEnumAttr<"MyBitEnum", "An example bit enum",
 
 // DEF-LABEL: std::string stringifyMyBitEnum
 // DEF: auto val = static_cast<uint32_t>
-// DEF: if (val == 0) return "None";
+// DEF: if (val == 0) return "none";
 // DEF: if (1u == (1u & val))
 // DEF-NEXT: push_back("tagged")
 // DEF: if (2u == (2u & val))
 // DEF-NEXT: push_back("Bit1")
 
 // DEF-LABEL: ::llvm::Optional<MyBitEnum> symbolizeMyBitEnum(::llvm::StringRef str)
-// DEF: if (str == "None") return MyBitEnum::None;
+// DEF: if (str == "none") return MyBitEnum::None;
 // DEF: .Case("tagged", 1)
 // DEF: .Case("Bit1", 2)
 
index 3dbda02..c9f5c81 100644 (file)
@@ -128,8 +128,7 @@ inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, {0} value) {{
         continue;
       StringRef symbol = it.value().getSymbol();
       os << llvm::formatv("  case {0}::{1}:\n", qualName,
-                          llvm::isDigit(symbol.front()) ? ("_" + symbol)
-                                                        : symbol);
+                          makeIdentifier(symbol));
     }
     os << "    break;\n"
           "  default:\n"
@@ -326,7 +325,7 @@ static void emitSymToStrFnForBitEnum(const Record &enumDef, raw_ostream &os) {
   if (allBitsUnsetCase) {
     os << "  // Special case for all bits unset.\n";
     os << formatv("  if (val == 0) return \"{0}\";\n\n",
-                  allBitsUnsetCase->getSymbol());
+                  allBitsUnsetCase->getStr());
   }
   os << "  ::llvm::SmallVector<::llvm::StringRef, 2> strs;\n";
 
@@ -413,7 +412,7 @@ static void emitStrToSymFnForBitEnum(const Record &enumDef, raw_ostream &os) {
     os << "  // Special case for all bits unset.\n";
     StringRef caseSymbol = allBitsUnsetCase->getSymbol();
     os << formatv("  if (str == \"{1}\") return {0}::{2};\n\n", enumName,
-                  caseSymbol, makeIdentifier(caseSymbol));
+                  allBitsUnsetCase->getStr(), makeIdentifier(caseSymbol));
   }
 
   // Split the string to get symbols for all the bits.