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!
why do we need a lock?
Is there a use case where multiple threads enter this function.
Right now, the only place we create a PassPluginLoader is in cl::opt<PassPluginLoader> PassPlugins.