forked from OSchip/llvm-project
[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
This commit is contained in:
parent
cfb96d845a
commit
434fed5aff
|
@ -132,9 +132,10 @@ bool MIRAddFSDiscriminators::runOnMachineFunction(MachineFunction &MF) {
|
|||
if (!M->getGlobalVariable(FSDiscriminatorVar)) {
|
||||
auto &Context = M->getContext();
|
||||
// Create a global variable to flag that FSDiscriminators are used.
|
||||
new GlobalVariable(*M, Type::getInt1Ty(Context), true,
|
||||
GlobalValue::WeakAnyLinkage,
|
||||
ConstantInt::getTrue(Context), FSDiscriminatorVar);
|
||||
// Using "common" linkage so that it will not gc GC'ed.
|
||||
new GlobalVariable(*M, Type::getInt1Ty(Context), false,
|
||||
GlobalValue::CommonLinkage,
|
||||
ConstantInt::getFalse(Context), FSDiscriminatorVar);
|
||||
}
|
||||
|
||||
LLVM_DEBUG(dbgs() << "Num of FS Discriminators: " << NumNewD << "\n");
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
; RUN: llc -enable-fs-discriminator < %s | FileCheck %s
|
||||
;
|
||||
; Check that fs-afdo discriminators are generated.
|
||||
;; Check that fs-afdo discriminators are generated.
|
||||
; CHECK: .loc 1 7 3 is_stmt 0 discriminator 2 # foo.c:7:3
|
||||
; Check: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
|
||||
; CHECK: .loc 1 9 5 is_stmt 0 discriminator 268435458 # foo.c:9:5
|
||||
; CHECK: .loc 1 7 3 is_stmt 1 discriminator 3892314114 # foo.c:7:3
|
||||
; Check that variable __llvm_fs_discriminator__ is generated.
|
||||
; CHECK: .type __llvm_fs_discriminator__,@object # @__llvm_fs_discriminator__
|
||||
; CHECK: .section .rodata,"a",@progbits
|
||||
; CHECK: .weak __llvm_fs_discriminator__
|
||||
; CHECK: __llvm_fs_discriminator__:
|
||||
; CHECK: .byte 1
|
||||
; CHECK: .size __llvm_fs_discriminator__, 1
|
||||
;; Check that variable __llvm_fs_discriminator__ is generated.
|
||||
; CHECK: .type __llvm_fs_discriminator__,@object
|
||||
; CHECK: .comm __llvm_fs_discriminator__,1,1
|
||||
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
|
|
|
@ -43,12 +43,8 @@
|
|||
; CHECK: .loc 1 23 9 is_stmt 0 discriminator 3623878657 # unroll.c:23:9
|
||||
;;
|
||||
;; Check that variable __llvm_fs_discriminator__ is generated.
|
||||
; CHECK: .type __llvm_fs_discriminator__,@object # @__llvm_fs_discriminator__
|
||||
; CHECK: .section .rodata,"a",@progbits
|
||||
; CHECK: .weak __llvm_fs_discriminator__
|
||||
; CHECK: __llvm_fs_discriminator__:
|
||||
; CHECK: .byte 1
|
||||
; CHECK: .size __llvm_fs_discriminator__, 1
|
||||
; CHECK: .type __llvm_fs_discriminator__,@object
|
||||
; CHECK: .comm __llvm_fs_discriminator__,1,1
|
||||
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
|
|
Loading…
Reference in New Issue