Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/cranelift/run-souper.sh
1685 views
1
#!/usr/bin/env bash
2
3
# Runs Souper on the LHSes that were harvested by `clif-util
4
# souper-harvest`.
5
#
6
# This script takes two inputs:
7
#
8
# 1. The `souper-check` binary, and
9
# 2. The directory of harvested left-hand sides (aka the `-o $directory` you
10
# specified to `clif-util souper-harvest`).
11
#
12
# For a left-hand side file `foo` that Souper successfully synthesized a
13
# right-hand side for, this script will write the whole optimization to a
14
# sibling file named `foo.result`.
15
#
16
# The left-hand sides are processed in smallest-to-largest order. This helps
17
# give you initial results more quickly, but does mean that progress will slow
18
# down as we encounter larger and larger left-hand sides.
19
#
20
# Usage:
21
#
22
# run-souper.sh path/to/souper-check path/to/left-hand-sides
23
24
set -e
25
26
# Knobs for configuring how large of right-hand sides Souper should try to
27
# generate and how much time we give it to synthesize a result. Feel free to
28
# play with these!
29
MAX_INSTS=3
30
TIMEOUT=5s
31
32
# Run Souper on one left-hand side.
33
function run_one {
34
local souper=$1
35
local lhs=$2
36
local rhs="$lhs".result
37
38
if [[ -f "$rhs" ]]; then
39
return
40
fi
41
42
local temp=$(mktemp)
43
local cmd="taskset --cpu-list 0-3 $souper --infer-rhs -souper-enumerative-synthesis-max-instructions=$MAX_INSTS $lhs > $temp"
44
45
set +e
46
$(which timeout) --foreground --kill-after=1s $TIMEOUT bash -c "$cmd"
47
local exit_code="$?"
48
set -e
49
50
case "$exit_code" in
51
"0")
52
# Success! Copy the RHS to its final destination.
53
cp $lhs $rhs
54
cat "$temp" >> "$rhs"
55
;;
56
57
# SIGINT. Exit this whole script.
58
"130")
59
exit 1
60
;;
61
62
# Timeout (regular).
63
"124")
64
return
65
;;
66
67
# Timeout (with SIGKILL).
68
"137")
69
return
70
;;
71
72
# Something else.
73
*)
74
exit 1
75
esac
76
77
}
78
79
# Run Souper on all the left-hand sides.
80
function main {
81
local souper=$1
82
local lhs_dir=$2
83
local lhs_count=$(ls -1 $lhs_dir | grep -v result | wc -l)
84
85
echo "Processing $lhs_count left-hand sides."
86
87
cd "$lhs_dir"
88
89
local i=0;
90
for lhs in $(ls -1S $lhs_dir); do
91
# Ignore '.result' files.
92
if $(echo "$lhs" | grep -q result); then
93
continue;
94
fi
95
96
i=$(( $i + 1 ))
97
if (( $i % 5 == 0 )); then
98
local percent=$(( $i * 100 / $lhs_count ))
99
echo "$i / $lhs_count ($percent%)"
100
fi
101
102
run_one "$souper" "$lhs"
103
done
104
105
echo "Done!"
106
}
107
108
# Kick everything off!
109
main $1 $2
110
111