[llvm] [SandboxIR] Add extern templates for GlobalWithNodeAPI (PR #111940)
Thomas Fransham via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 23 10:16:02 PDT 2024
https://github.com/fsfod updated https://github.com/llvm/llvm-project/pull/111940
>From 22bb1ebd6edab229d7b72b4655a821600dce01e4 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Wed, 9 Oct 2024 19:58:12 +0100
Subject: [PATCH 1/4] [SandboxIR] Add extern templates for GlobalWithNodeAPI
These symbols will need to be explicitly exported for SandboxIRTests when LLVM
is built as shared library on window with explicitly visibility macros are enabled.
This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on window.
---
llvm/include/llvm/SandboxIR/Constant.h | 10 ++++++++
llvm/lib/SandboxIR/Constant.cpp | 35 ++++++++++++++++++++------
2 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/Constant.h b/llvm/include/llvm/SandboxIR/Constant.h
index 6eafdefde60262..afaffb70d721a2 100644
--- a/llvm/include/llvm/SandboxIR/Constant.h
+++ b/llvm/include/llvm/SandboxIR/Constant.h
@@ -22,6 +22,7 @@
#include "llvm/SandboxIR/Context.h"
#include "llvm/SandboxIR/Type.h"
#include "llvm/SandboxIR/User.h"
+#include "llvm/Support/Compiler.h"
namespace llvm::sandboxir {
@@ -1227,6 +1228,15 @@ class ConstantTokenNone final : public Constant {
#endif
};
+extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
+ GlobalIFunc, llvm::GlobalIFunc, GlobalObject, llvm::GlobalObject>;
+extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
+ Function, llvm::Function, GlobalObject, llvm::GlobalObject>;
+extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
+ GlobalVariable, llvm::GlobalVariable, GlobalObject, llvm::GlobalObject>;
+extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
+ GlobalAlias, llvm::GlobalAlias, GlobalValue, llvm::GlobalValue>;
+
} // namespace llvm::sandboxir
#endif // LLVM_SANDBOXIR_CONSTANT_H
diff --git a/llvm/lib/SandboxIR/Constant.cpp b/llvm/lib/SandboxIR/Constant.cpp
index f26c004f630925..f86abfda9fd866 100644
--- a/llvm/lib/SandboxIR/Constant.cpp
+++ b/llvm/lib/SandboxIR/Constant.cpp
@@ -11,6 +11,7 @@
#include "llvm/SandboxIR/BasicBlock.h"
#include "llvm/SandboxIR/Context.h"
#include "llvm/SandboxIR/Function.h"
+#include "llvm/Support/Compiler.h"
namespace llvm::sandboxir {
@@ -291,15 +292,33 @@ GlobalT &GlobalWithNodeAPI<GlobalT, LLVMGlobalT, ParentT, LLVMParentT>::
return cast<GlobalT>(*Ctx.getValue(&LLVMGV));
}
+template LLVM_EXPORT_TEMPLATE GlobalIFunc &
+GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
+ llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalIFunc
+ &LLVMGV)
+ const;
+template LLVM_EXPORT_TEMPLATE Function &
+GlobalWithNodeAPI<Function, llvm::Function, GlobalObject, llvm::GlobalObject>::
+ LLVMGVToGV::operator()(llvm::Function &LLVMGV) const;
+
+template LLVM_EXPORT_TEMPLATE GlobalVariable &GlobalWithNodeAPI<
+ GlobalVariable, llvm::GlobalVariable, GlobalObject,
+ llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalVariable &LLVMGV)
+ const;
+template LLVM_EXPORT_TEMPLATE GlobalAlias &
+GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
+ llvm::GlobalValue>::LLVMGVToGV::operator()(llvm::GlobalAlias
+ &LLVMGV) const;
+
// Explicit instantiations.
-template class GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
- llvm::GlobalObject>;
-template class GlobalWithNodeAPI<Function, llvm::Function, GlobalObject,
- llvm::GlobalObject>;
-template class GlobalWithNodeAPI<GlobalVariable, llvm::GlobalVariable,
- GlobalObject, llvm::GlobalObject>;
-template class GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
- llvm::GlobalValue>;
+template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
+ GlobalIFunc, llvm::GlobalIFunc, GlobalObject, llvm::GlobalObject>;
+template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
+ Function, llvm::Function, GlobalObject, llvm::GlobalObject>;
+template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
+ GlobalVariable, llvm::GlobalVariable, GlobalObject, llvm::GlobalObject>;
+template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
+ GlobalAlias, llvm::GlobalAlias, GlobalValue, llvm::GlobalValue>;
void GlobalIFunc::setResolver(Constant *Resolver) {
Ctx.getTracker()
>From 13a5b0ce974408fe142785f0e0a3399ebb2b8e45 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Fri, 11 Oct 2024 06:35:41 +0100
Subject: [PATCH 2/4] Switch to just exporting LLVMGVToGV::operator()
---
llvm/include/llvm/SandboxIR/Constant.h | 27 +++++++++++++++++---------
llvm/lib/SandboxIR/Constant.cpp | 20 +++++++++----------
2 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/Constant.h b/llvm/include/llvm/SandboxIR/Constant.h
index afaffb70d721a2..28456c3cc35387 100644
--- a/llvm/include/llvm/SandboxIR/Constant.h
+++ b/llvm/include/llvm/SandboxIR/Constant.h
@@ -798,6 +798,24 @@ class GlobalWithNodeAPI : public ParentT {
}
};
+extern template LLVM_TEMPLATE_ABI GlobalIFunc &
+GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
+ llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalIFunc
+ &LLVMGV)
+ const;
+extern template LLVM_TEMPLATE_ABI Function &
+GlobalWithNodeAPI<Function, llvm::Function, GlobalObject, llvm::GlobalObject>::
+ LLVMGVToGV::operator()(llvm::Function &LLVMGV) const;
+
+extern template LLVM_TEMPLATE_ABI GlobalVariable &GlobalWithNodeAPI<
+ GlobalVariable, llvm::GlobalVariable, GlobalObject,
+ llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalVariable &LLVMGV)
+ const;
+extern template LLVM_TEMPLATE_ABI GlobalAlias &
+GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
+ llvm::GlobalValue>::LLVMGVToGV::operator()(llvm::GlobalAlias
+ &LLVMGV) const;
+
class GlobalIFunc final
: public GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
llvm::GlobalObject> {
@@ -1228,15 +1246,6 @@ class ConstantTokenNone final : public Constant {
#endif
};
-extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
- GlobalIFunc, llvm::GlobalIFunc, GlobalObject, llvm::GlobalObject>;
-extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
- Function, llvm::Function, GlobalObject, llvm::GlobalObject>;
-extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
- GlobalVariable, llvm::GlobalVariable, GlobalObject, llvm::GlobalObject>;
-extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
- GlobalAlias, llvm::GlobalAlias, GlobalValue, llvm::GlobalValue>;
-
} // namespace llvm::sandboxir
#endif // LLVM_SANDBOXIR_CONSTANT_H
diff --git a/llvm/lib/SandboxIR/Constant.cpp b/llvm/lib/SandboxIR/Constant.cpp
index f86abfda9fd866..d0f2bada75603c 100644
--- a/llvm/lib/SandboxIR/Constant.cpp
+++ b/llvm/lib/SandboxIR/Constant.cpp
@@ -292,6 +292,16 @@ GlobalT &GlobalWithNodeAPI<GlobalT, LLVMGlobalT, ParentT, LLVMParentT>::
return cast<GlobalT>(*Ctx.getValue(&LLVMGV));
}
+// Explicit instantiations.
+template class GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
+ llvm::GlobalObject>;
+template class GlobalWithNodeAPI<Function, llvm::Function, GlobalObject,
+ llvm::GlobalObject>;
+template class GlobalWithNodeAPI<GlobalVariable, llvm::GlobalVariable,
+ GlobalObject, llvm::GlobalObject>;
+template class GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
+ llvm::GlobalValue>;
+
template LLVM_EXPORT_TEMPLATE GlobalIFunc &
GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalIFunc
@@ -310,16 +320,6 @@ GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
llvm::GlobalValue>::LLVMGVToGV::operator()(llvm::GlobalAlias
&LLVMGV) const;
-// Explicit instantiations.
-template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
- GlobalIFunc, llvm::GlobalIFunc, GlobalObject, llvm::GlobalObject>;
-template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
- Function, llvm::Function, GlobalObject, llvm::GlobalObject>;
-template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
- GlobalVariable, llvm::GlobalVariable, GlobalObject, llvm::GlobalObject>;
-template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
- GlobalAlias, llvm::GlobalAlias, GlobalValue, llvm::GlobalValue>;
-
void GlobalIFunc::setResolver(Constant *Resolver) {
Ctx.getTracker()
.emplaceIfTracking<
>From f4a4661fc48aee709103bf4f15342233d789ed6d Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Wed, 23 Oct 2024 17:52:08 +0100
Subject: [PATCH 3/4] Add comment explaining templates
---
llvm/include/llvm/SandboxIR/Constant.h | 1 +
llvm/lib/SandboxIR/Constant.cpp | 1 +
2 files changed, 2 insertions(+)
diff --git a/llvm/include/llvm/SandboxIR/Constant.h b/llvm/include/llvm/SandboxIR/Constant.h
index 28456c3cc35387..17f55e973cd764 100644
--- a/llvm/include/llvm/SandboxIR/Constant.h
+++ b/llvm/include/llvm/SandboxIR/Constant.h
@@ -798,6 +798,7 @@ class GlobalWithNodeAPI : public ParentT {
}
};
+// These are needed for SandboxIRTest when building with LLVM_BUILD_LLVM_DYLIB
extern template LLVM_TEMPLATE_ABI GlobalIFunc &
GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalIFunc
diff --git a/llvm/lib/SandboxIR/Constant.cpp b/llvm/lib/SandboxIR/Constant.cpp
index d0f2bada75603c..13860ae0c56f27 100644
--- a/llvm/lib/SandboxIR/Constant.cpp
+++ b/llvm/lib/SandboxIR/Constant.cpp
@@ -302,6 +302,7 @@ template class GlobalWithNodeAPI<GlobalVariable, llvm::GlobalVariable,
template class GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
llvm::GlobalValue>;
+// These are needed for SandboxIRTest when building with LLVM_BUILD_LLVM_DYLIB
template LLVM_EXPORT_TEMPLATE GlobalIFunc &
GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalIFunc
>From d81725bb90effe6c233ae93a2659d449275cb378 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Wed, 23 Oct 2024 18:15:45 +0100
Subject: [PATCH 4/4] Only add the template definitions for windows to fix
duplicate error for linux
---
llvm/lib/SandboxIR/Constant.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/lib/SandboxIR/Constant.cpp b/llvm/lib/SandboxIR/Constant.cpp
index 13860ae0c56f27..3e13c935c42811 100644
--- a/llvm/lib/SandboxIR/Constant.cpp
+++ b/llvm/lib/SandboxIR/Constant.cpp
@@ -302,6 +302,7 @@ template class GlobalWithNodeAPI<GlobalVariable, llvm::GlobalVariable,
template class GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
llvm::GlobalValue>;
+#ifdef _MSC_VER
// These are needed for SandboxIRTest when building with LLVM_BUILD_LLVM_DYLIB
template LLVM_EXPORT_TEMPLATE GlobalIFunc &
GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
@@ -320,6 +321,7 @@ template LLVM_EXPORT_TEMPLATE GlobalAlias &
GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
llvm::GlobalValue>::LLVMGVToGV::operator()(llvm::GlobalAlias
&LLVMGV) const;
+#endif
void GlobalIFunc::setResolver(Constant *Resolver) {
Ctx.getTracker()
More information about the llvm-commits
mailing list