Also disable generating underlying value to symbol conversion declaration when there...
authorLei Zhang <antiagainst@google.com>
Mon, 1 Jul 2019 14:30:23 +0000 (07:30 -0700)
committerjpienaar <jpienaar@google.com>
Mon, 1 Jul 2019 16:56:11 +0000 (09:56 -0700)
PiperOrigin-RevId: 255950779

mlir/tools/mlir-tblgen/EnumsGen.cpp

index b750e0a..36f2e04 100644 (file)
@@ -211,9 +211,13 @@ static void emitEnumDecl(const Record &enumDef, raw_ostream &os) {
   emitEnumClass(enumDef, enumName, underlyingType, description, enumerants, os);
 
   // Emit coversion function declarations
-  os << formatv(
-      "llvm::Optional<{0}> {1}({2});\n", enumName, underlyingToSymFnName,
-      underlyingType.empty() ? std::string("unsigned") : underlyingType);
+  if (llvm::all_of(enumerants, [](EnumAttrCase enumerant) {
+        return enumerant.getValue() >= 0;
+      })) {
+    os << formatv(
+        "llvm::Optional<{0}> {1}({2});\n", enumName, underlyingToSymFnName,
+        underlyingType.empty() ? std::string("unsigned") : underlyingType);
+  }
   os << formatv("llvm::StringRef {1}({0});\n", enumName, symToStrFnName);
   os << formatv("llvm::Optional<{0}> {1}(llvm::StringRef);\n", enumName,
                 strToSymFnName);