fix warnings
[pluto.git] / vloog
blobc78f98c8f18631bdc428cded253da2829ee1cbfe
1 #!/bin/bash
3 # VLooG: Vector pragma adder, helper script for pluto
5 # Syntax
6 #
7 # vloog <C file>
9 #
10 # Reads contents of .vectorize and generate ivdep pragmas for those loops
11 # after replacing their bounds by scalars. This allows ICC to auto-vectorize
12 # those loops. .vectorize is created by the pluto core.
14 # Author: Uday Bondhugula
16 # Available under GNU GPL version 3 or (at your option) any later version
18 # This script is called by polycc
21 match_closing_brace() {
23 grep -n [{}] $1 > loopopenclose
24 sed -n -e '/^'$2':/,$p' loopopenclose > cut
26 open=0
27 numclose=0
28 #cat cut
29 while read -n1 char; do
30 #do something with the byte in $char
31 #echo $open $clos $char
32 if [ "$char" == "{" ]; then
33 open=$(($open+1))
34 elif [ "$char" == "}" ]; then
35 numclose=$(($numclose+1))
36 open=$(($open-1))
37 if [ $open == 0 ]; then
38 #echo $numclose
39 break
42 done <cut
44 cat cut | grep "}" > closecut
46 closing_brace_linenum=`sed -n -e ''$numclose'p' closecut | awk '{split($1,t,":"); print t[1]}'`
48 rm -f cut loopopenclose closecut
50 echo $closing_brace_linenum > closenum
51 return $closing_brace_linenum
55 if [ ! -f .vectorize ]; then
56 exit 2
59 numlines=`wc -l .vectorize | awk '{print $1}'`
61 if [ $numlines == "0" ]; then
62 exit 3
66 # Vectorization pragma for ICC
67 VECDIM=`cat .vectorize`
69 LINE_NUMBERS=`grep -n "for ($VECDIM.*=" $1 | awk '{split($1,t,":"); print t[1]}'`
71 j=0
72 for num in $LINE_NUMBERS; do
74 LOOP=`sed -n -e ''$(($num+5*$j))'p' $1`
76 match_closing_brace $1 $(($num+5*$j))
77 closing_brace=`cat closenum`
78 if [ $closing_brace -lt $num ]; then
79 echo "Vectorizer failed!"
80 exit 4
83 sed -n -e '1,'$(($num+5*$j-1))'p' $1 > .header
84 sed -n -e ''$(($closing_brace+1))',$p' $1 > .footer
85 sed -n -e ''$(($num+5*$j+1))','$closing_brace'p' $1 > .body
87 # everything from tr is a hack for ancc generated code
88 sed -n -e ''$(($num+5*$j))'p' $1 | tr -d ' ' | sed -e 's/for/for /' > .vecloop
90 # lower and upper bounds
91 echo -ne "{\n\tlbv="`awk '{split($2,t,";"); split(t[1],u,"="); print u[2] }' .vecloop`"; " > .lbv
92 echo -e "\tubv="`awk '{split($2,t,";"); split(t[2],u,"="); print u[2] }' .vecloop`";" > .ubv
94 cat .header .lbv .ubv > $1
95 echo -e "#pragma ivdep\n#pragma vector always\n\tfor ($VECDIM=lbv; $VECDIM<=ubv; $VECDIM++) {" >> $1
96 cat .body >> $1
97 echo "}" >> $1
98 cat .footer >> $1
100 j=$(($j+1))
101 done
102 echo "[Vloog] added vectorization pragmas on $j loop(s)"
104 rm -f .header .lbv .ubv .header .footer .vecloop .footer .body closenum