[PATCH] D130889: [llvm] Introduce a pass plugin registry and loader

Philippe Virouleau via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 1 02:19:06 PDT 2022


viroulep created this revision.
viroulep added reviewers: w2yehia, mehdi_amini, pcc.
Herald added subscribers: ormris, steven_wu, hiraditya, arichardson, mgorny, emaste.
Herald added a reviewer: MaskRay.
Herald added a project: All.
viroulep requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, StephenFan.
Herald added projects: clang, LLVM.

This basically extends what has been done for opt in https://reviews.llvm.org/D121566.

The general issue is that, at the moment and except for opt, you can't use command line options defined by plugins when using only -load-pass-plugin (or -fpass-plugin), and you have to also load the library with the "old" entry point through -load to have them recognized.

This is due to the fact that parsing command line options occurs before plugins are loaded through -load-pass-plugin, and basically each tool has its own way of dealing with the loading of pass plugins.
The patch tries to mimic what was done for the existing `-load` command line option and aims at providing common entry points for the lib and tools:

- tools make sure to register the loaded plugin (through the option or manually)
- any part of the lib/tools can query the registry to have the plugins register their callbacks.

As a result -load-pass-plugin has a behavior that matches the -load option, and tools can simply include the header defining the -load-pass-plugin option if they want to have the feature.

I'm not exactly sure why -load-pass-plugin wasn't created with the same behavior as -load, which makes me think I may be missing something: if the implementation I suggest doesn't look good to you I'd be happy to look into something else (hopefully the general idea of having a single load for old/new plugins does sound good to you).

This patch touches a couple of tools (clang, llvm-lto2, opt) in addition to llvm; I tried to include only a couple of appropriate reviewers; my apologies if I missed someone, please feel free to add more relevant people if you think it's necessary!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130889

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInstance.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/test/ELF/lto/ltopasses-extension.ll
  lld/test/lit.cfg.py
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Passes/PassPluginLoader.h
  llvm/include/llvm/Passes/PassPluginRegistry.h
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Passes/CMakeLists.txt
  llvm/lib/Passes/PassPluginLoader.cpp
  llvm/lib/Passes/PassPluginRegistry.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/opt/NewPMDriver.cpp
  llvm/tools/opt/NewPMDriver.h
  llvm/tools/opt/opt.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130889.448948.patch
Type: text/x-patch
Size: 19676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220801/9935c4bd/attachment-0001.bin>


More information about the cfe-commits mailing list