[Mlir-commits] [mlir] 9f1f44b - [mlir][ods] BitEnumAttr: Actually use the 'str' for the all unset case

Jeff Niu llvmlistbot at llvm.org
Thu Dec 8 12:30:36 PST 2022


Author: Jeff Niu
Date: 2022-12-08T12:30:30-08:00
New Revision: 9f1f44bb943ccff7215a61e6033b4a3c529581c8

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

LOG: [mlir][ods] BitEnumAttr: Actually use the 'str' for the all unset case

Reviewed By: rriddle

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/test/mlir-tblgen/enums-gen.td b/mlir/test/mlir-tblgen/enums-gen.td
index 977647ccf7b6..55181b96dd31 100644
--- a/mlir/test/mlir-tblgen/enums-gen.td
+++ b/mlir/test/mlir-tblgen/enums-gen.td
@@ -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)
 

diff  --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp
index 3dbda021c2da..c9f5c81af466 100644
--- a/mlir/tools/mlir-tblgen/EnumsGen.cpp
+++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp
@@ -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.


        


More information about the Mlir-commits mailing list