Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Semantic Analysis plugins #4430

Merged
merged 21 commits into from
Jul 23, 2023
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
08c3371
[NFC] cleanup plugins.cpp a little
JohanEngelen Jun 29, 2023
e86ef5b
Add support for semantic analysis (dlang frontend) plugins.
JohanEngelen Jun 29, 2023
9cf7d91
fixups
JohanEngelen Jun 29, 2023
f1b38d7
Add visitor test plugin
JohanEngelen Jul 5, 2023
c1e895e
fixup non-plugin build
JohanEngelen Jul 5, 2023
89f43fd
fixups
JohanEngelen Jul 5, 2023
fde0bf8
Fix symbol visibility issues on Linux for plugins
JohanEngelen Jul 19, 2023
4256475
Reorder CMakeLists such that LDC_ENABLE_PLUGINS is available when add…
JohanEngelen Jul 19, 2023
86e677a
fixup remnant from testing
JohanEngelen Jul 19, 2023
e566bdb
fixup host version check
JohanEngelen Jul 19, 2023
582ebec
fix python when compiler is not LDC
JohanEngelen Jul 20, 2023
f7dbb67
disable plugin test for macOS x86(-64)
JohanEngelen Jul 20, 2023
82b365e
Increase plugin ABI LDC version. (1.27.1 did not work on my Mac, but …
JohanEngelen Jul 20, 2023
c3b56d7
Add changelog entry, and fix order of plugins vs dcompute.
JohanEngelen Jul 20, 2023
b0d8748
Add ldc-build-plugin tool, and make use of it in plugins lit tests.
JohanEngelen Jul 21, 2023
a643e1d
Update Changelog
JohanEngelen Jul 21, 2023
2c91ab1
try to fix CI by running tests multiple times
JohanEngelen Jul 22, 2023
a45b0d8
Add ldc-build-plugin to cross build packaging
JohanEngelen Jul 22, 2023
e3b605e
Reduce the buildflag impact, try to only make changes when needed (pl…
JohanEngelen Jul 23, 2023
04fa0d5
[really re-add -fvisibility-inlines-hidden on Apple targets]
kinke Jul 23, 2023
64655c2
[fix plugin tests flakiness]
kinke Jul 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions driver/plugins.cpp
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@
//
// Implements functionality related to plugins (`-plugin=...`).
//
// Note: plugins can be LLVM-plugins (to be registered with the pass manager),
// or dlang-plugins for semantic analysis.
//
//===----------------------------------------------------------------------===//

#include "driver/plugins.h"
@@ -38,10 +41,24 @@ cl::list<std::string> pluginFiles("plugin", cl::CommaSeparated,

} // anonymous namespace

/// 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(),
&errorString)) {
error(Loc(), "Error loading plugin '%s': %s", filename.c_str(),
errorString.c_str());
}
}
}

#if LDC_LLVM_VER >= 1400

namespace {
llvm::SmallVector<llvm::PassPlugin, 1> plugins;
llvm::SmallVector<llvm::PassPlugin, 1> llvm_plugins;
}
/// Loads all plugins for the new pass manager. These plugins will need to be
/// added When building the optimization pipeline.
@@ -53,42 +70,28 @@ void loadAllPluginsNewPM() {
llvm::toString(plugin.takeError()).c_str());
continue;
}
plugins.emplace_back(plugin.get());
llvm_plugins.emplace_back(plugin.get());
}
}
void registerAllPluginsWithPassBuilder(llvm::PassBuilder &PB) {
for (auto &plugin : plugins) {
for (auto &plugin : llvm_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(),
&errorString)) {
error(Loc(), "Error loading plugin '%s': %s", filename.c_str(),
errorString.c_str());
}
}
}

#if LDC_LLVM_VER >= 1400
void loadAllPlugins() {
if (opts::isUsingLegacyPassManager())
loadAllPluginsLegacyPM();
else
loadAllPluginsNewPM();
}
#else

#else // LDC_LLVM_VER >= 1400

void loadAllPlugins() { loadAllPluginsLegacyPM(); }
void registerAllPluginsWithPassBuilder(llvm::PassBuilder &) {}
#endif

#endif // LDC_LLVM_VER >= 1400

#else // #if LDC_ENABLE_PLUGINS