Now that SamplePGOSupport is part of PGOOpt, there are several places that need tweaking:
- AddDiscriminator pass should *not* be invoked at ThinLTOBackend (as it's already invoked in the PreLink phase)
- addPGOInstrPasses should only be invoked when either ProfileGenFile or ProfileUseFile is non-empty.
- SampleProfileLoaderPass should only be invoked when SampleProfileFile is non-empty.
- PGOIndirectCallPromotion should only be invoked in ProfileUse phase, or in ThinLTOBackend of SamplePGO.
I'd suggest hoisting this into the caller, and its own module-to-function adaptor so we walk the entire module and add discriminators once befare we do anything else. That'll match the other similar "semantic" pass we have where we force certain function attributes.