[SampleFDO] Using common linkage for the discriminator flag variable
authorRong Xu <xur@google.com>
Tue, 15 Jun 2021 19:32:03 +0000 (12:32 -0700)
committerRong Xu <xur@google.com>
Tue, 15 Jun 2021 21:51:27 +0000 (14:51 -0700)
commit434fed5aff5e62460e2e984c7cc2674c12779b1e
treea935cfd6c1f0d42b2dcb4f3d7f47ed6d737584a1
parentcfb96d845a684a5c567823dbe2aa4392937ee979
[SampleFDO] Using common linkage for the discriminator flag variable

We create flag variable "__llvm_fs_discriminator__" in the binary
to indicate that FSAFDO hierarchical discriminators are used.

This variable might be GC'ed by the linker since it is not explicitly
reference. I initially added the var to the use list in pass
MIRFSDiscriminator but it did not work. It turned out the used global
list is collected in lowering (before MIR pass) and then emitted in
the end of pass pipeline.

In this patch, we use a "common" linkage for this variable so that
it will be GC'ed by the linker.

Differential Revision: https://reviews.llvm.org/D103988
llvm/lib/CodeGen/MIRFSDiscriminator.cpp
llvm/test/CodeGen/X86/fsafdo_test1.ll
llvm/test/CodeGen/X86/fsafdo_test2.ll