[TypeProf][InstrFDO]Implement more efficient comparison sequence for
indirect-call-promotion with vtable profiles.
Clang's `-fwhole-program-vtables` is required for this optimization to
take place. If `-fwhole-program-vtables` is not enabled, this change is
no-op.
Function-comparison (before):
VTable-comparison (after):
Key changes:
1. Find out virtual calls and the vtables they come from.
- The ICP relies on type intrinsic `llvm.type.test` and
`llvm.public.type.test` to find out virtual calls and the
compatible vtables, and relies on type metadata to find the address
point (offset) for comparison.
2. ICP pass does cost-benefit analysis and compares vtable only when
both conditions are met
1) The function addressing and vtable load can sink to indirect
fallback, and the indirect fallback is cold block
2) The number of vtables for a function candidate is within
(option specified) threshold.
3. Sink the function addressing and vtable load instruction to indirect
fallback.
- The sink helper functions are simplified versions of
`InstCombinerImpl::tryToSinkInstruction`.
- The helper functions to handle debug intrinsics are copied from
`InstCombinerImpl::tryToSinkInstructionDbgValues` and
`InstCombinerImpl::tryToSinkInstructionDbgVariableRecords` into
Transforms/Utils/Local.cpp. Ideally only one copy should exist
for inst-combine, icp and other passes.
4. Keep value profiles updated
1) Update vtable value profiles after inline
2) For either function-based comparison or vtable-based comparison,
update both vtable and indirect call value profiles.