diff options
| author | John Brawn <john.brawn@arm.com> | 2016-07-28 17:17:22 +0000 |
|---|---|---|
| committer | John Brawn <john.brawn@arm.com> | 2016-07-28 17:17:22 +0000 |
| commit | 2853269224b098cd13daa68ebaad5bb0c28920fa (patch) | |
| tree | cdaca73d759d52e66cf02d6839db1badb7f47c4f | |
| parent | 8550509b64e671e4ead8dbc0628c54b5f856875f (diff) | |
| download | bcm5719-llvm-2853269224b098cd13daa68ebaad5bb0c28920fa.tar.gz bcm5719-llvm-2853269224b098cd13daa68ebaad5bb0c28920fa.zip | |
Revert r276973 "Adjust Registry interface to not require plugins to export a registry"
Buildbot failures when building with clang -Werror. Reverting while I try to
figure this out.
llvm-svn: 277008
| -rw-r--r-- | clang-tools-extra/clang-tidy/ClangTidy.cpp | 2 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/ClangTidyModuleRegistry.h | 2 | ||||
| -rw-r--r-- | clang/examples/AnnotateFunctions/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | clang/examples/PrintFunctionNames/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | clang/include/clang/Frontend/FrontendPluginRegistry.h | 3 | ||||
| -rw-r--r-- | clang/include/clang/Lex/Preprocessor.h | 2 | ||||
| -rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Tooling/CompilationDatabase.cpp | 2 | ||||
| -rw-r--r-- | llvm/include/llvm/Support/Registry.h | 81 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/GCMetadataPrinter.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/GCStrategy.cpp | 2 |
12 files changed, 71 insertions, 33 deletions
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 562e1e80f54..af1c7f9e61e 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -47,7 +47,7 @@ using namespace clang::driver; using namespace clang::tooling; using namespace llvm; -LLVM_INSTANTIATE_REGISTRY(clang::tidy::ClangTidyModuleRegistry) +template class llvm::Registry<clang::tidy::ClangTidyModule>; namespace clang { namespace tidy { diff --git a/clang-tools-extra/clang-tidy/ClangTidyModuleRegistry.h b/clang-tools-extra/clang-tidy/ClangTidyModuleRegistry.h index dc44d14efe1..de2a3d72494 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyModuleRegistry.h +++ b/clang-tools-extra/clang-tidy/ClangTidyModuleRegistry.h @@ -13,6 +13,8 @@ #include "ClangTidyModule.h" #include "llvm/Support/Registry.h" +extern template class llvm::Registry<clang::tidy::ClangTidyModule>; + namespace clang { namespace tidy { diff --git a/clang/examples/AnnotateFunctions/CMakeLists.txt b/clang/examples/AnnotateFunctions/CMakeLists.txt index 5684abf2380..cf564d527d6 100644 --- a/clang/examples/AnnotateFunctions/CMakeLists.txt +++ b/clang/examples/AnnotateFunctions/CMakeLists.txt @@ -1,4 +1,4 @@ -add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp PLUGIN_TOOL clang) +add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp) if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) target_link_libraries(AnnotateFunctions PRIVATE diff --git a/clang/examples/PrintFunctionNames/CMakeLists.txt b/clang/examples/PrintFunctionNames/CMakeLists.txt index f5f818866ca..5a00d5036fb 100644 --- a/clang/examples/PrintFunctionNames/CMakeLists.txt +++ b/clang/examples/PrintFunctionNames/CMakeLists.txt @@ -9,7 +9,7 @@ if( NOT MSVC ) # MSVC mangles symbols differently, and endif() endif() -add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp PLUGIN_TOOL clang) +add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp) if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) target_link_libraries(PrintFunctionNames PRIVATE diff --git a/clang/include/clang/Frontend/FrontendPluginRegistry.h b/clang/include/clang/Frontend/FrontendPluginRegistry.h index 9d7ee08d95d..ecab630c122 100644 --- a/clang/include/clang/Frontend/FrontendPluginRegistry.h +++ b/clang/include/clang/Frontend/FrontendPluginRegistry.h @@ -13,6 +13,9 @@ #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. diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 000df6647fe..c9b712504e1 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1972,4 +1972,6 @@ typedef llvm::Registry<PragmaHandler> PragmaHandlerRegistry; } // end namespace clang +extern template class llvm::Registry<clang::PragmaHandler>; + #endif diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 2945b8925f9..d2c2a80394d 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -33,7 +33,7 @@ #include <system_error> using namespace clang; -LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry) +template class llvm::Registry<clang::PluginASTAction>; namespace { diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index f0d68725462..8832c7f80c4 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -54,7 +54,7 @@ #include <utility> using namespace clang; -LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry) +template class llvm::Registry<clang::PragmaHandler>; //===----------------------------------------------------------------------===// ExternalPreprocessorSource::~ExternalPreprocessorSource() { } diff --git a/clang/lib/Tooling/CompilationDatabase.cpp b/clang/lib/Tooling/CompilationDatabase.cpp index 6f95bf01f69..8fc4a1fe5be 100644 --- a/clang/lib/Tooling/CompilationDatabase.cpp +++ b/clang/lib/Tooling/CompilationDatabase.cpp @@ -32,8 +32,6 @@ using namespace clang; using namespace tooling; -LLVM_INSTANTIATE_REGISTRY(CompilationDatabasePluginRegistry) - CompilationDatabase::~CompilationDatabase() {} std::unique_ptr<CompilationDatabase> diff --git a/llvm/include/llvm/Support/Registry.h b/llvm/include/llvm/Support/Registry.h index 89c405efd9a..27f025fcd08 100644 --- a/llvm/include/llvm/Support/Registry.h +++ b/llvm/include/llvm/Support/Registry.h @@ -69,14 +69,13 @@ namespace llvm { node(const entry &V) : Next(nullptr), Val(V) {} }; - /// 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); + static void add_node(node *N) { + if (Tail) + Tail->Next = N; + else + Head = N; + Tail = N; + } /// Iterators for registry entries. /// @@ -121,23 +120,61 @@ namespace llvm { 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 -/// Instantiate a registry class. -/// -/// This instantiates add_node and the Head and Tail pointers. -#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \ - namespace llvm { \ - template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Head = nullptr; \ - template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Tail = nullptr; \ - template<> void REGISTRY_CLASS::add_node(REGISTRY_CLASS::node *N) { \ - if (Tail) \ - Tail->Next = N; \ - else \ - Head = N; \ - Tail = N; \ - } \ +#ifdef LLVM_ON_WIN32 +#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS) \ + extern "C" { \ + __declspec(dllexport) void *__cdecl LLVMGetRegistry_##REGISTRY_CLASS() { \ + return REGISTRY_CLASS::exportRegistry(); \ + } \ } +#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 diff --git a/llvm/lib/CodeGen/GCMetadataPrinter.cpp b/llvm/lib/CodeGen/GCMetadataPrinter.cpp index d183c7f2980..bb8cfa1cc80 100644 --- a/llvm/lib/CodeGen/GCMetadataPrinter.cpp +++ b/llvm/lib/CodeGen/GCMetadataPrinter.cpp @@ -14,8 +14,6 @@ #include "llvm/CodeGen/GCMetadataPrinter.h" using namespace llvm; -LLVM_INSTANTIATE_REGISTRY(GCMetadataPrinterRegistry) - GCMetadataPrinter::GCMetadataPrinter() {} GCMetadataPrinter::~GCMetadataPrinter() {} diff --git a/llvm/lib/CodeGen/GCStrategy.cpp b/llvm/lib/CodeGen/GCStrategy.cpp index 31ab86fdf27..554d326942e 100644 --- a/llvm/lib/CodeGen/GCStrategy.cpp +++ b/llvm/lib/CodeGen/GCStrategy.cpp @@ -16,8 +16,6 @@ using namespace llvm; -LLVM_INSTANTIATE_REGISTRY(GCRegistry) - GCStrategy::GCStrategy() : UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false), CustomWriteBarriers(false), CustomRoots(false), InitRoots(true), |

