[PATCH] D85299: [llvm] Support autoloading vendor-defined plugins

Michał Górny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 06:30:19 PDT 2020


mgorny created this revision.
mgorny added reviewers: chandlerc, grosser, Meinersbur, jdoerfert, MaskRay.
Herald added a reviewer: bollu.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
mgorny requested review of this revision.

Provide a new LLVM_AUTOLOAD_PLUGINS CMake variable to specify plugins
that LLVM should attempt to load automatically.  This is going
to be used to make it possible for LLVM to automatically take advantage
of installed Polly plugin without requiring it to be unconditionally
present at build or runtime.


https://reviews.llvm.org/D85299

Files:
  llvm/CMakeLists.txt
  llvm/include/llvm/Config/config.h.cmake
  llvm/lib/Support/PluginLoader.cpp


Index: llvm/lib/Support/PluginLoader.cpp
===================================================================
--- llvm/lib/Support/PluginLoader.cpp
+++ llvm/lib/Support/PluginLoader.cpp
@@ -12,6 +12,7 @@
 
 #define DONT_GET_PLUGIN_LOADER_OPTION
 #include "llvm/Support/PluginLoader.h"
+#include "llvm/Config/config.h"
 #include "llvm/Support/DynamicLibrary.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
@@ -44,3 +45,22 @@
          "Asking for an out of bounds plugin");
   return (*Plugins)[num];
 }
+
+struct PluginAutoLoader {
+  PluginAutoLoader() {
+    SmallVector<StringRef, 4> PluginList;
+    StringRef(LLVM_AUTOLOAD_PLUGINS).split(PluginList, ';', -1, false);
+
+    for (auto &Val : PluginList) {
+      sys::SmartScopedLock<true> Lock(*PluginsLock);
+      std::string Filename = Val.str();
+      std::string Error;
+      if (!sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(),
+                                                       &Error)) {
+        Plugins->push_back(Filename);
+      }
+    }
+  }
+};
+
+static PluginAutoLoader AutoPlugins;
Index: llvm/include/llvm/Config/config.h.cmake
===================================================================
--- llvm/include/llvm/Config/config.h.cmake
+++ llvm/include/llvm/Config/config.h.cmake
@@ -344,4 +344,7 @@
 /* Whether Timers signpost passes in Xcode Instruments */
 #cmakedefine01 LLVM_SUPPORT_XCODE_SIGNPOSTS
 
+/* Define to the list of plugins to autoload */
+#define LLVM_AUTOLOAD_PLUGINS "${LLVM_AUTOLOAD_PLUGINS}"
+
 #endif
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -669,6 +669,10 @@
 endif()
 option(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default})
 
+set(LLVM_AUTOLOAD_PLUGINS "" CACHE STRING
+    "List of plugin paths to attempt autoloading")
+mark_as_advanced(LLVM_AUTOLOAD_PLUGINS)
+
 include(HandleLLVMOptions)
 
 if(CMAKE_VERSION VERSION_LESS 3.12)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85299.283214.patch
Type: text/x-patch
Size: 2014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200805/fc3b7126/attachment.bin>


More information about the llvm-commits mailing list