about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
diff options
context:
space:
mode:
authorAxel Cohen <axel.cohen@eshard.com>2021-11-19 17:01:41 +0100
committerAxel Cohen <axel.cohen@eshard.com>2021-12-13 10:40:44 +0100
commit97cf461b8f4c0ed0de8fdc1c441b904ddb8b3194 (patch)
tree436752a1ffb01de4304b68790df0579062e3b10d /compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
parent4a7fb971c939d268abdbd0963cd45d046442f7af (diff)
downloadrust-97cf461b8f4c0ed0de8fdc1c441b904ddb8b3194.tar.gz
rust-97cf461b8f4c0ed0de8fdc1c441b904ddb8b3194.zip
Add a codegen option to allow loading LLVM pass plugins
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp')
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
index 4f77db8a24d..32a2ffcef00 100644
--- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Object/IRObjectFile.h"
 #include "llvm/Passes/PassBuilder.h"
+#include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
 #include "llvm/Support/CBindingWrapping.h"
 #include "llvm/Support/FileSystem.h"
@@ -753,7 +754,8 @@ LLVMRustOptimizeWithNewPassManager(
     void* LlvmSelfProfiler,
     LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
     LLVMRustSelfProfileAfterPassCallback AfterPassCallback,
-    const char *ExtraPasses, size_t ExtraPassesLen) {
+    const char *ExtraPasses, size_t ExtraPassesLen,
+    const char *PassPlugins, size_t PassPluginsLen) {
   Module *TheModule = unwrap(ModuleRef);
   TargetMachine *TM = unwrap(TMRef);
   OptimizationLevel OptLevel = fromRust(OptLevelRust);
@@ -924,6 +926,20 @@ LLVMRustOptimizeWithNewPassManager(
     }
   }
 
+  if (PassPluginsLen) {
+    auto PluginsStr = StringRef(PassPlugins, PassPluginsLen);
+    SmallVector<StringRef> Plugins;
+    PluginsStr.split(Plugins, ' ', -1, false);
+    for (auto PluginPath: Plugins) {
+      auto Plugin = PassPlugin::Load(PluginPath.str());
+      if (!Plugin) {
+        LLVMRustSetLastError(("Failed to load pass plugin" + PluginPath.str()).c_str());
+        continue;
+      }
+      Plugin->registerPassBuilderCallbacks(PB);
+    }
+  }
+
 #if LLVM_VERSION_GE(13, 0)
   ModulePassManager MPM;
 #else