[llvm] [LTO] Enable adding custom pass instrumentation callbacks (PR #71268)

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 27 17:01:20 PST 2023


igorkudrin wrote:

> Can you clarify what you meant by "These are command-line options and their variables are local to the TU. There is no API to access them from other components." Because if you have a tool that is built like llvm-lto2 etc using LLVM libraries, you should be able to parse the internal command line options passed to it. I'm not sure what is TU local about them?

Let's take `-enable-npm-synthetic-counts` as an example:
```c++
static cl::opt<bool> EnableSyntheticCounts("enable-npm-synthetic-counts", ...);
```

This is a command line option, so a user may be able to specify it on the command line when running the tool. This is suitable for developer-level tools like `opt`, `llc`, etc., but does not work well for a user-level tool that has its own options and hides the implementation details. As for our tool, we should not rely on a user to specify the option; moreover, we disable internal options with `cl::HideUnrelatedOptions()`.

The variable for this option is `static`, so only `PassBuilderPipelines.cpp` can access it.

If we make the variable `external`, or provide a function that can be called from another translation unit to set the value of the option, this would mean that we are trying to communicate with the `PassBuilder` through a global state, which is hardly a good design choice.

https://github.com/llvm/llvm-project/pull/71268


More information about the llvm-commits mailing list