Index: flang/lib/Frontend/CMakeLists.txt =================================================================== --- flang/lib/Frontend/CMakeLists.txt +++ flang/lib/Frontend/CMakeLists.txt @@ -42,6 +42,7 @@ LINK_COMPONENTS Passes Analysis + Extensions IRReader Option Support Index: flang/lib/Frontend/FrontendActions.cpp =================================================================== --- flang/lib/Frontend/FrontendActions.cpp +++ flang/lib/Frontend/FrontendActions.cpp @@ -48,6 +48,7 @@ #include "llvm/IRReader/IRReader.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Passes/PassBuilder.h" +#include "llvm/Passes/PassPlugin.h" #include "llvm/Passes/StandardInstrumentations.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/SourceMgr.h" @@ -56,6 +57,11 @@ using namespace Fortran::frontend; +// Declare plugin extension function declarations. +#define HANDLE_EXTENSION(Ext) \ + llvm::PassPluginLibraryInfo get##Ext##PluginInfo(); +#include "llvm/Support/Extension.def" + //===----------------------------------------------------------------------===// // Custom BeginSourceFileAction //===----------------------------------------------------------------------===// @@ -691,6 +697,11 @@ si.registerCallbacks(pic, &fam); llvm::PassBuilder pb(tm.get(), pto, pgoOpt, &pic); + // Register static plugin extensions. +#define HANDLE_EXTENSION(Ext) \ + get##Ext##PluginInfo().RegisterPassBuilderCallbacks(pb); +#include "llvm/Support/Extension.def" + // Register all the basic analyses with the managers. pb.registerModuleAnalyses(mam); pb.registerCGSCCAnalyses(cgam); Index: flang/test/CMakeLists.txt =================================================================== --- flang/test/CMakeLists.txt +++ flang/test/CMakeLists.txt @@ -5,6 +5,7 @@ llvm_canonicalize_cmake_booleans( FLANG_BUILD_EXAMPLES FLANG_STANDALONE_BUILD + LLVM_BYE_LINK_INTO_TOOLS LLVM_ENABLE_PLUGINS ) @@ -64,6 +65,10 @@ FortranDecimal ) +if (LLVM_ENABLE_PLUGINS AND NOT WIN32) + list(APPEND FLANG_TEST_DEPENDS Bye) +endif() + if (FLANG_INCLUDE_TESTS) if (FLANG_GTEST_AVAIL) list(APPEND FLANG_TEST_DEPENDS FlangUnitTests) Index: flang/test/Driver/pass-plugin.f90 =================================================================== --- /dev/null +++ flang/test/Driver/pass-plugin.f90 @@ -0,0 +1,17 @@ +! Verify that the static and dynamically loaded pass plugins work as expected. + +! UNSUPPORTED: system-windows +! TODO: Remove staticbye dependency once -fpass-plugin= option is supported. +! REQUIRES: plugins, shell, staticbye + +! RUN: %flang -S %s %loadbye -Xflang -fdebug-pass-manager -o /dev/null \ +! RUN: 2>&1 | FileCheck %s + +! RUN: %flang_fc1 -S %s %loadbye -fdebug-pass-manager -o /dev/null \ +! RUN: 2>&1 | FileCheck %s + + +! CHECK: Running pass: {{.*}}Bye on empty_ + +subroutine empty +end subroutine empty Index: flang/test/lit.cfg.py =================================================================== --- flang/test/lit.cfg.py +++ flang/test/lit.cfg.py @@ -58,6 +58,14 @@ if config.has_plugins: config.available_features.add('plugins') +if config.linked_bye_extension: + config.available_features.add('staticbye') + config.substitutions.append(('%loadbye', '')) +else: + config.substitutions.append(('%loadbye', + '-fpass-plugin={}/Bye{}'.format(config.llvm_shlib_dir, + config.llvm_plugin_ext))) + # test_source_root: The root path where tests are located. config.test_source_root = os.path.dirname(__file__) Index: flang/test/lit.site.cfg.py.in =================================================================== --- flang/test/lit.site.cfg.py.in +++ flang/test/lit.site.cfg.py.in @@ -17,6 +17,7 @@ config.python_executable = "@PYTHON_EXECUTABLE@" config.flang_standalone_build = @FLANG_STANDALONE_BUILD@ config.has_plugins = @LLVM_ENABLE_PLUGINS@ +config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@ config.cc = "@CMAKE_C_COMPILER@" config.targets_to_build = "@TARGETS_TO_BUILD@"