-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathrun-souper.sh
executable file
·109 lines (88 loc) · 2.54 KB
/
run-souper.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
#!/usr/bin/env bash
# Runs Souper on the LHSes that were harvested by `clif-util
# souper-harvest`.
#
# This script takes two inputs:
#
# 1. The `souper-check` binary, and
# 2. The directory of harvested left-hand sides (aka the `-o $directory` you
# specified to `clif-util souper-harvest`).
#
# For a left-hand side file `foo` that Souper successfully synthesized a
# right-hand side for, this script will write the whole optimization to a
# sibling file named `foo.result`.
#
# The left-hand sides are processed in smallest-to-largest order. This helps
# give you initial results more quickly, but does mean that progress will slow
# down as we encounter larger and larger left-hand sides.
#
# Usage:
#
# run-souper.sh path/to/souper-check path/to/left-hand-sides
set -e
# Knobs for configuring how large of right-hand sides Souper should try to
# generate and how much time we give it to synthesize a result. Feel free to
# play with these!
MAX_INSTS=3
TIMEOUT=5s
# Run Souper on one left-hand side.
function run_one {
local souper=$1
local lhs=$2
local rhs="$lhs".result
if [[ -f "$rhs" ]]; then
return
fi
local temp=$(mktemp)
local cmd="taskset --cpu-list 0-3 $souper --infer-rhs -souper-enumerative-synthesis-max-instructions=$MAX_INSTS $lhs > $temp"
set +e
$(which timeout) --foreground --kill-after=1s $TIMEOUT bash -c "$cmd"
local exit_code="$?"
set -e
case "$exit_code" in
"0")
# Success! Copy the RHS to its final destination.
cp $lhs $rhs
cat "$temp" >> "$rhs"
;;
# SIGINT. Exit this whole script.
"130")
exit 1
;;
# Timeout (regular).
"124")
return
;;
# Timeout (with SIGKILL).
"137")
return
;;
# Something else.
*)
exit 1
esac
}
# Run Souper on all the left-hand sides.
function main {
local souper=$1
local lhs_dir=$2
local lhs_count=$(ls -1 $lhs_dir | grep -v result | wc -l)
echo "Processing $lhs_count left-hand sides."
cd "$lhs_dir"
local i=0;
for lhs in $(ls -1S $lhs_dir); do
# Ignore '.result' files.
if $(echo "$lhs" | grep -q result); then
continue;
fi
i=$(( $i + 1 ))
if (( $i % 5 == 0 )); then
local percent=$(( $i * 100 / $lhs_count ))
echo "$i / $lhs_count ($percent%)"
fi
run_one "$souper" "$lhs"
done
echo "Done!"
}
# Kick everything off!
main $1 $2