diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -867,7 +867,7 @@ // absence of the SHF_LINK_ORDER flag. if (isCounterLinkOrderEnabled()) CounterPtr->setMetadata(LLVMContext::MD_associated, - MDNode::get(Ctx, ValueAsMetadata::get(Fn))); + MDNode::get(Ctx, ValueAsMetadata::get(CounterPtr))); auto *Int8PtrTy = Type::getInt8PtrTy(Ctx); // Allocate statically the array of pointers to value profile nodes for diff --git a/llvm/test/Instrumentation/InstrProfiling/icall.ll b/llvm/test/Instrumentation/InstrProfiling/icall.ll --- a/llvm/test/Instrumentation/InstrProfiling/icall.ll +++ b/llvm/test/Instrumentation/InstrProfiling/icall.ll @@ -60,10 +60,8 @@ ; STATIC-SEXT: declare void @__llvm_profile_instrument_target(i64, i8*, i32 signext) ; METADATA: @__profc_foo = private global [1 x i64] zeroinitializer, section "{{[^"]+}}", align 8, !associated !0 -; METADATA: @__profvp_foo = private global [1 x i64] zeroinitializer, section "{{[^"]+}}", align 8, !associated !1 -; METADATA: @__profc_bar = private global [1 x i64] zeroinitializer, section "{{[^"]+}}", comdat($__profd_bar), align 8, !associated !2 -; METADATA: @__profvp_bar = private global [1 x i64] zeroinitializer, section "{{[^"]+}}", comdat($__profd_bar), align 8, !associated !3 -; METADATA: !0 = !{i32 (i32 ()*)* @foo} -; METADATA: !1 = !{[1 x i64]* @__profc_foo} -; METADATA: !2 = !{i32 (i32 ()*)* @bar} -; METADATA: !3 = !{[1 x i64]* @__profc_bar} +; METADATA: @__profvp_foo = private global [1 x i64] zeroinitializer, section "{{[^"]+}}", align 8, !associated !0 +; METADATA: @__profc_bar = private global [1 x i64] zeroinitializer, section "{{[^"]+}}", comdat($__profd_bar), align 8, !associated !1 +; METADATA: @__profvp_bar = private global [1 x i64] zeroinitializer, section "{{[^"]+}}", comdat($__profd_bar), align 8, !associated !1 +; METADATA: !0 = !{[1 x i64]* @__profc_foo} +; METADATA: !1 = !{[1 x i64]* @__profc_bar} diff --git a/llvm/test/Instrumentation/InstrProfiling/linkage.ll b/llvm/test/Instrumentation/InstrProfiling/linkage.ll --- a/llvm/test/Instrumentation/InstrProfiling/linkage.ll +++ b/llvm/test/Instrumentation/InstrProfiling/linkage.ll @@ -23,7 +23,7 @@ ; POSIX: @__profc_foo = hidden global ; METADATA-SAME: !associated !0 ; POSIX: @__profd_foo = hidden global -; METADATA-SAME: !associated !1 +; METADATA-SAME: !associated !0 ; COFF: @__profc_foo = internal global ; COFF-NOT: comdat ; COFF: @__profd_foo = internal global @@ -33,9 +33,9 @@ } ; POSIX: @__profc_foo_weak = weak hidden global -; METADATA: !associated !2 +; METADATA: !associated !1 ; POSIX: @__profd_foo_weak = weak hidden global -; METADATA: !associated !3 +; METADATA: !associated !1 ; COFF: @__profc_foo_weak = internal global ; COFF: @__profd_foo_weak = internal global define weak void @foo_weak() { @@ -44,9 +44,9 @@ } ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global -; METADATA-SAME: !associated !4 +; METADATA-SAME: !associated !2 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global -; METADATA-SAME: !associated !5 +; METADATA-SAME: !associated !2 ; COFF: @"__profc_linkage.ll:foo_internal" = internal global ; COFF: @"__profd_linkage.ll:foo_internal" = internal global define internal void @foo_internal() { @@ -55,9 +55,9 @@ } ; POSIX: @__profc_foo_inline = linkonce_odr hidden global -; METADATA-SAME: !associated !6 +; METADATA-SAME: !associated !3 ; POSIX: @__profd_foo_inline = linkonce_odr hidden global -; METADATA-SAME: !associated !7 +; METADATA-SAME: !associated !3 ; COFF: @__profc_foo_inline = internal global{{.*}} section ".lprfc$M", align 8 ; COFF: @__profd_foo_inline = internal global{{.*}} section ".lprfd$M", align 8 define linkonce_odr void @foo_inline() { @@ -66,9 +66,9 @@ } ; LINUX: @__profc_foo_extern = linkonce_odr hidden global {{.*}}section "__llvm_prf_cnts", comdat($__profd_foo_extern), align 8 -; METADATA-SAME: !associated !8 +; METADATA-SAME: !associated !4 ; LINUX: @__profd_foo_extern = linkonce_odr hidden global {{.*}}section "__llvm_prf_data", comdat, align 8 -; METADATA-SAME: !associated !9 +; METADATA-SAME: !associated !4 ; MACHO: @__profc_foo_extern = linkonce_odr hidden global ; MACHO: @__profd_foo_extern = linkonce_odr hidden global ; COFF: @__profc_foo_extern = linkonce_odr hidden global {{.*}}section ".lprfc$M", comdat, align 8 @@ -88,13 +88,8 @@ ; LINUX-NOT: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() {{.*}} { ; LINUX-NOT: %[[REG:.*]] = load i32, i32* @__llvm_profile_runtime -; METADATA: !0 = !{void ()* @foo} -; METADATA: !1 = !{[1 x i64]* @__profc_foo} -; METADATA: !2 = !{void ()* @foo_weak} -; METADATA: !3 = !{[1 x i64]* @__profc_foo_weak} -; METADATA: !4 = !{void ()* @foo_internal} -; METADATA: !5 = !{[1 x i64]* @"__profc_linkage.ll:foo_internal"} -; METADATA: !6 = !{void ()* @foo_inline} -; METADATA: !7 = !{[1 x i64]* @__profc_foo_inline} -; METADATA: !8 = !{void ()* @foo_extern} -; METADATA: !9 = !{[1 x i64]* @__profc_foo_extern} +; METADATA: !0 = !{[1 x i64]* @__profc_foo} +; METADATA: !1 = !{[1 x i64]* @__profc_foo_weak} +; METADATA: !2 = !{[1 x i64]* @"__profc_linkage.ll:foo_internal"} +; METADATA: !3 = !{[1 x i64]* @__profc_foo_inline} +; METADATA: !4 = !{[1 x i64]* @__profc_foo_extern} diff --git a/llvm/test/Transforms/PGOProfile/associated.ll b/llvm/test/Transforms/PGOProfile/associated.ll --- a/llvm/test/Transforms/PGOProfile/associated.ll +++ b/llvm/test/Transforms/PGOProfile/associated.ll @@ -2,11 +2,10 @@ ; RUN: opt < %s -passes=pgo-instr-gen,instrprof -counter-link-order -S | FileCheck %s ; CHECK: @__profc_foo = private global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8, !associated !0 -; CHECK: @__profd_foo = private global {{.*}}, section "__llvm_prf_data", align 8, !associated !1 +; CHECK: @__profd_foo = private global {{.*}}, section "__llvm_prf_data", align 8, !associated !0 define void @foo() { ret void } -; CHECK: !0 = !{void ()* @foo} -; CHECK: !1 = !{[1 x i64]* @__profc_foo} +; CHECK: !0 = !{[1 x i64]* @__profc_foo}