[cmake] Add PCH support for the MSVC dylib build (#242637)

Previously, we were always using a single PCH for every target. This was
not compatible with the MSVC/clang-cl LLVM dylib build because we set
different defines depending on whether we are building the LLVM library
or consuming it, and how.

In order to have working PCH for this build configuration, these changes
add a new property to LLVM targets, LLVM_ABI_MODE, which defines how a
target is built and what its PCH mode is. The mode is "none" for build
configurations that only have a single mode. Otherwise, it is one of
"export", "import" or "static".

When a PCH is created for a target in a mode outside of "none", we also
create the other two PCHs, through a static library with an empty TU.
When looking for a PCH to reuse among dependencies, we then check the
PCH mode. In case of a mismatch, we use the appropriate static library's
PCH, if it exists.

Finally, MSVC requires that the object creating the PCH be linked into
the final image, so this is saved in the LLVM_PCH_VARIANT property so it
can be queried and properly linked later.

Previous effort to fix this regressed the non-dylib PCH build, so
special care was given to benchmark these changes, ensuring no
regression. The following data is taken from a build on recent main,
building clang, clang-tools-extra, lld and lldb:

| Compiler | Dylib | PCH | main (s) | this PR (s) |
|----------|-------|-----|----------|-------------|
| MSVC     | OFF   | OFF | 1249     | 1251        |
| MSVC     | OFF   | ON  | 841      | 835         |
| MSVC     | ON    | OFF | 1362     | 1359        |
| MSVC     | ON    | ON  | N/A      | 857         |
| clang-cl | OFF   | OFF | 586      | 587         |
| clang-cl | OFF   | ON  | 360      | 365         |
| clang-cl | ON    | OFF | 590      | 590         |
| clang-cl | ON    | ON  | N/A      | 365         |

Part of #226993, tracking PCH support for the Windows dylib build.

LLM-aided with Claude Code

GitOrigin-RevId: acf253913c1f4c7a1a082493676e64948f3ff81d
3 files changed