-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.sh
executable file
·184 lines (169 loc) · 4.29 KB
/
start.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env sh
MFILE=./Makefile
INPUT_FILE=
FNAME=
XMIN=0
XMAX=50
YMAX=1
INC=0.01
FROM=0
TO=0
# Due to heat-colors and path probabilities supported after llvm-11 in generating .dot files
LLVM_DIR=/usr/lib/llvm-11
COST_FILE=
MODEL_FILE=
while [ "$1" != "" ]; do
case $1 in
-i | --input)
shift
INPUT_FILE="$1"
;;
-f | --fname)
shift
FNAME="$1"
;;
-xmax)
shift
XMAX="$1"
;;
-xmin)
shift
XMIN="$1"
;;
-inc)
shift
INC="$1"
;;
-ymax)
shift
YMAX="$1"
;;
--llvm-dir)
shift
LLVM_DIR="$1"
;;
-from)
shift
FROM="$1"
;;
-to)
shift
TO="$1"
;;
-e)
COST_FILE=.output/energy.costs
;;
-t)
COST_FILE=.output/timing.costs
;;
-m | --model-file)
shift
MODEL_FILE="$1"
;;
esac
shift
done
# shellcheck disable=SC2039
ulimit -s 102400 # enlarge stack limit to 100 MB = 102400 KB (in binary)
echo "Checking instruction's model file..."
if ! test -f "$MODEL_FILE"; then
echo " Model file not found"
exit
else
echo " Plotting Models"
if ! [ -d .model ]; then
mkdir .model
else
rm -r ./.model/ >/dev/null 2>&1
mkdir .model
fi
Rscript R/model.R "$MODEL_FILE" svg 2>&1 &#launch shell independent process
fi
###
echo "Checkin input C/C++ file and emitting LLVM code..."
if ! test -f "$INPUT_FILE"; then
echo " Input file not found: $INPUT_FILE"
exit
else
if ! [ -d .llvm ]; then
mkdir .llvm
else
rm -r ./.llvm/ >/dev/null 2>&1
mkdir .llvm
fi
./clang/bin/clang -v -O0 -g -emit-llvm -S -fno-discard-value-names "$INPUT_FILE" -o ./.llvm/input.ll #>/dev/null 2>&1
fi
###
echo "Running CMake..."
cmake -DLT_LLVM_INSTALL_DIR="$LLVM_DIR" -DCMAKE_BUILD_TYPE=Release . #> /dev/null 2>&1
if test -f "$MFILE"; then
echo "Building passes..."
make
else
echo " Makefile not found"
exit
fi
###
echo "Running passes..."
if ! [ -d .output ]; then
mkdir .output
else
rm -r ./.output/ >/dev/null 2>&1
mkdir .output
fi
echo " Running optimization pass (mem2reg, ?simplifycfg, ?constprop)..."
"$LLVM_DIR"/bin/opt -S -mem2reg -time-passes ./.llvm/input.ll -o ./.llvm/input.ll
#"$LLVM_DIR"/bin/opt -S -constprop -simplifycfg -time-passes ./.llvm/input.ll -o ./.llvm/input.ll
#"$LLVM_DIR"/bin/opt -S -time-passes -loop-unroll -unroll-count=3 ./.llvm/input.ll -o ./.llvm/input.ll
echo " Running config pass..."
"$LLVM_DIR"/bin/opt -S -load ./passes/libConfigPass.so -config-pass -model-file "$MODEL_FILE" ./.llvm/input.ll -o ./.llvm/inst-conf.ll
echo " Running cost model pass..."
"$LLVM_DIR"/bin/opt -S -load ./passes/libCostModelPass.so -bb-cost-model ./.llvm/inst-conf.ll -o ./.llvm/prob-block-cost.ll
###
echo "Generating control-flow-graph files..."
if ! [ -d .dots ]; then
mkdir .dots
else
rm -r ./.dots/ >/dev/null 2>&1
mkdir .dots
fi
cd .dots || exit
# -cfg-dot-filename-prefix=cfg
# -cfg-func-name=get_sign
# -cfg-heat-colors
# -cfg-weights
# -cfg-raw-weights (optional)
"$LLVM_DIR"/bin/opt -dot-cfg-only -cfg-heat-colors -cfg-weights ../.llvm/prob-block-cost.ll -o /dev/null
"$LLVM_DIR"/bin/opt -dot-cfg -cfg-dot-filename-prefix=.cfg -cfg-heat-colors -cfg-weights ../.llvm/prob-block-cost.ll -o /dev/null
cd ..
###
echo "Embedding Energy/Timing Models to graphs..."
Rscript R/cfg.R # 2>&1 &#launch shell independent process
###
echo " Running probabilistic symbolic execution pass..."
"$LLVM_DIR"/bin/opt -S -load ./passes/libProbabilisticSymbolicExecution.so -prob-sym-exec ./.llvm/prob-block-cost.ll -o ./.llvm/prob-sym-exec.ll
#echo " Generating probabilistic symbolic machine..."
#"$LLVM_DIR"/bin/opt -S -load ./passes/libProbabilisticSymbolicExecution.so -prob-sym-exec-writer -execute-machines=true -generate-cfg=false ./.llvm/prob-sym-exec.ll -o ./.llvm/prob-sym-exec.ll
echo " Running normal execution pass..."
"$LLVM_DIR"/bin/opt -S -load ./passes/libNEAnalysisPass.so -normal-execution ./.llvm/prob-sym-exec.ll -o ./.llvm/output.ll
###
echo "Creating output(s)..."
if ! [ -d .temp ]; then
mkdir .temp
else
rm ./.temp/* >/dev/null 2>&1
fi
###
echo "Drawing the graph(s)..."
if [ -z "$FNAME" ]; then
./Reporter "$COST_FILE"
else
./Reporter "$COST_FILE" -fname "$FNAME"
fi
if [ -n "$FNAME" ]; then
if ! test -f ./.temp/"$FNAME"; then
echo " Function not found"
exit
fi
fi
Rscript R/graph.R "$XMIN" "$XMAX" "$YMAX" "$INC" "$FROM" "$TO" #>/dev/null 2>&1