Add a codegen option to allow loading LLVM pass plugins
This commit is contained in:
parent
4a7fb971c9
commit
97cf461b8f
6 changed files with 30 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue