Skip to content

[Offload] Add tagged type to enumerator docs #147998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025

Conversation

kbenzie
Copy link
Contributor

@kbenzie kbenzie commented Jul 10, 2025

When EnumRec::isTyped() is true, include the EnumValueRec::getTaggedType() to the documentation.

@kbenzie kbenzie marked this pull request as ready for review July 10, 2025 16:37
@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2025

@llvm/pr-subscribers-offload

Author: Kenneth Benzie (Benie) (kbenzie)

Changes

Not all EnumValues specify a tagged type, this patch reflects that in the record definitions whilst also including the tagged type in the docs when it is specified.


Full diff: https://github.com/llvm/llvm-project/pull/147998.diff

3 Files Affected:

  • (modified) offload/tools/offload-tblgen/DocGen.cpp (+5-1)
  • (modified) offload/tools/offload-tblgen/PrintGen.cpp (+13-11)
  • (modified) offload/tools/offload-tblgen/RecordTypes.hpp (+2-2)
diff --git a/offload/tools/offload-tblgen/DocGen.cpp b/offload/tools/offload-tblgen/DocGen.cpp
index 29d00cb3b5098..c9899f7e72748 100644
--- a/offload/tools/offload-tblgen/DocGen.cpp
+++ b/offload/tools/offload-tblgen/DocGen.cpp
@@ -86,7 +86,11 @@ void processEnum(const EnumRec &E, raw_ostream &OS) {
   for (const EnumValueRec Etor : E.getValues()) {
     OS << formatv("  .. c:enumerator:: {0}_{1}\n\n", E.getEnumValNamePrefix(),
                   Etor.getName());
-    OS << "    " << Etor.getDesc() << "\n\n";
+    OS << "    ";
+    if (Etor.getTaggedType()) {
+      OS << ":c:expr:`" << *Etor.getTaggedType() << "` — ";
+    }
+    OS << Etor.getDesc() << "\n\n";
   }
 }
 
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index d1189688a90a3..98f51b0a1a3e1 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -71,19 +71,21 @@ inline void printTagged(llvm::raw_ostream &os, const void *ptr, {0} value, size_
     auto Type = Val.getTaggedType();
     OS << formatv(TAB_1 "case {0}: {{\n", Name);
     // Special case for strings
-    if (Type == "char[]") {
-      OS << formatv(TAB_2 "printPtr(os, (const char*) ptr);\n");
-    } else {
-      OS << formatv(TAB_2 "const {0} * const tptr = (const {0} * const)ptr;\n",
-                    Type);
-      // TODO: Handle other cases here
-      OS << TAB_2 "os << (const void *)tptr << \" (\";\n";
-      if (Type.ends_with("*")) {
-        OS << TAB_2 "os << printPtr(os, tptr);\n";
+    if (Type) {
+      if (Type == "char[]") {
+        OS << formatv(TAB_2 "printPtr(os, (const char*) ptr);\n");
       } else {
-        OS << TAB_2 "os << *tptr;\n";
+        OS << formatv(
+            TAB_2 "const {0} * const tptr = (const {0} * const)ptr;\n", Type);
+        // TODO: Handle other cases here
+        OS << TAB_2 "os << (const void *)tptr << \" (\";\n";
+        if (Type->ends_with("*")) {
+          OS << TAB_2 "os << printPtr(os, tptr);\n";
+        } else {
+          OS << TAB_2 "os << *tptr;\n";
+        }
+        OS << TAB_2 "os << \")\";\n";
       }
-      OS << TAB_2 "os << \")\";\n";
     }
     OS << formatv(TAB_2 "break;\n" TAB_1 "}\n");
   }
diff --git a/offload/tools/offload-tblgen/RecordTypes.hpp b/offload/tools/offload-tblgen/RecordTypes.hpp
index 65c0a4ce4a2c7..c63876bc346da 100644
--- a/offload/tools/offload-tblgen/RecordTypes.hpp
+++ b/offload/tools/offload-tblgen/RecordTypes.hpp
@@ -66,8 +66,8 @@ class EnumValueRec {
   explicit EnumValueRec(const Record *rec) : rec(rec) {}
   std::string getName() const { return rec->getValueAsString("name").upper(); }
   StringRef getDesc() const { return rec->getValueAsString("desc"); }
-  StringRef getTaggedType() const {
-    return rec->getValueAsString("tagged_type");
+  std::optional<StringRef> getTaggedType() const {
+    return rec->getValueAsOptionalString("tagged_type");
   }
 
 private:

@kbenzie kbenzie force-pushed the benie/optional-enum-tagged-type branch 3 times, most recently from 3eda059 to 7c75600 Compare July 14, 2025 10:30
@kbenzie kbenzie changed the title [Offload] Make EnumValueRec::getTaggedType() optional [Offload] Add tagged type when to enumerator docs Jul 14, 2025
@kbenzie kbenzie changed the title [Offload] Add tagged type when to enumerator docs [Offload] Add tagged type to enumerator docs Jul 14, 2025
When `EnumRec::isTyped()` is true, include the
`EnumValueRec::getTaggedType()` to the documentation.
@kbenzie kbenzie force-pushed the benie/optional-enum-tagged-type branch from 7c75600 to 05ce7b0 Compare July 14, 2025 10:33
@callumfare callumfare merged commit b520d21 into llvm:main Jul 14, 2025
9 checks passed
@kbenzie kbenzie deleted the benie/optional-enum-tagged-type branch July 14, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants