[llvm] [TableGen] Add explicit symbol visibility macros to code generated (PR #107873)
Thomas Fransham via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 10 08:12:02 PDT 2024
https://github.com/fsfod updated https://github.com/llvm/llvm-project/pull/107873
>From f602bb4e36700e666377b06cd071bd829e971726 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 9 Sep 2024 01:51:48 +0100
Subject: [PATCH] [TableGen] Add explicit symbol visibility macros to code
generated
Update llvm's TableGen to add explicit symbol visibility macros to function declarations it creates
The symbols need to be export from llvm's shared library for Clang and some OpenMP tests
---
llvm/test/TableGen/directive1.td | 19 ++++++++++---------
llvm/test/TableGen/directive2.td | 15 ++++++++-------
llvm/utils/TableGen/DirectiveEmitter.cpp | 22 ++++++++++++----------
3 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/llvm/test/TableGen/directive1.td b/llvm/test/TableGen/directive1.td
index 3af3b04dc00939..2f877029c83962 100644
--- a/llvm/test/TableGen/directive1.td
+++ b/llvm/test/TableGen/directive1.td
@@ -53,6 +53,7 @@ def TDL_DirA : Directive<"dira"> {
// CHECK-EMPTY:
// CHECK-NEXT: #include "llvm/ADT/ArrayRef.h"
// CHECK-NEXT: #include "llvm/ADT/BitmaskEnum.h"
+// CHECK-NEXT: #include "llvm/Support/Compiler.h"
// CHECK-NEXT: #include <cstddef>
// CHECK-EMPTY:
// CHECK-NEXT: namespace llvm {
@@ -114,22 +115,22 @@ def TDL_DirA : Directive<"dira"> {
// CHECK-NEXT: constexpr auto TDLCV_valc = llvm::tdl::AKind::TDLCV_valc;
// CHECK-EMPTY:
// CHECK-NEXT: // Enumeration helper functions
-// CHECK-NEXT: Directive getTdlDirectiveKind(llvm::StringRef Str);
+// CHECK-NEXT: LLVM_ABI Directive getTdlDirectiveKind(llvm::StringRef Str);
// CHECK-EMPTY:
-// CHECK-NEXT: llvm::StringRef getTdlDirectiveName(Directive D);
+// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlDirectiveName(Directive D);
// CHECK-EMPTY:
-// CHECK-NEXT: Clause getTdlClauseKind(llvm::StringRef Str);
+// CHECK-NEXT: LLVM_ABI Clause getTdlClauseKind(llvm::StringRef Str);
// CHECK-EMPTY:
-// CHECK-NEXT: llvm::StringRef getTdlClauseName(Clause C);
+// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlClauseName(Clause C);
// CHECK-EMPTY:
// CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
-// CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
+// CHECK-NEXT: LLVM_ABI bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::size_t getMaxLeafCount() { return 0; }
-// CHECK-NEXT: Association getDirectiveAssociation(Directive D);
-// CHECK-NEXT: Category getDirectiveCategory(Directive D);
-// CHECK-NEXT: AKind getAKind(StringRef);
-// CHECK-NEXT: llvm::StringRef getTdlAKindName(AKind);
+// CHECK-NEXT: LLVM_ABI Association getDirectiveAssociation(Directive D);
+// CHECK-NEXT: LLVM_ABI Category getDirectiveCategory(Directive D);
+// CHECK-NEXT: LLVM_ABI AKind getAKind(StringRef);
+// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlAKindName(AKind);
// CHECK-EMPTY:
// CHECK-NEXT: } // namespace tdl
// CHECK-NEXT: } // namespace llvm
diff --git a/llvm/test/TableGen/directive2.td b/llvm/test/TableGen/directive2.td
index 209901bb616f4e..3f1a44cfdd4f96 100644
--- a/llvm/test/TableGen/directive2.td
+++ b/llvm/test/TableGen/directive2.td
@@ -46,6 +46,7 @@ def TDL_DirA : Directive<"dira"> {
// CHECK-NEXT: #define LLVM_Tdl_INC
// CHECK-EMPTY:
// CHECK-NEXT: #include "llvm/ADT/ArrayRef.h"
+// CHECK-NEXT: #include "llvm/Support/Compiler.h"
// CHECK-NEXT: #include <cstddef>
// CHECK-EMPTY:
// CHECK-NEXT: namespace llvm {
@@ -90,20 +91,20 @@ def TDL_DirA : Directive<"dira"> {
// CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 4;
// CHECK-EMPTY:
// CHECK-NEXT: // Enumeration helper functions
-// CHECK-NEXT: Directive getTdlDirectiveKind(llvm::StringRef Str);
+// CHECK-NEXT: LLVM_ABI Directive getTdlDirectiveKind(llvm::StringRef Str);
// CHECK-EMPTY:
-// CHECK-NEXT: llvm::StringRef getTdlDirectiveName(Directive D);
+// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlDirectiveName(Directive D);
// CHECK-EMPTY:
-// CHECK-NEXT: Clause getTdlClauseKind(llvm::StringRef Str);
+// CHECK-NEXT: LLVM_ABI Clause getTdlClauseKind(llvm::StringRef Str);
// CHECK-EMPTY:
-// CHECK-NEXT: llvm::StringRef getTdlClauseName(Clause C);
+// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlClauseName(Clause C);
// CHECK-EMPTY:
// CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
-// CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
+// CHECK-NEXT: LLVM_ABI bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::size_t getMaxLeafCount() { return 0; }
-// CHECK-NEXT: Association getDirectiveAssociation(Directive D);
-// CHECK-NEXT: Category getDirectiveCategory(Directive D);
+// CHECK-NEXT: LLVM_ABI Association getDirectiveAssociation(Directive D);
+// CHECK-NEXT: LLVM_ABI Category getDirectiveCategory(Directive D);
// CHECK-NEXT: } // namespace tdl
// CHECK-NEXT: } // namespace llvm
// CHECK-NEXT: #endif // LLVM_Tdl_INC
diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp
index aaad0fc861529f..fafdfa0db89af2 100644
--- a/llvm/utils/TableGen/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/DirectiveEmitter.cpp
@@ -111,12 +111,12 @@ static void GenerateEnumClauseVal(ArrayRef<const Record *> Records,
<< "llvm::" << DirLang.getCppNamespace() << "::" << EnumName
<< "::" << CV->getName() << ";\n";
}
- EnumHelperFuncs += (Twine(EnumName) + Twine(" get") + Twine(EnumName) +
- Twine("(StringRef);\n"))
+ EnumHelperFuncs += (Twine("LLVM_ABI ") + Twine(EnumName) + Twine(" get") +
+ Twine(EnumName) + Twine("(StringRef);\n"))
.str();
EnumHelperFuncs +=
- (Twine("llvm::StringRef get") + Twine(DirLang.getName()) +
+ (Twine("LLVM_ABI llvm::StringRef get") + Twine(DirLang.getName()) +
Twine(EnumName) + Twine("Name(") + Twine(EnumName) + Twine(");\n"))
.str();
}
@@ -200,6 +200,7 @@ static void EmitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
if (DirLang.hasEnableBitmaskEnumInNamespace())
OS << "#include \"llvm/ADT/BitmaskEnum.h\"\n";
+ OS << "#include \"llvm/Support/Compiler.h\"\n";
OS << "#include <cstddef>\n"; // for size_t
OS << "\n";
OS << "namespace llvm {\n";
@@ -242,26 +243,27 @@ static void EmitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
// Generic function signatures
OS << "\n";
OS << "// Enumeration helper functions\n";
- OS << "Directive get" << DirLang.getName()
+ OS << "LLVM_ABI Directive get" << DirLang.getName()
<< "DirectiveKind(llvm::StringRef Str);\n";
OS << "\n";
- OS << "llvm::StringRef get" << DirLang.getName()
+ OS << "LLVM_ABI llvm::StringRef get" << DirLang.getName()
<< "DirectiveName(Directive D);\n";
OS << "\n";
- OS << "Clause get" << DirLang.getName()
+ OS << "LLVM_ABI Clause get" << DirLang.getName()
<< "ClauseKind(llvm::StringRef Str);\n";
OS << "\n";
- OS << "llvm::StringRef get" << DirLang.getName() << "ClauseName(Clause C);\n";
+ OS << "LLVM_ABI llvm::StringRef get" << DirLang.getName()
+ << "ClauseName(Clause C);\n";
OS << "\n";
OS << "/// Return true if \\p C is a valid clause for \\p D in version \\p "
<< "Version.\n";
- OS << "bool isAllowedClauseForDirective(Directive D, "
+ OS << "LLVM_ABI bool isAllowedClauseForDirective(Directive D, "
<< "Clause C, unsigned Version);\n";
OS << "\n";
OS << "constexpr std::size_t getMaxLeafCount() { return "
<< GetMaxLeafCount(DirLang) << "; }\n";
- OS << "Association getDirectiveAssociation(Directive D);\n";
- OS << "Category getDirectiveCategory(Directive D);\n";
+ OS << "LLVM_ABI Association getDirectiveAssociation(Directive D);\n";
+ OS << "LLVM_ABI Category getDirectiveCategory(Directive D);\n";
if (EnumHelperFuncs.length() > 0) {
OS << EnumHelperFuncs;
OS << "\n";
More information about the llvm-commits
mailing list