This revision was automatically updated to reflect the committed changes. Closed by commit rL276856: Adjust Registry interface to not require plugins to export a registry (authored by john.brawn).
Repository: rL LLVM https://reviews.llvm.org/D21385 Files: cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h cfe/trunk/include/clang/Lex/Preprocessor.h cfe/trunk/lib/Frontend/FrontendAction.cpp cfe/trunk/lib/Lex/Preprocessor.cpp cfe/trunk/lib/Tooling/CompilationDatabase.cpp llvm/trunk/include/llvm/Support/Registry.h llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp llvm/trunk/lib/CodeGen/GCStrategy.cpp
Index: llvm/trunk/include/llvm/Support/Registry.h =================================================================== --- llvm/trunk/include/llvm/Support/Registry.h +++ llvm/trunk/include/llvm/Support/Registry.h @@ -69,13 +69,14 @@ node(const entry &V) : Next(nullptr), Val(V) {} }; - static void add_node(node *N) { - if (Tail) - Tail->Next = N; - else - Head = N; - Tail = N; - } + /// Add a node to the Registry: this is the interface between the plugin and + /// the executable. + /// + /// This function is exported by the executable and called by the plugin to + /// add a node to the executable's registry. Therefore it's not defined here + /// to avoid it being instantiated in the plugin and is instead defined in + /// the executable (see LLVM_INSTANTIATE_REGISTRY below). + static void add_node(node *N); /// Iterators for registry entries. /// @@ -120,61 +121,23 @@ add_node(&Node); } }; - - /// A dynamic import facility. This is used on Windows to - /// import the entries added in the plugin. - static void import(sys::DynamicLibrary &DL, const char *RegistryName) { - typedef void *(*GetRegistry)(); - std::string Name("LLVMGetRegistry_"); - Name.append(RegistryName); - GetRegistry Getter = - (GetRegistry)(intptr_t)DL.getAddressOfSymbol(Name.c_str()); - if (Getter) { - // Call the getter function in order to get the full copy of the - // registry defined in the plugin DLL, and copy them over to the - // current Registry. - typedef std::pair<const node *, const node *> Info; - Info *I = static_cast<Info *>(Getter()); - iterator begin(I->first); - iterator end(I->second); - for (++end; begin != end; ++begin) { - // This Node object needs to remain alive for the - // duration of the program. - add_node(new node(*begin)); - } - } - } - - /// Retrieve the data to be passed across DLL boundaries when - /// importing registries from another DLL on Windows. - static void *exportRegistry() { - static std::pair<const node *, const node *> Info(Head, Tail); - return &Info; - } }; - - - // Since these are defined in a header file, plugins must be sure to export - // these symbols. - template <typename T> - typename Registry<T>::node *Registry<T>::Head; - - template <typename T> - typename Registry<T>::node *Registry<T>::Tail; } // end namespace llvm -#ifdef LLVM_ON_WIN32 -#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS) \ - extern "C" { \ - __declspec(dllexport) void *__cdecl LLVMGetRegistry_##REGISTRY_CLASS() { \ - return REGISTRY_CLASS::exportRegistry(); \ - } \ +/// Instantiate a registry class. +/// +/// This instantiates add_node and the Head and Tail pointers. +#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \ + namespace llvm { \ + template<> void REGISTRY_CLASS::add_node(REGISTRY_CLASS::node *N) { \ + if (Tail) \ + Tail->Next = N; \ + else \ + Head = N; \ + Tail = N; \ + } \ + template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Head = nullptr; \ + template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Tail = nullptr; \ } -#define LLVM_IMPORT_REGISTRY(REGISTRY_CLASS, DL) \ - REGISTRY_CLASS::import(DL, #REGISTRY_CLASS) -#else -#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS) -#define LLVM_IMPORT_REGISTRY(REGISTRY_CLASS, DL) -#endif #endif // LLVM_SUPPORT_REGISTRY_H Index: llvm/trunk/lib/CodeGen/GCStrategy.cpp =================================================================== --- llvm/trunk/lib/CodeGen/GCStrategy.cpp +++ llvm/trunk/lib/CodeGen/GCStrategy.cpp @@ -16,6 +16,8 @@ using namespace llvm; +LLVM_INSTANTIATE_REGISTRY(GCRegistry) + GCStrategy::GCStrategy() : UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false), CustomWriteBarriers(false), CustomRoots(false), InitRoots(true), Index: llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp =================================================================== --- llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp +++ llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp @@ -14,6 +14,8 @@ #include "llvm/CodeGen/GCMetadataPrinter.h" using namespace llvm; +LLVM_INSTANTIATE_REGISTRY(GCMetadataPrinterRegistry) + GCMetadataPrinter::GCMetadataPrinter() {} GCMetadataPrinter::~GCMetadataPrinter() {} Index: cfe/trunk/include/clang/Lex/Preprocessor.h =================================================================== --- cfe/trunk/include/clang/Lex/Preprocessor.h +++ cfe/trunk/include/clang/Lex/Preprocessor.h @@ -1956,6 +1956,4 @@ } // end namespace clang -extern template class llvm::Registry<clang::PragmaHandler>; - #endif Index: cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h =================================================================== --- cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h +++ cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h @@ -13,9 +13,6 @@ #include "clang/Frontend/FrontendAction.h" #include "llvm/Support/Registry.h" -// Instantiated in FrontendAction.cpp. -extern template class llvm::Registry<clang::PluginASTAction>; - namespace clang { /// The frontend plugin registry. Index: cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt =================================================================== --- cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt +++ cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt @@ -9,7 +9,7 @@ endif() endif() -add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp) +add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp PLUGIN_TOOL clang) if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) target_link_libraries(PrintFunctionNames PRIVATE Index: cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt =================================================================== --- cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt +++ cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt @@ -1,4 +1,4 @@ -add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp) +add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp PLUGIN_TOOL clang) if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) target_link_libraries(AnnotateFunctions PRIVATE Index: cfe/trunk/lib/Lex/Preprocessor.cpp =================================================================== --- cfe/trunk/lib/Lex/Preprocessor.cpp +++ cfe/trunk/lib/Lex/Preprocessor.cpp @@ -54,7 +54,7 @@ #include <utility> using namespace clang; -template class llvm::Registry<clang::PragmaHandler>; +LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry) //===----------------------------------------------------------------------===// ExternalPreprocessorSource::~ExternalPreprocessorSource() { } Index: cfe/trunk/lib/Frontend/FrontendAction.cpp =================================================================== --- cfe/trunk/lib/Frontend/FrontendAction.cpp +++ cfe/trunk/lib/Frontend/FrontendAction.cpp @@ -33,7 +33,7 @@ #include <system_error> using namespace clang; -template class llvm::Registry<clang::PluginASTAction>; +LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry) namespace { Index: cfe/trunk/lib/Tooling/CompilationDatabase.cpp =================================================================== --- cfe/trunk/lib/Tooling/CompilationDatabase.cpp +++ cfe/trunk/lib/Tooling/CompilationDatabase.cpp @@ -32,6 +32,8 @@ using namespace clang; using namespace tooling; +LLVM_INSTANTIATE_REGISTRY(CompilationDatabasePluginRegistry) + CompilationDatabase::~CompilationDatabase() {} std::unique_ptr<CompilationDatabase>
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits