[clang] 6d25345 - Remove the `CustomEntry` escape hatch from builtin TableGen (#120861)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 14 01:10:45 PST 2025
Author: Chandler Carruth
Date: 2025-01-14T01:10:42-08:00
New Revision: 6d2534546582721b8d7f10963c329de0a04f0bfe
URL: https://github.com/llvm/llvm-project/commit/6d2534546582721b8d7f10963c329de0a04f0bfe
DIFF: https://github.com/llvm/llvm-project/commit/6d2534546582721b8d7f10963c329de0a04f0bfe.diff
LOG: Remove the `CustomEntry` escape hatch from builtin TableGen (#120861)
This was an especially challenging escape hatch because it directly
forced the use of a specific X-macro structure and prevented any other
form of TableGen emission.
The problematic feature that motivated this is a case where a builtin's
prototype can't be represented in the mini-language used by TableGen.
Instead of adding a complete custom entry for this, this PR just teaches
the prototype handling to do the same thing the X-macros did in this
case: emit an empty string and let the Clang builtin handling respond
appropriately.
This should produce identical results while preserving all the rest of
the structured representation in the builtin TableGen code.
Added:
Modified:
clang/include/clang/Basic/Builtins.td
clang/include/clang/Basic/BuiltinsBase.td
clang/utils/TableGen/ClangBuiltinsEmitter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index f4216bd01a0743..ea22690ce4f5cc 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -3347,10 +3347,12 @@ def VFork : LibBuiltin<"unistd.h"> {
}
// POSIX pthread.h
-// FIXME: This should be a GNULibBuiltin, but it's currently missing the prototype.
-def PthreadCreate : CustomEntry {
- let Entry = "LIBBUILTIN(pthread_create, \"\", \"fC<2,3>\", PTHREAD_H, ALL_GNU_LANGUAGES)";
+def PthreadCreate : GNULibBuiltin<"pthread.h"> {
+ let Spellings = ["pthread_create"];
+ let Attributes = [FunctionWithoutBuiltinPrefix, Callback<[2, 3]>];
+ // Note that we don't have an expressable prototype so we leave it empty.
+ let Prototype = "";
}
def SigSetJmp : LibBuiltin<"setjmp.h"> {
diff --git a/clang/include/clang/Basic/BuiltinsBase.td b/clang/include/clang/Basic/BuiltinsBase.td
index 1a1096d41da40a..6180a94aa4b5c7 100644
--- a/clang/include/clang/Basic/BuiltinsBase.td
+++ b/clang/include/clang/Basic/BuiltinsBase.td
@@ -17,6 +17,11 @@ class IndexedAttribute<string baseMangling, int I> : Attribute<baseMangling> {
int Index = I;
}
+class MultiIndexAttribute<string baseMangling, list<int> Is>
+ : Attribute<baseMangling> {
+ list<int> Indices = Is;
+}
+
// Standard Attributes
// -------------------
def NoReturn : Attribute<"r">;
@@ -77,6 +82,10 @@ def Constexpr : Attribute<"E">;
// Builtin is immediate and must be constant evaluated. Implies Constexpr, and will only be supported in C++20 mode.
def Consteval : Attribute<"EG">;
+// Callback behavior: the first index argument is called with the arguments
+// indicated by the remaining indices.
+class Callback<list<int> ArgIndices> : MultiIndexAttribute<"C", ArgIndices>;
+
// Builtin kinds
// =============
@@ -92,10 +101,6 @@ class Builtin {
bit EnableOpenCLLong = 0;
}
-class CustomEntry {
- string Entry;
-}
-
class AtomicBuiltin : Builtin;
class LibBuiltin<string header, string languages = "ALL_LANGUAGES"> : Builtin {
diff --git a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
index 94cc2183760026..6aca4edfdfb888 100644
--- a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
+++ b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "TableGenBackends.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
@@ -39,6 +40,14 @@ class PrototypeParser {
private:
void ParsePrototype(StringRef Prototype) {
Prototype = Prototype.trim();
+
+ // Some builtins don't have an expressible prototype, simply emit an empty
+ // string for them.
+ if (Prototype.empty()) {
+ Type = "";
+ return;
+ }
+
ParseTypes(Prototype);
}
@@ -246,8 +255,15 @@ void PrintAttributes(const Record *Builtin, BuiltinType BT, raw_ostream &OS) {
for (const auto *Attr : Builtin->getValueAsListOfDefs("Attributes")) {
OS << Attr->getValueAsString("Mangling");
- if (Attr->isSubClassOf("IndexedAttribute"))
+ if (Attr->isSubClassOf("IndexedAttribute")) {
OS << ':' << Attr->getValueAsInt("Index") << ':';
+ } else if (Attr->isSubClassOf("MultiIndexAttribute")) {
+ OS << '<';
+ llvm::ListSeparator Sep(",");
+ for (int64_t Index : Attr->getValueAsListOfInts("Indices"))
+ OS << Sep << Index;
+ OS << '>';
+ }
}
OS << '\"';
}
@@ -405,10 +421,6 @@ void clang::EmitClangBuiltins(const RecordKeeper &Records, raw_ostream &OS) {
EmitBuiltin(OS, Builtin);
}
- for (const auto *Entry : Records.getAllDerivedDefinitions("CustomEntry")) {
- OS << Entry->getValueAsString("Entry") << '\n';
- }
-
OS << R"c++(
#undef ATOMIC_BUILTIN
#undef BUILTIN
More information about the cfe-commits
mailing list