|
17 | 17 | #include "llvm/Object/ObjectFile.h"
|
18 | 18 | #include "llvm/Object/IRObjectFile.h"
|
19 | 19 | #include "llvm/Passes/PassBuilder.h"
|
| 20 | +#include "llvm/Passes/PassPlugin.h" |
20 | 21 | #include "llvm/Passes/StandardInstrumentations.h"
|
21 | 22 | #include "llvm/Support/CBindingWrapping.h"
|
22 | 23 | #include "llvm/Support/FileSystem.h"
|
@@ -753,7 +754,8 @@ LLVMRustOptimizeWithNewPassManager(
|
753 | 754 | void* LlvmSelfProfiler,
|
754 | 755 | LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
|
755 | 756 | LLVMRustSelfProfileAfterPassCallback AfterPassCallback,
|
756 |
| - const char *ExtraPasses, size_t ExtraPassesLen) { |
| 757 | + const char *ExtraPasses, size_t ExtraPassesLen, |
| 758 | + const char *PassPlugins, size_t PassPluginsLen) { |
757 | 759 | Module *TheModule = unwrap(ModuleRef);
|
758 | 760 | TargetMachine *TM = unwrap(TMRef);
|
759 | 761 | OptimizationLevel OptLevel = fromRust(OptLevelRust);
|
@@ -924,6 +926,20 @@ LLVMRustOptimizeWithNewPassManager(
|
924 | 926 | }
|
925 | 927 | }
|
926 | 928 |
|
| 929 | + if (PassPluginsLen) { |
| 930 | + auto PluginsStr = StringRef(PassPlugins, PassPluginsLen); |
| 931 | + SmallVector<StringRef> Plugins; |
| 932 | + PluginsStr.split(Plugins, ' ', -1, false); |
| 933 | + for (auto PluginPath: Plugins) { |
| 934 | + auto Plugin = PassPlugin::Load(PluginPath.str()); |
| 935 | + if (!Plugin) { |
| 936 | + LLVMRustSetLastError(("Failed to load pass plugin" + PluginPath.str()).c_str()); |
| 937 | + continue; |
| 938 | + } |
| 939 | + Plugin->registerPassBuilderCallbacks(PB); |
| 940 | + } |
| 941 | + } |
| 942 | + |
927 | 943 | #if LLVM_VERSION_GE(13, 0)
|
928 | 944 | ModulePassManager MPM;
|
929 | 945 | #else
|
|
0 commit comments