[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / llvm / test / Transforms / PGOProfile / Inputs / update_memprof_inputs.sh
blobcbf9a401a607235623a44e12070ec120e14ce1ce
1 #!/bin/bash
3 if [ $# -lt 2 ]; then
4 echo "Path to clang and llvm-profdata required!"
5 echo "Usage: update_memprof_inputs.sh /path/to/updated/clang /path/to/updated/llvm-profdata"
6 exit 1
7 else
8 CLANG=$1
9 LLVMPROFDATA=$2
12 # Allows the script to be invoked from other directories.
13 OUTDIR=$(dirname $(realpath -s $0))
15 # Note that changes in the code below which affect relative line number
16 # offsets of calls from their parent function can affect callsite matching in
17 # the LLVM IR.
18 cat > ${OUTDIR}/memprof.cc << EOF
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22 char *foo() {
23 return new char[10];
25 char *foo2() {
26 return foo();
28 char *bar() {
29 return foo2();
31 char *baz() {
32 return foo2();
34 char *recurse(unsigned n) {
35 if (!n)
36 return foo();
37 return recurse(n-1);
39 int main(int argc, char **argv) {
40 // Test allocations with different combinations of stack contexts and
41 // coldness (based on lifetime, since they are all accessed a single time
42 // per byte via the memset).
43 char *a = new char[10];
44 char *b = new char[10];
45 char *c = foo();
46 char *d = foo();
47 char *e = bar();
48 char *f = baz();
49 memset(a, 0, 10);
50 memset(b, 0, 10);
51 memset(c, 0, 10);
52 memset(d, 0, 10);
53 memset(e, 0, 10);
54 memset(f, 0, 10);
55 // a and c have short lifetimes
56 delete[] a;
57 delete[] c;
58 // b, d, e, and f have long lifetimes and will be detected as cold by default.
59 sleep(200);
60 delete[] b;
61 delete[] d;
62 delete[] e;
63 delete[] f;
65 // Loop ensures the two calls to recurse have stack contexts that only differ
66 // in one level of recursion. We should get two stack contexts reflecting the
67 // different levels of recursion and different allocation behavior (since the
68 // first has a very long lifetime and the second has a short lifetime).
69 for (unsigned i = 0; i < 2; i++) {
70 char *g = recurse(i + 3);
71 memset(g, 0, 10);
72 if (!i)
73 sleep(200);
74 delete[] g;
76 return 0;
78 EOF
80 COMMON_FLAGS="-fuse-ld=lld -Wl,--no-rosegment -gmlt -fdebug-info-for-profiling -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -m64 -Wl,-build-id -no-pie"
82 ${CLANG} ${COMMON_FLAGS} -fmemory-profile ${OUTDIR}/memprof.cc -o ${OUTDIR}/memprof.exe
83 env MEMPROF_OPTIONS=log_path=stdout ${OUTDIR}/memprof.exe > ${OUTDIR}/memprof.memprofraw
85 # Generate another profile without any column numbers.
86 ${CLANG} ${COMMON_FLAGS} -gno-column-info -fmemory-profile ${OUTDIR}/memprof.cc -o ${OUTDIR}/memprof.nocolinfo.exe
87 env MEMPROF_OPTIONS=log_path=stdout ${OUTDIR}/memprof.nocolinfo.exe > ${OUTDIR}/memprof.nocolinfo.memprofraw
89 ${CLANG} ${COMMON_FLAGS} -fprofile-generate=. \
90 ${OUTDIR}/memprof.cc -o ${OUTDIR}/pgo.exe
91 env LLVM_PROFILE_FILE=${OUTDIR}/memprof_pgo.profraw ${OUTDIR}/pgo.exe
92 ${LLVMPROFDATA} merge --text ${OUTDIR}/memprof_pgo.profraw -o ${OUTDIR}/memprof_pgo.proftext
94 rm ${OUTDIR}/memprof.cc
95 rm ${OUTDIR}/pgo.exe
96 rm ${OUTDIR}/memprof_pgo.profraw