[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-03 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: compiler-rt/test/profile/instrprof-gc-sections.c:30
+// RUN: llvm-nm -jgU %t | grep -vE "main|_start|_IO_stdin_used|__libc_.*" > 
%t.code.syms
+// RUN: diff %t.nocode.syms %t.code.syms
+

phosek wrote:
> MaskRay wrote:
> > This fails on my machine (cc @akuegel). If I use `diff -u`:
> > 
> > ```
> > --- 
> > /tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.nocode.syms
> >2021-02-01 22:14:22.850222346 -0800
> > +++ 
> > /tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.code.syms
> >  2021-02-01 22:14:22.854222358 -0800
> > @@ -3,6 +3,5 @@
> >  __prof_cnts_sect_data
> >  __prof_data_sect_data
> >  __prof_nms_sect_data
> > -__prof_orderfile_sect_data
> >  __prof_vnodes_sect_data
> >  lprofDirMode
> > ```
> > 
> > At the worst we can temporarily disable it (if others report issues as 
> > well).
> What's your build setup? I ran `check-profile` on my Linux workstation just 
> now but haven't seen this issue.
This also fails on my machine:
$ cmake -GNinja -DLLVM_ENABLE_PROJECTS='clang;compiler-rt;lld' 
-DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_LLD=ON ..
$ ninja check-profile


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-02 Thread Petr Hosek via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG97ba5cde5266: [InstrProfiling] Use !associated metadata for 
counters, data and values (authored by phosek).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/test/CMakeLists.txt
  compiler-rt/test/profile/CMakeLists.txt
  compiler-rt/test/profile/instrprof-gc-sections.c
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/icall.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll
  llvm/test/Transforms/PGOProfile/associated.ll
  llvm/test/Transforms/PGOProfile/counter_promo.ll
  llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Index: llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
@@ -69,7 +69,7 @@
 ; PROMO-NEXT:  %pgocount{{.*}} = load {{.*}} @__profc_foo{{.*}} 4)
 ; PROMO-NEXT: add 
 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}4)
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 bb15: ; preds = %bb14, %bb4
Index: llvm/test/Transforms/PGOProfile/counter_promo.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo.ll
@@ -60,7 +60,7 @@
 ; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}0), i64 %[[LIVEOUT1]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 }
Index: llvm/test/Transforms/PGOProfile/associated.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/associated.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -pgo-instr-gen -instrprof -counter-link-order -S | FileCheck %s
+; 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
+
+define void @foo() {
+  ret void
+}
+
+; CHECK: !0 = !{void ()* @foo}
+; CHECK: !1 = !{[1 x i64]* @__profc_foo}
Index: llvm/test/Instrumentation/InstrProfiling/linkage.ll
===
--- llvm/test/Instrumentation/InstrProfiling/linkage.ll
+++ llvm/test/Instrumentation/InstrProfiling/linkage.ll
@@ -8,6 +8,8 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s -mtriple=x86_64-unknown-fuchsia -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
 
 ; MACHO: @__llvm_profile_runtime = external global i32
 ; LINUX-NOT: @__llvm_profile_runtime = external global i32
@@ -19,7 +21,9 @@
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
 
 ; POSIX: @__profc_foo = hidden global
+; METADATA-SAME: !associated !0
 ; POSIX: @__profd_foo = hidden global
+; METADATA-SAME: !associated !1
 ; COFF: @__profc_foo = internal global
 ; COFF-NOT: comdat
 ; COFF: @__profd_foo = internal global
@@ -29,7 +33,9 @@
 }
 
 ; POSIX: @__profc_foo_weak = weak hidden global
+; METADATA: !associated !2
 ; POSIX: @__profd_foo_weak = weak hidden global
+; METADATA: !associated !3
 ; COFF: @__profc_foo_weak = internal global
 ; COFF: @__profd_foo_weak = internal global
 define weak void @foo_weak() {
@@ -38,7 +44,9 @@
 }
 
 ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !4
 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !5
 ; COFF: @"__profc_linkage.ll:foo_internal" = internal global
 ; COFF: @"__profd_linkage.ll:foo_internal" = internal global
 define internal void @foo_internal() {
@@ -47,7 +55,9 @@
 }
 
 ; POSIX: @__profc_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !6
 ; POSIX: @__profd_foo_inline = linkonce_odr hidden gl

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-02 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 321015.
Herald added a subscriber: mgorny.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/test/CMakeLists.txt
  compiler-rt/test/profile/CMakeLists.txt
  compiler-rt/test/profile/instrprof-gc-sections.c
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/icall.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll
  llvm/test/Transforms/PGOProfile/associated.ll
  llvm/test/Transforms/PGOProfile/counter_promo.ll
  llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Index: llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
@@ -69,7 +69,7 @@
 ; PROMO-NEXT:  %pgocount{{.*}} = load {{.*}} @__profc_foo{{.*}} 4)
 ; PROMO-NEXT: add 
 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}4)
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 bb15: ; preds = %bb14, %bb4
Index: llvm/test/Transforms/PGOProfile/counter_promo.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo.ll
@@ -60,7 +60,7 @@
 ; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}0), i64 %[[LIVEOUT1]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 }
Index: llvm/test/Transforms/PGOProfile/associated.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/associated.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -pgo-instr-gen -instrprof -counter-link-order -S | FileCheck %s
+; 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
+
+define void @foo() {
+  ret void
+}
+
+; CHECK: !0 = !{void ()* @foo}
+; CHECK: !1 = !{[1 x i64]* @__profc_foo}
Index: llvm/test/Instrumentation/InstrProfiling/linkage.ll
===
--- llvm/test/Instrumentation/InstrProfiling/linkage.ll
+++ llvm/test/Instrumentation/InstrProfiling/linkage.ll
@@ -8,6 +8,8 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s -mtriple=x86_64-unknown-fuchsia -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
 
 ; MACHO: @__llvm_profile_runtime = external global i32
 ; LINUX-NOT: @__llvm_profile_runtime = external global i32
@@ -19,7 +21,9 @@
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
 
 ; POSIX: @__profc_foo = hidden global
+; METADATA-SAME: !associated !0
 ; POSIX: @__profd_foo = hidden global
+; METADATA-SAME: !associated !1
 ; COFF: @__profc_foo = internal global
 ; COFF-NOT: comdat
 ; COFF: @__profd_foo = internal global
@@ -29,7 +33,9 @@
 }
 
 ; POSIX: @__profc_foo_weak = weak hidden global
+; METADATA: !associated !2
 ; POSIX: @__profd_foo_weak = weak hidden global
+; METADATA: !associated !3
 ; COFF: @__profc_foo_weak = internal global
 ; COFF: @__profd_foo_weak = internal global
 define weak void @foo_weak() {
@@ -38,7 +44,9 @@
 }
 
 ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !4
 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !5
 ; COFF: @"__profc_linkage.ll:foo_internal" = internal global
 ; COFF: @"__profd_linkage.ll:foo_internal" = internal global
 define internal void @foo_internal() {
@@ -47,7 +55,9 @@
 }
 
 ; POSIX: @__profc_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !6
 ; POSIX: @__profd_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !7
 ; COFF: @__profc_foo_inline = internal global{{.*}} section ".lprfc$M", align 8
 ; COFF: @__profd_foo_inline = internal global{{.*}} sectio

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-02 Thread Tom Weaver via Phabricator via cfe-commits
TWeaver added a comment.

Hiya,

this patch (probably) broke the build bot at:

http://lab.llvm.org:8011/#/builders/53/builds/1184


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: compiler-rt/test/profile/instrprof-gc-sections.c:30
+// RUN: llvm-nm -jgU %t | grep -vE "main|_start|_IO_stdin_used|__libc_.*" > 
%t.code.syms
+// RUN: diff %t.nocode.syms %t.code.syms
+

MaskRay wrote:
> This fails on my machine (cc @akuegel). If I use `diff -u`:
> 
> ```
> --- 
> /tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.nocode.syms
>2021-02-01 22:14:22.850222346 -0800
> +++ 
> /tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.code.syms
>  2021-02-01 22:14:22.854222358 -0800
> @@ -3,6 +3,5 @@
>  __prof_cnts_sect_data
>  __prof_data_sect_data
>  __prof_nms_sect_data
> -__prof_orderfile_sect_data
>  __prof_vnodes_sect_data
>  lprofDirMode
> ```
> 
> At the worst we can temporarily disable it (if others report issues as well).
What's your build setup? I ran `check-profile` on my Linux workstation just now 
but haven't seen this issue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a subscriber: akuegel.
MaskRay added inline comments.



Comment at: compiler-rt/test/profile/instrprof-gc-sections.c:30
+// RUN: llvm-nm -jgU %t | grep -vE "main|_start|_IO_stdin_used|__libc_.*" > 
%t.code.syms
+// RUN: diff %t.nocode.syms %t.code.syms
+

This fails on my machine (cc @akuegel). If I use `diff -u`:

```
--- 
/tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.nocode.syms
   2021-02-01 22:14:22.850222346 -0800
+++ 
/tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.code.syms
 2021-02-01 22:14:22.854222358 -0800
@@ -3,6 +3,5 @@
 __prof_cnts_sect_data
 __prof_data_sect_data
 __prof_nms_sect_data
-__prof_orderfile_sect_data
 __prof_vnodes_sect_data
 lprofDirMode
```

At the worst we can temporarily disable it (if others report issues as well).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdf3e39f60b35: [InstrProfiling] Use !associated metadata for 
counters, data and values (authored by phosek).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/test/profile/instrprof-gc-sections.c
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/icall.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll
  llvm/test/Transforms/PGOProfile/associated.ll
  llvm/test/Transforms/PGOProfile/counter_promo.ll
  llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Index: llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
@@ -69,7 +69,7 @@
 ; PROMO-NEXT:  %pgocount{{.*}} = load {{.*}} @__profc_foo{{.*}} 4)
 ; PROMO-NEXT: add 
 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}4)
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 bb15: ; preds = %bb14, %bb4
Index: llvm/test/Transforms/PGOProfile/counter_promo.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo.ll
@@ -60,7 +60,7 @@
 ; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}0), i64 %[[LIVEOUT1]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 }
Index: llvm/test/Transforms/PGOProfile/associated.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/associated.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -pgo-instr-gen -instrprof -counter-link-order -S | FileCheck %s
+; 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
+
+define void @foo() {
+  ret void
+}
+
+; CHECK: !0 = !{void ()* @foo}
+; CHECK: !1 = !{[1 x i64]* @__profc_foo}
Index: llvm/test/Instrumentation/InstrProfiling/linkage.ll
===
--- llvm/test/Instrumentation/InstrProfiling/linkage.ll
+++ llvm/test/Instrumentation/InstrProfiling/linkage.ll
@@ -8,6 +8,8 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s -mtriple=x86_64-unknown-fuchsia -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
 
 ; MACHO: @__llvm_profile_runtime = external global i32
 ; LINUX-NOT: @__llvm_profile_runtime = external global i32
@@ -19,7 +21,9 @@
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
 
 ; POSIX: @__profc_foo = hidden global
+; METADATA-SAME: !associated !0
 ; POSIX: @__profd_foo = hidden global
+; METADATA-SAME: !associated !1
 ; COFF: @__profc_foo = internal global
 ; COFF-NOT: comdat
 ; COFF: @__profd_foo = internal global
@@ -29,7 +33,9 @@
 }
 
 ; POSIX: @__profc_foo_weak = weak hidden global
+; METADATA: !associated !2
 ; POSIX: @__profd_foo_weak = weak hidden global
+; METADATA: !associated !3
 ; COFF: @__profc_foo_weak = internal global
 ; COFF: @__profd_foo_weak = internal global
 define weak void @foo_weak() {
@@ -38,7 +44,9 @@
 }
 
 ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !4
 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !5
 ; COFF: @"__profc_linkage.ll:foo_internal" = internal global
 ; COFF: @"__profd_linkage.ll:foo_internal" = internal global
 define internal void @foo_internal() {
@@ -47,7 +55,9 @@
 }
 
 ; POSIX: @__profc_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !6
 ; POSIX: @__profd_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !7
 ; COFF: @__profc_foo_inline = internal global{{.*}} section ".lprfc$M", align 8
 ; COFF: @__p

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.

Thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D76802#2534118 , @MaskRay wrote:

> "prevents discarding" is not accurate in the context. `__llvm_prf_*` cannot 
> be discarded because C identifier name input sections are GC roots.
>
> Add "C identifier name input sections are GC roots. In LLD, the 
> SHF_LINK_ORDER flag overrides the C identifier name semantics." in 
> appropriate place.

Done, I have revised the change description.

> This C identifier name GC currently only works with LLD but does no harm to 
> gold/GNU ld.
>
> Do you think `__llvm_prf_*` can link to the text section so that the 
> self-link trick is not needed? 
> (https://sourceware.org/bugzilla/show_bug.cgi?id=27259)

I associated the counter with the function symbol which seems to be working and 
we no longer need the self-link trick.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 320562.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/test/profile/instrprof-gc-sections.c
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/icall.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll
  llvm/test/Transforms/PGOProfile/associated.ll
  llvm/test/Transforms/PGOProfile/counter_promo.ll
  llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Index: llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
@@ -69,7 +69,7 @@
 ; PROMO-NEXT:  %pgocount{{.*}} = load {{.*}} @__profc_foo{{.*}} 4)
 ; PROMO-NEXT: add 
 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}4)
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 bb15: ; preds = %bb14, %bb4
Index: llvm/test/Transforms/PGOProfile/counter_promo.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo.ll
@@ -60,7 +60,7 @@
 ; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}0), i64 %[[LIVEOUT1]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 }
Index: llvm/test/Transforms/PGOProfile/associated.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/associated.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -pgo-instr-gen -instrprof -counter-link-order -S | FileCheck %s
+; 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
+
+define void @foo() {
+  ret void
+}
+
+; CHECK: !0 = !{void ()* @foo}
+; CHECK: !1 = !{[1 x i64]* @__profc_foo}
Index: llvm/test/Instrumentation/InstrProfiling/linkage.ll
===
--- llvm/test/Instrumentation/InstrProfiling/linkage.ll
+++ llvm/test/Instrumentation/InstrProfiling/linkage.ll
@@ -8,6 +8,8 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s -mtriple=x86_64-unknown-fuchsia -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
 
 ; MACHO: @__llvm_profile_runtime = external global i32
 ; LINUX-NOT: @__llvm_profile_runtime = external global i32
@@ -19,7 +21,9 @@
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
 
 ; POSIX: @__profc_foo = hidden global
+; METADATA-SAME: !associated !0
 ; POSIX: @__profd_foo = hidden global
+; METADATA-SAME: !associated !1
 ; COFF: @__profc_foo = internal global
 ; COFF-NOT: comdat
 ; COFF: @__profd_foo = internal global
@@ -29,7 +33,9 @@
 }
 
 ; POSIX: @__profc_foo_weak = weak hidden global
+; METADATA: !associated !2
 ; POSIX: @__profd_foo_weak = weak hidden global
+; METADATA: !associated !3
 ; COFF: @__profc_foo_weak = internal global
 ; COFF: @__profd_foo_weak = internal global
 define weak void @foo_weak() {
@@ -38,7 +44,9 @@
 }
 
 ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !4
 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !5
 ; COFF: @"__profc_linkage.ll:foo_internal" = internal global
 ; COFF: @"__profd_linkage.ll:foo_internal" = internal global
 define internal void @foo_internal() {
@@ -47,7 +55,9 @@
 }
 
 ; POSIX: @__profc_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !6
 ; POSIX: @__profd_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !7
 ; 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() {
@@ -56,7 +66,9 @@
 }
 
 ; LINUX: @__profc_foo_extern = linkonce_odr hidden global {{.*

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> The !associated metadata may be attached to a global object declaration with 
> a single argument that references another global object. This metadata 
> prevents discarding of the global object in linker GC unless the referenced 
> object is also discarded.

"prevents discarding" is not accurate in the context. `__llvm_prf_*` cannot be 
discarded because C identifier name input sections are GC roots.

Add "C identifier name input sections are GC roots. In LLD, the SHF_LINK_ORDER 
flag overrides the C identifier name semantics." in appropriate place.

> Furthermore, when a function symbol is discarded by the linker, setting up 
> !associated metadata allows linker to discard counters, data and values 
> associated with that function symbol. This is not possible today because 
> there's metadata to guide the linker. This approach is also used by other 
> instrumentations like sanitizers.

This C identifier name GC currently only works with LLD but does no harm to 
gold/GNU ld.

Do you think `__llvm_prf_*` can link to the text section so that the self-link 
trick is not needed? (https://sourceware.org/bugzilla/show_bug.cgi?id=27259)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-01-31 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

@MaskRay I saw on https://sourceware.org/bugzilla/show_bug.cgi?id=27259 that 
the infinite loop fix has been cherry picked into 2.36 branch so I updated the 
condition to `-fbinutils-version=2.36`. Is this OK to land?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-01-31 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 320398.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/test/profile/instrprof-gc-sections.c
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/icall.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll
  llvm/test/Transforms/PGOProfile/associated.ll
  llvm/test/Transforms/PGOProfile/counter_promo.ll
  llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Index: llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
@@ -69,7 +69,7 @@
 ; PROMO-NEXT:  %pgocount{{.*}} = load {{.*}} @__profc_foo{{.*}} 4)
 ; PROMO-NEXT: add 
 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}4)
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 bb15: ; preds = %bb14, %bb4
Index: llvm/test/Transforms/PGOProfile/counter_promo.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo.ll
@@ -60,7 +60,7 @@
 ; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}0), i64 %[[LIVEOUT1]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 }
Index: llvm/test/Transforms/PGOProfile/associated.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/associated.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -pgo-instr-gen -instrprof -counter-link-order -S | FileCheck %s
+; 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 !0
+
+define void @foo() {
+  ret void
+}
+
+; CHECK: !0 = !{[1 x i64]* @__profc_foo}
Index: llvm/test/Instrumentation/InstrProfiling/linkage.ll
===
--- llvm/test/Instrumentation/InstrProfiling/linkage.ll
+++ llvm/test/Instrumentation/InstrProfiling/linkage.ll
@@ -8,6 +8,8 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s -mtriple=x86_64-unknown-fuchsia -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
 
 ; MACHO: @__llvm_profile_runtime = external global i32
 ; LINUX-NOT: @__llvm_profile_runtime = external global i32
@@ -19,7 +21,9 @@
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
 
 ; POSIX: @__profc_foo = hidden global
+; METADATA-SAME: !associated !0
 ; POSIX: @__profd_foo = hidden global
+; METADATA-SAME: !associated !0
 ; COFF: @__profc_foo = internal global
 ; COFF-NOT: comdat
 ; COFF: @__profd_foo = internal global
@@ -29,7 +33,9 @@
 }
 
 ; POSIX: @__profc_foo_weak = weak hidden global
+; METADATA: !associated !1
 ; POSIX: @__profd_foo_weak = weak hidden global
+; METADATA: !associated !1
 ; COFF: @__profc_foo_weak = internal global
 ; COFF: @__profd_foo_weak = internal global
 define weak void @foo_weak() {
@@ -38,7 +44,9 @@
 }
 
 ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !2
 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global
+; 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() {
@@ -47,7 +55,9 @@
 }
 
 ; POSIX: @__profc_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !3
 ; POSIX: @__profd_foo_inline = linkonce_odr hidden global
+; 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() {
@@ -56,7 +66,9 @@
 }
 
 ; LINUX: @__profc_foo_extern = linkonce_odr hidden global {{.*}}section "__llvm_prf_cnts", com

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-01-27 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D76802#2526483 , @MaskRay wrote:

> Looks quite good.
>
> In D76802#2526382 , @phosek wrote:
>
>> @MaskRay does this look good to you?
>
> Looks like GNU ld has an infinite loop problem w.r.t self-link 
> SHF_LINK_ORDER: https://sourceware.org/bugzilla/show_bug.cgi?id=27259

Thanks for checking this.

>> The reason is that the C identifier sections are considered as GC roots. 
>> Adding SHF_LINK_ORDER is a trick to defeat the GC root semantics.
>
> Hope GNU ld can implement the rule. For now, only `-fbinutils-version=none` 
> can use this.

I've updated the logic to reflect that.

> About `counter-associated-metadata`: perhaps we should just call it 
> `linkorder-counter`. `!associated` while being metadata, is actually similar 
> to `, comdat` (it cannot be freely dropped) and its semantics is tightly 
> coupled with `SHF_LINK_ORDER`. linkorder conveys more information than 
> `associated` (`associated` can mean many things).

Done.

In D76802#2526485 , @MaskRay wrote:

> Please also comment (and update the description) that self-link may be used. 
> This is subtle. The reason is that the ELF section names (e.g. 
> `__llvm_prf_cnts`) are C identifiers and considered GC roots in the absence 
> of the `SHF_LINK_ORDER` flag.

Done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-01-27 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 319762.
phosek added a reviewer: MaskRay.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/test/profile/instrprof-gc-sections.c
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/icall.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll
  llvm/test/Transforms/PGOProfile/associated.ll
  llvm/test/Transforms/PGOProfile/counter_promo.ll
  llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Index: llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
@@ -69,7 +69,7 @@
 ; PROMO-NEXT:  %pgocount{{.*}} = load {{.*}} @__profc_foo{{.*}} 4)
 ; PROMO-NEXT: add 
 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}4)
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 bb15: ; preds = %bb14, %bb4
Index: llvm/test/Transforms/PGOProfile/counter_promo.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo.ll
@@ -60,7 +60,7 @@
 ; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}0), i64 %[[LIVEOUT1]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 }
Index: llvm/test/Transforms/PGOProfile/associated.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/associated.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -pgo-instr-gen -instrprof -counter-link-order -S | FileCheck %s
+; 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 !0
+
+define void @foo() {
+  ret void
+}
+
+; CHECK: !0 = !{[1 x i64]* @__profc_foo}
Index: llvm/test/Instrumentation/InstrProfiling/linkage.ll
===
--- llvm/test/Instrumentation/InstrProfiling/linkage.ll
+++ llvm/test/Instrumentation/InstrProfiling/linkage.ll
@@ -8,6 +8,8 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s -mtriple=x86_64-unknown-fuchsia -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
 
 ; MACHO: @__llvm_profile_runtime = external global i32
 ; LINUX-NOT: @__llvm_profile_runtime = external global i32
@@ -19,7 +21,9 @@
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
 
 ; POSIX: @__profc_foo = hidden global
+; METADATA-SAME: !associated !0
 ; POSIX: @__profd_foo = hidden global
+; METADATA-SAME: !associated !0
 ; COFF: @__profc_foo = internal global
 ; COFF-NOT: comdat
 ; COFF: @__profd_foo = internal global
@@ -29,7 +33,9 @@
 }
 
 ; POSIX: @__profc_foo_weak = weak hidden global
+; METADATA: !associated !1
 ; POSIX: @__profd_foo_weak = weak hidden global
+; METADATA: !associated !1
 ; COFF: @__profc_foo_weak = internal global
 ; COFF: @__profd_foo_weak = internal global
 define weak void @foo_weak() {
@@ -38,7 +44,9 @@
 }
 
 ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !2
 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global
+; 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() {
@@ -47,7 +55,9 @@
 }
 
 ; POSIX: @__profc_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !3
 ; POSIX: @__profd_foo_inline = linkonce_odr hidden global
+; 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() {
@@ -56,7 +66,9 @@
 }
 
 ; LINUX: @__profc_foo

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-01-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Please also comment (and update the description) that self-link may be used. 
This is subtle. The reason is that the ELF section names (e.g. 
`__llvm_prf_cnts`) are C identifiers and considered GC roots in the absence of 
the `SHF_LINK_ORDER` flag.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-01-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Looks quite good.

In D76802#2526382 , @phosek wrote:

> @MaskRay does this look good to you?

Looks like GNU ld has an infinite loop problem w.r.t self-link SHF_LINK_ORDER: 
https://sourceware.org/bugzilla/show_bug.cgi?id=27259

> The reason is that the C identifier sections are considered as GC roots. 
> Adding SHF_LINK_ORDER is a trick to defeat the GC root semantics.

Hope GNU ld can implement the rule. For now, only `-fbinutils-version=none` can 
use this.

About `counter-associated-metadata`: perhaps we should just call it 
`linkorder-counter`. `!associated` while being metadata, is actually similar to 
`, comdat` (it cannot be freely dropped) and its semantics is tightly coupled 
with `SHF_LINK_ORDER`. linkorder conveys more information than `associated` 
(`associated` can mean many things).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-01-27 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

@MaskRay does this look good to you?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-01-27 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D76802#2524039 , @MaskRay wrote:

> - `__llvm_prf_cnts` does not need to have a self link `SHF_LINK_ORDER`. 
> `__llvm_prf_data` linking to `__llvm_prf_cnts` suffices. This is on the 
> premise that only `__llvm_prf_data` may reference `__llvm_prf_cnts`

Discussed with @MaskRay over chat, this is necessary because `__llvm_prf_cnts` 
is a C identifier.

> - Please update `InstrProfiling/icall.ll` to test `__profvp_` 
> (`-vp-static-alloc=true`). `__llvm_prf_vals` should link to `__llvm_prf_cnts`.

Done.

> - From the current organization of tests, I think `linkage.ll` is a better 
> place than a separate `associated.ll`. The tests there are more comprehensive 
> (needs-comdat and non-needs-comdat cases). You can add the new associated 
> mode to `linkage.ll`.

Done.

> -fbinutils-version is now available. You can condition the associated feature 
> on 2.36 now.

Done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-01-27 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 319493.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/test/profile/instrprof-gc-sections.c
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/icall.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll
  llvm/test/Transforms/PGOProfile/associated.ll
  llvm/test/Transforms/PGOProfile/counter_promo.ll
  llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Index: llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
@@ -69,7 +69,7 @@
 ; PROMO-NEXT:  %pgocount{{.*}} = load {{.*}} @__profc_foo{{.*}} 4)
 ; PROMO-NEXT: add 
 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}4)
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 bb15: ; preds = %bb14, %bb4
Index: llvm/test/Transforms/PGOProfile/counter_promo.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo.ll
@@ -60,7 +60,7 @@
 ; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}0), i64 %[[LIVEOUT1]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 }
Index: llvm/test/Transforms/PGOProfile/associated.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/associated.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -pgo-instr-gen -instrprof -counter-associated-metadata -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen,instrprof -counter-associated-metadata -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 !0
+
+define void @foo() {
+  ret void
+}
+
+; CHECK: !0 = !{[1 x i64]* @__profc_foo}
Index: llvm/test/Instrumentation/InstrProfiling/linkage.ll
===
--- llvm/test/Instrumentation/InstrProfiling/linkage.ll
+++ llvm/test/Instrumentation/InstrProfiling/linkage.ll
@@ -8,6 +8,8 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s -mtriple=x86_64-unknown-fuchsia -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -counter-associated-metadata -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -counter-associated-metadata -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
 
 ; MACHO: @__llvm_profile_runtime = external global i32
 ; LINUX-NOT: @__llvm_profile_runtime = external global i32
@@ -19,7 +21,9 @@
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
 
 ; POSIX: @__profc_foo = hidden global
+; METADATA-SAME: !associated !0
 ; POSIX: @__profd_foo = hidden global
+; METADATA-SAME: !associated !0
 ; COFF: @__profc_foo = internal global
 ; COFF-NOT: comdat
 ; COFF: @__profd_foo = internal global
@@ -29,7 +33,9 @@
 }
 
 ; POSIX: @__profc_foo_weak = weak hidden global
+; METADATA: !associated !1
 ; POSIX: @__profd_foo_weak = weak hidden global
+; METADATA: !associated !1
 ; COFF: @__profc_foo_weak = internal global
 ; COFF: @__profd_foo_weak = internal global
 define weak void @foo_weak() {
@@ -38,7 +44,9 @@
 }
 
 ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !2
 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global
+; 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() {
@@ -47,7 +55,9 @@
 }
 
 ; POSIX: @__profc_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !3
 ; POSIX: @__profd_foo_inline = linkonce_odr hidden global
+; 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 linkon