diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index b729c40228b96..31565db1b7929 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -795,6 +795,20 @@ LLVMRustOptimize( CGSCCAnalysisManager CGAM; ModuleAnalysisManager MAM; + if (LLVMPluginsLen) { + auto PluginsStr = StringRef(LLVMPlugins, LLVMPluginsLen); + SmallVector 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()); + return LLVMRustResult::Failure; + } + Plugin->registerPassBuilderCallbacks(PB); + } + } + FAM.registerPass([&] { return PB.buildDefaultAAPipeline(); }); Triple TargetTriple(TheModule->getTargetTriple()); @@ -918,20 +932,6 @@ LLVMRustOptimize( } } - if (LLVMPluginsLen) { - auto PluginsStr = StringRef(LLVMPlugins, LLVMPluginsLen); - SmallVector 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()); - return LLVMRustResult::Failure; - } - Plugin->registerPassBuilderCallbacks(PB); - } - } - ModulePassManager MPM; bool NeedThinLTOBufferPasses = UseThinLTOBuffers; if (!NoPrepopulatePasses) {