Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / test / tools / llvm-profdata / Inputs / update_memprof_inputs.sh
blob5365a0bb6cc3a390f398ce3b9da00d519c755544
1 #!/bin/bash
3 if [ -z $1 ]; then
4 echo "Path to clang required!"
5 echo "Usage: update_memprof_inputs.sh /path/to/updated/clang"
6 exit 1
7 else
8 CLANG=$1
9 fi
11 # Allows the script to be invoked from other directories.
12 OUTDIR=$(dirname $(realpath -s $0))
14 read -r -d '' BASIC << EOF
15 #include <stdlib.h>
16 #include <string.h>
17 int main(int argc, char **argv) {
18 char *x = (char *)malloc(10);
19 memset(x, 0, 10);
20 free(x);
21 x = (char *)malloc(10);
22 memset(x, 0, 10);
23 free(x);
24 return 0;
26 EOF
28 read -r -d '' INLINE << EOF
29 #include <stdlib.h>
30 #include <string.h>
32 __attribute__((always_inline))
33 void qux(int x) {
34 char *ptr = malloc(x);
35 memset(ptr, 0, x);
36 free(ptr);
39 __attribute__((noinline))
40 void foo(int x){ qux(x); }
42 __attribute__((noinline))
43 void bar(int x) { foo(x); }
45 int main(int argc, char **argv) {
46 bar(argc);
47 return 0;
49 EOF
51 read -r -d '' MULTI << EOF
52 #include <sanitizer/memprof_interface.h>
53 #include <stdlib.h>
54 #include <string.h>
55 int main(int argc, char **argv) {
56 char *x = (char *)malloc(10);
57 memset(x, 0, 10);
58 free(x);
59 __memprof_profile_dump();
60 x = (char *)malloc(10);
61 memset(x, 0, 10);
62 free(x);
63 return 0;
65 EOF
67 DEFAULT_MEMPROF_FLAGS="-fuse-ld=lld -Wl,--no-rosegment -gmlt -fdebug-info-for-profiling -fmemory-profile -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -m64 -Wl,-build-id -no-pie"
69 # Map each test to their source and any additional flags separated by ;
70 declare -A INPUTS
71 INPUTS["basic"]="BASIC"
72 INPUTS["inline"]="INLINE"
73 INPUTS["multi"]="MULTI"
74 INPUTS["pic"]="BASIC;-pie"
75 INPUTS["buildid"]="BASIC;-Wl,-build-id=sha1"
77 for name in "${!INPUTS[@]}"; do
78 IFS=";" read -r src flags <<< "${INPUTS[$name]}"
79 echo "${!src}" > ${OUTDIR}/${name}.c
80 ${CLANG} ${DEFAULT_MEMPROF_FLAGS} ${flags} ${OUTDIR}/${name}.c -o ${OUTDIR}/${name}.memprofexe
81 env MEMPROF_OPTIONS=log_path=stdout ${OUTDIR}/${name}.memprofexe > ${OUTDIR}/${name}.memprofraw
82 rm ${OUTDIR}/${name}.c
83 done