Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / tsan / analyze_libtsan.sh
blob367ccca894725e34dc12a405b99e01c1c3039ee3
1 #!/usr/bin/env bash
3 # Script that prints information about generated code in TSan runtime.
5 set -e
6 set -u
8 if [[ "$#" != 1 ]]; then
9 echo "Usage: $0 /path/to/binary/built/with/tsan"
10 exit 1
13 get_asm() {
14 grep __tsan_$1.: -A 10000 ${OBJDUMP_CONTENTS} | \
15 awk "/[^:]$/ {print;} />:/ {c++; if (c == 2) {exit}}"
18 list="write1 \
19 write2 \
20 write4 \
21 write8 \
22 read1 \
23 read2 \
24 read4 \
25 read8 \
26 func_entry \
27 func_exit"
29 BIN=$1
30 OUTPUT_DIR=$(mktemp -t -d analyze_libtsan_out.XXXXXXXX)
31 OBJDUMP_CONTENTS=${OUTPUT_DIR}/libtsan_objdump
32 NM_CONTENTS=${OUTPUT_DIR}/libtsan_nm
34 objdump -d $BIN > ${OBJDUMP_CONTENTS}
35 nm -S $BIN | grep "__tsan_" > ${NM_CONTENTS}
37 for f in $list; do
38 file=${OUTPUT_DIR}/asm_$f.s
39 get_asm $f > $file
40 tot=$(wc -l < $file)
41 size=$(grep __tsan_$f$ ${NM_CONTENTS} | awk --non-decimal-data '{print ("0x"$2)+0}')
42 rsp=$(grep '(%rsp)' $file | wc -l)
43 push=$(grep 'push' $file | wc -l)
44 pop=$(grep 'pop' $file | wc -l)
45 call=$(grep 'call' $file | wc -l)
46 load=$(egrep 'mov .*\,.*\(.*\)|cmp .*\,.*\(.*\)' $file | wc -l)
47 store=$(egrep 'mov .*\(.*\),' $file | wc -l)
48 mov=$(grep 'mov' $file | wc -l)
49 lea=$(grep 'lea' $file | wc -l)
50 sh=$(grep 'shr\|shl' $file | wc -l)
51 cmp=$(grep 'cmp\|test' $file | wc -l)
52 printf "%10s tot %3d; size %4d; rsp %d; push %d; pop %d; call %d; load %2d; store %2d; sh %3d; mov %3d; lea %3d; cmp %3d\n" \
53 $f $tot $size $rsp $push $pop $call $load $store $sh $mov $lea $cmp;
54 done