-
Notifications
You must be signed in to change notification settings - Fork 2
/
nisse_profiler_noprint.sh
executable file
·123 lines (101 loc) · 2.25 KB
/
nisse_profiler_noprint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
# Example:
# ./mem_profiler.sh ../../tests/simple_array.c
if [ $# -lt 1 ]
then
echo Syntax: regions_ex file.c
exit 1
fi
# LLVM tools:
#
source ./config.sh
LLVM_OPT=$LLVM_INSTALL_DIR/bin/opt
LLVM_CLANG=$LLVM_INSTALL_DIR/bin/clang
PROFILER_IMPL=$SOURCE_DIR/lib/prof.c
MY_LLVM_LIB=$BUILD_DIR/lib/libNisse.so
PROP_BIN=$BUILD_DIR/bin/propagation
# Move to folder where the file is:
#
DR_NAME="$(dirname $1)"
cd $DR_NAME
# File names:
#
FL_NAME=$(basename $1)
BS_NAME=$(basename $FL_NAME .c)
PROF_DIR=$FL_NAME.profiling
LL_NAME="$BS_NAME.ll"
PF_NAME="$BS_NAME.profiled.ll"
# Create the profiling folder:
#
if [ -d "$PROF_DIR" ]; then
rm -r "$PROF_DIR"
fi
mkdir $PROF_DIR
cd $PROF_DIR
CLANG_FLAGS="-Xclang -disable-O0-optnone -std=c99 -c -S -emit-llvm"
# Generating the bytecode in SSA form:
#
$LLVM_CLANG $CLANG_FLAGS ../$FL_NAME -o $LL_NAME
if [[ $ret_code -ne 0 ]]; then
echo "Compilation failed"
cd -
echo $FL_NAME >> err.txt
exit $ret_code
fi
$LLVM_OPT -S -passes="mem2reg,instnamer" $LL_NAME -o $LL_NAME
# Running the pass:
#
$LLVM_OPT -S -load-pass-plugin $MY_LLVM_LIB -passes="nisse" -nisse-disable-print -stats \
$LL_NAME -o $PF_NAME
# Print the instrumented CFG
#
$LLVM_OPT -S -passes="dot-cfg" -stats \
$PF_NAME -o $PF_NAME
# Compile the newly instrumented program, and link it against the profiler.
# We are passing -no_pie to disable address space layout randomization:
#
$LLVM_CLANG -Wall -std=c99 $PF_NAME $PROFILER_IMPL -o $BS_NAME
ret_code=$?
if [[ $ret_code -ne 0 ]]; then
echo "Compilation failed"
cd -
echo $FL_NAME >> err.txt
exit $ret_code
fi
# Run the instrumented binary:
#
./$BS_NAME 0
# Prepare the result folders
#
mkdir graphs profiles compiled partial_profiles dot
# # Propagation Flags to use:
# #
# if [ $# -eq 2 ]
# then
# PROP_FLAG="-s"
# else
# PROP_FLAG=""
# fi
# # Propagate the weights for each function:
# #
for i in *.prof; do
# PROF_NAME="$i.full"
# $PROP_BIN $i $PROP_FLAG -o $PROF_NAME
mv $i partial_profiles/
# mv $PROF_NAME profiles/
done
# Move the files to apropriate folders
#
for i in .*.dot; do
mv $i dot/
done
for i in *.graph; do
mv $i graphs/
done
for i in *.ll; do
mv $i compiled/
done
mv $BS_NAME compiled/
# Go back to the folder where you were before:
#
cd -