[clang] [clang-tools-extra] [llvm] [compiler-rt] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-11 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.

LGTM once these changes are made.

* unused `%clangxx_pgouse=`
* profraw => proftext for the PGOProfile test
* lld-available -fuse-ld=lld and windows triple simplification for the 
compiler-rt test

It seems useful to wait for others' opinions as well.

https://github.com/llvm/llvm-project/pull/74008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [compiler-rt] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-11 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,97 @@
+// This is a regression test for ThinLTO indirect-call-promotion when candidate
+// callees need to be imported from another IR module.  In the C++ test case,
+// `main` calls `global_func` which is defined in another module. `global_func`
+// has two indirect callees, one has external linkage and one has local 
linkage.
+// All three functions should be imported into the IR module of main.
+
+// What the test does:
+// - Generate raw profiles from executables and convert it to indexed profiles.
+//   During the conversion, a profiled callee address in raw profiles will be
+//   converted to function hash in indexed profiles.
+// - Run IRPGO profile use and ThinTLO prelink pipeline and get LLVM bitcodes
+//   for both cpp files in the C++ test case.
+// - Generate ThinLTO summary file with LLVM bitcodes, and run 
`function-import` pass.
+// - Run `pgo-icall-prom` pass for the IR module which needs to import callees.
+
+// RUN: rm -rf %t && split-file %s %t && cd %t
+
+// Use clang*_{pgogen,pgouse} for IR level instrumentation, and use clangxx* 
for
+// C++.
+//
+// Do setup work for all below tests.
+// Generate raw profiles from real programs and convert it into indexed 
profiles.
+// RUN: %clangxx_pgogen -fuse-ld=lld -O2 lib.cpp main.cpp -o main
+// RUN: env LLVM_PROFILE_FILE=main.profraw %run ./main
+// RUN: llvm-profdata merge main.profraw -o main.profdata
+
+// Use profile on lib and get bitcode, test that local function callee0 has
+// expected !PGOFuncName metadata and external function callee1 doesn't have
+// !PGOFuncName metadata. Explicitly skip ICP pass to test ICP happens as
+// expected in the IR module that imports functions from lib.
+// RUN: %clang -target x86_64-unknown-linux-gnu -mllvm -disable-icp 
-fprofile-use=main.profdata -flto=thin -O2 -c lib.cpp -o lib.bc

MaskRay wrote:

To match 32-bit Windows triples, `i.86.*windows` suffices. The normalized 
triples don't use `win32`.

https://github.com/llvm/llvm-project/pull/74008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [compiler-rt] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-11 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/74008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [compiler-rt] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-11 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/74008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [compiler-rt] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-11 Thread Fangrui Song via cfe-commits


@@ -1,39 +0,0 @@
-; Do setup work for all below tests: generate bitcode and combined index

MaskRay wrote:

It looks like that we had 3 precanned profraw files and this patch is adding 
another one. Since the raw profile isn't stable, this is going to add some 
inconvenience whenever the version is bumped.
`thinlto_indirect_call_promotion.profraw` probably should be rewritten as 
`.proftext` and `llvm-profdata merge`
```
% fd -e profraw
Transforms/PGOProfile/Inputs/thinlto_indirect_call_promotion.profraw
tools/llvm-profdata/Inputs/basic.profraw
tools/llvm-profdata/Inputs/compressed.profraw
tools/llvm-profdata/Inputs/c-general.profraw
```

It seems that there is an earlier comment that proftext may not cover the use 
case well, so we also utilize a runtime test in `compiler-rt/test`.

https://github.com/llvm/llvm-project/pull/74008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [compiler-rt] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-08 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Trying to summarize the issue.

`__llvm_prf_nm` contains an entry `getIRPGONameForGlobalObject() == 
"lib.cc;_ZL7callee0v"`. The hash in the "VP" metadata uses 
`md5("lib.cc;_ZL7callee0v")`: `!31 = !{!"VP", i32 0, i64 1, i64 
8947761083887884635, i64 1}`

Without this patch, when invoking `opt -passes=pgo-instr-use 
-pgo-test-profile-file=%t.profdata -module-summary %tdir/lib.ll -o %t2.bc`,
in `llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:computeFunctionSummary`,
the local linkage `_ZL7callee0v`'s GUID is incorrectly computed as 
`md5("lib.cc:_ZL7callee0v")` and therefore is not associated with the global 
variable summary `_Z7callee1v`
(displayed as a stray `^2 = gv: (guid: 8947761083887884635)`).

This patch fixes `_ZL7callee0v`'s GUID to be `md5("lib.cc;_ZL7callee0v")`, 
correctly associating it with the global variable summary `_Z7callee1v`.

---

Mach-O (and 32-bit Windows) mangle global symbols with a leading `_`.
`llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:computeFunctionSummary` uses 
`getGlobalIdentifier`, which does not have `GlobalObject` information for the 
mangling scheme.
The identifier can be different from the producer, causing missed import of 
functions for indirect-call-promotion (#74565).


https://github.com/llvm/llvm-project/pull/74008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [compiler-rt] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-08 Thread Fangrui Song via cfe-commits


@@ -1,39 +1,45 @@
-; Do setup work for all below tests: generate bitcode and combined index
-; RUN: opt -module-summary %s -o %t.bc
-; RUN: opt -module-summary %p/Inputs/thinlto_indirect_call_promotion.ll -o 
%t2.bc
+; The raw profiles and reduced IR inputs are generated from 
Inputs/update_icall_promotion_inputs.sh
+
+; Do setup work for all below tests: annotate value profiles, generate bitcode 
and combined index.
+; Explicitly turn off ICP pass in Inputs/thinlto_indirect_call_promotion.ll.
+; This way ICP happens in %t.bc after _Z11global_funcv and two indirect 
callees are imported.
+; RUN: opt -passes=pgo-instr-use 
-pgo-test-profile-file=%p/Inputs/thinlto_icall_prom.profdata -module-summary %s 
-o %t.bc

MaskRay wrote:

A common pattern is `rm -rf %t && split-file %s %t`. When dealing with multiple 
files, it is useful to ensure the temporary directory is cleared.  If 
specifying `%t/out.bc` is too inconvenient, you can run `rm -rf %t && 
split-file %s %t && cd %t` and then forget about `%t`.

https://github.com/llvm/llvm-project/pull/74008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits