-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·83 lines (65 loc) · 2.27 KB
/
run.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
#!/bin/bash
# Example usage: ./run.sh -bo hw2perf1 > hw2perf1_opt.txt
set -Eeuo pipefail
# b = view LLVM bytecode
# o = run OptimizeASan pass
VIEW_BYTECODE=0
RUN_ASAN=0
RUN_OPT_ASAN=0
while getopts "bao" opt; do
case $opt in
b)
VIEW_BYTECODE=1
;;
a)
RUN_ASAN=1
;;
o)
RUN_OPT_ASAN=1
;;
esac
done
shift $((OPTIND - 1))
TESTCASE=$1
# Convert source code into LLVM bytecode.
clang -Xclang -disable-O0-optnone -emit-llvm $TESTCASE.cpp -c -o $TESTCASE.bc
# Canonicalize natural loops.
opt -passes='loop-simplify' $TESTCASE.bc -o $TESTCASE.out.bc
mv $TESTCASE.out.bc $TESTCASE.bc
# Add profiling instrumentation.
opt -passes='pgo-instr-gen,instrprof' $TESTCASE.bc -o $TESTCASE.prof.bc
# Generate executable from profiling code.
clang -fprofile-instr-generate -x ir $TESTCASE.prof.bc -o $TESTCASE.prof.exe
# Run profiler-embedded executable, which generates a default.profraw file.
# We discard the output into /dev/null.
./$TESTCASE.prof.exe ~ > /dev/null
# Convert profiling data into LLVM form.
llvm-profdata merge -o $TESTCASE.profdata default.profraw
# The "Profile Guided Optimization Use" pass attaches the profile data to the .bc file.
opt -passes="pgo-instr-use" -o $TESTCASE.bc -pgo-test-profile-file=$TESTCASE.profdata < $TESTCASE.prof.bc > /dev/null
# Now, our .bc file is augmented with the profile data.
# Below, we run our own passes.
# Run mem2reg.
opt -mem2reg $TESTCASE.bc -o $TESTCASE.out.bc
mv $TESTCASE.out.bc $TESTCASE.bc
# Run loop-rotate.
opt -loop-rotate $TESTCASE.bc -o $TESTCASE.out.bc
mv $TESTCASE.out.bc $TESTCASE.bc
if [ "$RUN_OPT_ASAN" -eq 1 ]; then
# Run OptimizeASan.
opt -enable-new-pm=0 -load build/optimize_asan/LLVMPJT_OPTIMIZE_ASAN.so -optimize_asan < $TESTCASE.bc > $TESTCASE.out.bc
mv $TESTCASE.out.bc $TESTCASE.bc
fi
if [ "$RUN_ASAN" -eq 1 ]; then
# Run ASan instrumentation.
opt -enable-new-pm=0 -load build/asan/LLVMPJT_ASAN.so -asan < $TESTCASE.bc > $TESTCASE.out.bc
mv $TESTCASE.out.bc $TESTCASE.bc
fi
if [ "$VIEW_BYTECODE" -eq 1 ]; then
# Show bytecode.
llvm-dis $TESTCASE.bc -o -
else
# Compile executable and benchmark its performance.
clang -lasan -x ir $TESTCASE.bc -o $TESTCASE.exe
time ./$TESTCASE.exe > /dev/null
fi