-
Notifications
You must be signed in to change notification settings - Fork 2
/
nisse_profiler.sh
executable file
·134 lines (111 loc) · 2.39 KB
/
nisse_profiler.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
124
125
126
127
128
129
130
131
132
133
134
#!/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
echo $(pwd)
# 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"
INFO_PROF="info.prof"
MAIN_PROF="main.prof"
PROF_SUF=".prof.full"
# 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 -passes="loop-simplify,break-crit-edges" $LL_NAME -o $LL_NAME
$LLVM_OPT -S -load-pass-plugin $MY_LLVM_LIB -passes="nisse" -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
#
$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:
#
if [ $# -ge 2 ]
then
./$BS_NAME $2
else
./$BS_NAME 0
fi
ret_code=$?
if [ ! -f $INFO_PROF ] || [ ! -f $MAIN_PROF ]
then
echo "Execution failed"
cd -
echo $FL_NAME >> err.txt
exit $ret_code
fi
# Propagate the weights for each function:
#
$PROP_BIN $INFO_PROF $MAIN_PROF -o ".prof.full"
# Prepare the result folders
#
mkdir graphs profiles compiled partial_profiles dot
# 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
for i in *.prof.full*; do
mv $i profiles/
done
for i in *.prof; do
mv $i partial_profiles/
done
mv $BS_NAME compiled/
# Go back to the folder where you were before:
#
cd -