mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-12 05:47:11 +03:00
Fix loading pass plugins while using the new passmanager. (LLVM >= 14) (#4254)
This commit is contained in:
parent
7707754a03
commit
da3e45f330
9 changed files with 135 additions and 13 deletions
|
@ -17,21 +17,57 @@
|
|||
|
||||
#include "dmd/errors.h"
|
||||
#include "dmd/globals.h"
|
||||
#include "llvm/Passes/PassBuilder.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/Passes/PassPlugin.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
|
||||
#include "driver/cl_options.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
namespace cl = llvm::cl;
|
||||
|
||||
cl::list<std::string>
|
||||
pluginFiles("plugin", cl::CommaSeparated, cl::desc("Plugins to load."),
|
||||
cl::value_desc("dynamic_library.so,lib2.so"));
|
||||
cl::list<std::string> pluginFiles("plugin", cl::CommaSeparated,
|
||||
cl::desc("Pass plugins to load."),
|
||||
cl::value_desc("dynamic_library.so,lib2.so"));
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
/// Loads all plugins. The static constructor of each plugin should take care of
|
||||
/// the plugins registering themself with the rest of LDC/LLVM.
|
||||
void loadAllPlugins() {
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
|
||||
namespace {
|
||||
llvm::SmallVector<llvm::PassPlugin, 1> plugins;
|
||||
}
|
||||
/// Loads all plugins for the new pass manager. These plugins will need to be
|
||||
/// added When building the optimization pipeline.
|
||||
void loadAllPluginsNewPM() {
|
||||
for (auto &filename : pluginFiles) {
|
||||
auto plugin = llvm::PassPlugin::Load(filename);
|
||||
if (!plugin) {
|
||||
error(Loc(), "Error loading plugin '%s': %s", filename.c_str(),
|
||||
llvm::toString(plugin.takeError()).c_str());
|
||||
continue;
|
||||
}
|
||||
plugins.emplace_back(plugin.get());
|
||||
}
|
||||
}
|
||||
void registerAllPluginsWithPassBuilder(llvm::PassBuilder &PB) {
|
||||
for (auto &plugin : plugins) {
|
||||
plugin.registerPassBuilderCallbacks(PB);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // LDC_LLVM_VER >= 1400
|
||||
|
||||
/// Loads all plugins for the legacy pass manaager. The static constructor of
|
||||
/// each plugin should take care of the plugins registering themself with the
|
||||
/// rest of LDC/LLVM.
|
||||
void loadAllPluginsLegacyPM() {
|
||||
for (auto &filename : pluginFiles) {
|
||||
std::string errorString;
|
||||
if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(filename.c_str(),
|
||||
|
@ -42,8 +78,21 @@ void loadAllPlugins() {
|
|||
}
|
||||
}
|
||||
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
void loadAllPlugins() {
|
||||
if (opts::isUsingLegacyPassManager())
|
||||
loadAllPluginsLegacyPM();
|
||||
else
|
||||
loadAllPluginsNewPM();
|
||||
}
|
||||
#else
|
||||
void loadAllPlugins() { loadAllPluginsLegacyPM(); }
|
||||
void registerAllPluginsWithPassBuilder(llvm::PassBuilder &) {}
|
||||
#endif
|
||||
|
||||
#else // #if LDC_ENABLE_PLUGINS
|
||||
|
||||
void loadAllPlugins() {}
|
||||
void registerAllPluginsWithPassBuilder(llvm::PassBuilder &) {}
|
||||
|
||||
#endif // LDC_ENABLE_PLUGINS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue