Add plugin support (#15169)
Add plugin support and pass LLVM arguments after plugins have been loaded.
This commit is contained in:
parent
3750135c31
commit
f9b7ba1430
@ -74,6 +74,9 @@ namespace cling {
|
||||
///\brief The remaining arguments to pass to clang.
|
||||
///
|
||||
std::vector<const char*> Remaining;
|
||||
|
||||
/// A list of arguments to forward to LLVM's option processing.
|
||||
std::vector<std::string> LLVMArgs;
|
||||
};
|
||||
|
||||
class InvocationOptions {
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/IR/Verifier.h"
|
||||
#include "llvm/Passes/PassBuilder.h"
|
||||
#include "llvm/Passes/PassPlugin.h"
|
||||
#include "llvm/Passes/StandardInstrumentations.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Transforms/IPO.h"
|
||||
@ -399,6 +400,14 @@ void BackendPasses::CreatePasses(int OptLevel, llvm::ModulePassManager& MPM,
|
||||
std::optional<PGOOptions> PGOOpt;
|
||||
PassBuilder PB(&m_TM, PTO, PGOOpt, &PIC);
|
||||
|
||||
// Attempt to load pass plugins and register their callbacks with PB.
|
||||
for (auto& PluginFN : m_CGOpts.PassPlugins) {
|
||||
auto PassPlugin = PassPlugin::Load(PluginFN);
|
||||
if (PassPlugin) {
|
||||
PassPlugin->registerPassBuilderCallbacks(PB);
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_CGOpts.DisableLLVMPasses) {
|
||||
// Use the default pass pipeline. We also have to map our optimization
|
||||
// levels into one of the distinct levels used to configure the pipeline.
|
||||
|
@ -220,6 +220,21 @@ namespace cling {
|
||||
if (!m_IncrParser->isValid(false))
|
||||
return;
|
||||
|
||||
// Load any requested plugins.
|
||||
getCI()->LoadRequestedPlugins();
|
||||
|
||||
// Honor set of `-mllvm` options. This should happen AFTER plugins have been
|
||||
// loaded!
|
||||
if (!m_Opts.CompilerOpts.LLVMArgs.empty()) {
|
||||
unsigned NumArgs = m_Opts.CompilerOpts.LLVMArgs.size();
|
||||
auto Args = std::make_unique<const char*[]>(NumArgs + 2);
|
||||
Args[0] = "cling (LLVM option parsing)";
|
||||
for (unsigned i = 0; i != NumArgs; ++i)
|
||||
Args[i + 1] = m_Opts.CompilerOpts.LLVMArgs[i].c_str();
|
||||
Args[NumArgs + 1] = nullptr;
|
||||
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
|
||||
}
|
||||
|
||||
// Initialize the opt level to what CodeGenOpts says.
|
||||
if (m_OptLevel == -1)
|
||||
setDefaultOptLevel(getCI()->getCodeGenOpts().OptimizationLevel);
|
||||
|
@ -159,9 +159,6 @@ void CompilerOptions::Parse(int argc, const char* const argv[],
|
||||
MissingArgCount, 0,
|
||||
options::NoDriverOption | options::CLOption | options::DXCOption));
|
||||
|
||||
std::vector<const char*> LLVMArgs;
|
||||
LLVMArgs.push_back("cling (LLVM option parsing)");
|
||||
|
||||
for (const Arg* arg : Args) {
|
||||
switch (arg->getOption().getID()) {
|
||||
// case options::OPT_d_Flag:
|
||||
@ -202,12 +199,6 @@ void CompilerOptions::Parse(int argc, const char* const argv[],
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check that there were LLVM arguments, other than the first dummy entry.
|
||||
if (LLVMArgs.size() > 1) {
|
||||
LLVMArgs.push_back(nullptr);
|
||||
llvm::cl::ParseCommandLineOptions(LLVMArgs.size() - 1, LLVMArgs.data());
|
||||
}
|
||||
}
|
||||
|
||||
bool CompilerOptions::DefaultLanguage(const LangOptions* LangOpts) const {
|
||||
|
Loading…
Reference in New Issue
Block a user