From 22bb1ebd6edab229d7b72b4655a821600dce01e4 Mon Sep 17 00:00:00 2001 From: Thomas Fransham 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 6eafdefde6026..afaffb70d721a 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 f26c004f63092..f86abfda9fd86 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:: return cast(*Ctx.getValue(&LLVMGV)); } +template LLVM_EXPORT_TEMPLATE GlobalIFunc & +GlobalWithNodeAPI::LLVMGVToGV::operator()(llvm::GlobalIFunc + &LLVMGV) + const; +template LLVM_EXPORT_TEMPLATE Function & +GlobalWithNodeAPI:: + 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::LLVMGVToGV::operator()(llvm::GlobalAlias + &LLVMGV) const; + // Explicit instantiations. -template class GlobalWithNodeAPI; -template class GlobalWithNodeAPI; -template class GlobalWithNodeAPI; -template class GlobalWithNodeAPI; +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 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 afaffb70d721a..28456c3cc3538 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::LLVMGVToGV::operator()(llvm::GlobalIFunc + &LLVMGV) + const; +extern template LLVM_TEMPLATE_ABI Function & +GlobalWithNodeAPI:: + 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::LLVMGVToGV::operator()(llvm::GlobalAlias + &LLVMGV) const; + class GlobalIFunc final : public GlobalWithNodeAPI { @@ -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 f86abfda9fd86..d0f2bada75603 100644 --- a/llvm/lib/SandboxIR/Constant.cpp +++ b/llvm/lib/SandboxIR/Constant.cpp @@ -292,6 +292,16 @@ GlobalT &GlobalWithNodeAPI:: return cast(*Ctx.getValue(&LLVMGV)); } +// Explicit instantiations. +template class GlobalWithNodeAPI; +template class GlobalWithNodeAPI; +template class GlobalWithNodeAPI; +template class GlobalWithNodeAPI; + template LLVM_EXPORT_TEMPLATE GlobalIFunc & GlobalWithNodeAPI::LLVMGVToGV::operator()(llvm::GlobalIFunc @@ -310,16 +320,6 @@ GlobalWithNodeAPI::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 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 28456c3cc3538..17f55e973cd76 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::LLVMGVToGV::operator()(llvm::GlobalIFunc diff --git a/llvm/lib/SandboxIR/Constant.cpp b/llvm/lib/SandboxIR/Constant.cpp index d0f2bada75603..13860ae0c56f2 100644 --- a/llvm/lib/SandboxIR/Constant.cpp +++ b/llvm/lib/SandboxIR/Constant.cpp @@ -302,6 +302,7 @@ template class GlobalWithNodeAPI; +// These are needed for SandboxIRTest when building with LLVM_BUILD_LLVM_DYLIB template LLVM_EXPORT_TEMPLATE GlobalIFunc & GlobalWithNodeAPI::LLVMGVToGV::operator()(llvm::GlobalIFunc From d81725bb90effe6c233ae93a2659d449275cb378 Mon Sep 17 00:00:00 2001 From: Thomas Fransham 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 13860ae0c56f2..3e13c935c4281 100644 --- a/llvm/lib/SandboxIR/Constant.cpp +++ b/llvm/lib/SandboxIR/Constant.cpp @@ -302,6 +302,7 @@ template class GlobalWithNodeAPI; +#ifdef _MSC_VER // These are needed for SandboxIRTest when building with LLVM_BUILD_LLVM_DYLIB template LLVM_EXPORT_TEMPLATE GlobalIFunc & GlobalWithNodeAPI::LLVMGVToGV::operator()(llvm::GlobalAlias &LLVMGV) const; +#endif void GlobalIFunc::setResolver(Constant *Resolver) { Ctx.getTracker()