Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions clang/include/clang/Basic/CodeGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

namespace llvm {
class PassBuilder;
class PassPlugin;
}
namespace clang {

Expand Down Expand Up @@ -474,8 +475,11 @@ class CodeGenOptions : public CodeGenOptionsBase {

std::vector<std::string> DefaultFunctionAttrs;

/// List of dynamic shared object files to be loaded as pass plugins.
std::vector<std::string> PassPlugins;
/// List of dynamic shared object file names to be loaded as pass plugins.
std::vector<std::string> PassPluginNames;

/// List of loaded pass plugins.
std::vector<llvm::PassPlugin *> PassPlugins;

/// List of pass builder callbacks.
std::vector<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Options/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4072,7 +4072,7 @@ def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">,
Group<f_Group>, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
MetaVarName<"<dsopath>">, Flags<[NoArgumentUnused]>,
HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">,
MarshallingInfoStringVector<CodeGenOpts<"PassPlugins">>;
MarshallingInfoStringVector<CodeGenOpts<"PassPluginNames">>;
defm tocdata : BoolOption<"m","tocdata",
CodeGenOpts<"AllTocData">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option],
Expand Down
13 changes: 3 additions & 10 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,16 +1017,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
}
#endif
}
// Attempt to load pass plugins and register their callbacks with PB.
for (auto &PluginFN : CodeGenOpts.PassPlugins) {
auto PassPlugin = PassPlugin::Load(PluginFN);
if (PassPlugin) {
PassPlugin->registerPassBuilderCallbacks(PB);
} else {
Diags.Report(diag::err_fe_unable_to_load_plugin)
<< PluginFN << toString(PassPlugin.takeError());
}
}
// Register plugin callbacks with PB.
for (llvm::PassPlugin *Plugin : CodeGenOpts.PassPlugins)
Plugin->registerPassBuilderCallbacks(PB);
for (const auto &PassCallback : CodeGenOpts.PassBuilderCallbacks)
PassCallback(PB);
#define HANDLE_EXTENSION(Ext) \
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Support/AdvisoryLock.h"
#include "llvm/Support/BuryPointer.h"
#include "llvm/Support/CrashRecoveryContext.h"
Expand Down
1 change: 1 addition & 0 deletions clang/lib/FrontendTool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(LLVM_LINK_COMPONENTS
Option
Passes
Support
)

Expand Down
15 changes: 15 additions & 0 deletions clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "clang/StaticAnalyzer/Frontend/AnalyzerHelpFlags.h"
#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Support/BuryPointer.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
Expand Down Expand Up @@ -233,6 +234,20 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {

Clang->LoadRequestedPlugins();

// Load and store pass plugins for the back-end. Store the loaded pass plugins
// here and store references to these in CodeGenOpts to avoid pulling in the
// entire PassPlugin dependency chain in CodeGenOpts.
std::vector<std::unique_ptr<llvm::PassPlugin>> PassPlugins;
for (const std::string &Path : Clang->getCodeGenOpts().PassPluginNames) {
if (auto PassPlugin = llvm::PassPlugin::Load(Path)) {
PassPlugins.emplace_back(std::make_unique<llvm::PassPlugin>(*PassPlugin));
Clang->getCodeGenOpts().PassPlugins.push_back(PassPlugins.back().get());
} else {
Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
<< Path << toString(PassPlugin.takeError());
}
}

// Honor -mllvm.
//
// FIXME: Remove this, one day.
Expand Down
6 changes: 6 additions & 0 deletions clang/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ if(CLANG_BUILD_EXAMPLES AND CLANG_PLUGIN_SUPPORT)
)
endif ()

if(LLVM_BUILD_EXAMPLES AND NOT WIN32)
list(APPEND CLANG_TEST_DEPS
Bye
)
endif()

if(LLVM_INCLUDE_SPIRV_TOOLS_TESTS)
list(APPEND CLANG_TEST_DEPS
spirv-dis
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CodeGen/pass-plugins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang_cc1 -S < %s -fpass-plugin=%llvmshlibdir/Bye%pluginext -O2 2>&1 | FileCheck %s --check-prefix=CHECK-INACTIVE
// RUN: %clang_cc1 -S < %s -fpass-plugin=%llvmshlibdir/Bye%pluginext -O2 -mllvm -wave-goodbye 2>&1 | FileCheck %s --check-prefix=CHECK-ACTIVE
// REQUIRES: plugins, llvm-examples
// UNSUPPORTED: target={{.*windows.*}}
// CHECK-INACTIVE-NOT: Bye
// CHECK-ACTIVE: Bye

int f(int x) {
return x;
}
2 changes: 2 additions & 0 deletions clang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@

if config.clang_examples:
config.available_features.add("examples")
if config.llvm_examples:
config.available_features.add("llvm-examples")


def have_host_out_of_process_jit_feature_support():
Expand Down
1 change: 1 addition & 0 deletions clang/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ config.clang_staticanalyzer_z3 = @LLVM_WITH_Z3@
config.clang_staticanalyzer_z3_mock = @TEST_WITH_Z3_MOCK@
config.clang_enable_cir = @CLANG_ENABLE_CIR@
config.clang_examples = @CLANG_BUILD_EXAMPLES@
config.llvm_examples = @LLVM_BUILD_EXAMPLES@
config.enable_shared = @ENABLE_SHARED@
config.enable_backtrace = @ENABLE_BACKTRACES@
config.enable_threads = @LLVM_ENABLE_THREADS@
Expand Down
Loading