-
Notifications
You must be signed in to change notification settings - Fork 0
/
vloog
executable file
·104 lines (79 loc) · 2.63 KB
/
vloog
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
#!/bin/bash
#
# VLooG: Vector pragma adder, helper script for pluto
# Syntax
#
# vloog <C file>
#
#
# Reads contents of .vectorize and generate ivdep pragmas for those loops
# after replacing their bounds by scalars. This allows ICC to auto-vectorize
# those loops. .vectorize is created by the pluto core.
#
# Author: Uday Bondhugula
# Available under GNU GPL version 3 or (at your option) any later version
#
# This script is called by polycc
#
match_closing_brace() {
grep -n [{}] $1 > loopopenclose
sed -n -e '/^'$2':/,$p' loopopenclose > cut
open=0
numclose=0
#cat cut
while read -n1 char; do
#do something with the byte in $char
#echo $open $clos $char
if [ "$char" == "{" ]; then
open=$(($open+1))
elif [ "$char" == "}" ]; then
numclose=$(($numclose+1))
open=$(($open-1))
if [ $open == 0 ]; then
#echo $numclose
break
fi
fi
done <cut
cat cut | grep "}" > closecut
closing_brace_linenum=`sed -n -e ''$numclose'p' closecut | awk '{split($1,t,":"); print t[1]}'`
rm -f cut loopopenclose closecut
echo $closing_brace_linenum > closenum
return $closing_brace_linenum
}
if [ ! -f .vectorize ]; then
exit 2
fi
numlines=`wc -l .vectorize | awk '{print $1}'`
if [ $numlines == "0" ]; then
exit 3
fi
# Vectorization pragma for ICC
VECDIM=`cat .vectorize`
LINE_NUMBERS=`grep -n "for ($VECDIM.*=" $1 | awk '{split($1,t,":"); print t[1]}'`
j=0
for num in $LINE_NUMBERS; do
LOOP=`sed -n -e ''$(($num+5*$j))'p' $1`
match_closing_brace $1 $(($num+5*$j))
closing_brace=`cat closenum`
if [ $closing_brace -lt $num ]; then
echo "Vectorizer failed!"
exit 4
fi
sed -n -e '1,'$(($num+5*$j-1))'p' $1 > .header
sed -n -e ''$(($closing_brace+1))',$p' $1 > .footer
sed -n -e ''$(($num+5*$j+1))','$closing_brace'p' $1 > .body
# everything from tr is a hack for ancc generated code
sed -n -e ''$(($num+5*$j))'p' $1 | tr -d ' ' | sed -e 's/for/for /' > .vecloop
# lower and upper bounds
echo -ne "{\n\tlbv="`awk '{split($2,t,";"); split(t[1],u,"="); print u[2] }' .vecloop`"; " > .lbv
echo -e "\tubv="`awk '{split($2,t,";"); split(t[2],u,"="); print u[2] }' .vecloop`";" > .ubv
cat .header .lbv .ubv > $1
echo -e "#pragma ivdep\n#pragma vector always\n\tfor ($VECDIM=lbv; $VECDIM<=ubv; $VECDIM++) {" >> $1
cat .body >> $1
echo "}" >> $1
cat .footer >> $1
j=$(($j+1))
done
echo "[Vloog] added vectorization pragmas on $j loop(s)"
rm -f .header .lbv .ubv .header .footer .vecloop .footer .body closenum