forked from bondhugula/pluto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polycc.sh.in
116 lines (101 loc) · 2.64 KB
/
polycc.sh.in
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
110
111
112
113
114
115
116
#!/bin/bash
#
# Top-level script that runs all components of the end-to-end
# system
#
# Just run 'polycc <C code>' when the program section to
# be parallelized/optimized around special comments as described
# in the `README'
#
# Copyright (C) 2007-2008 Uday Bondhugula
#
# This file is available under the MIT license. Please see LICENSE in the
# top-level directory for details.
#
pluto=@abs_top_builddir@/tool/pluto
inscop=@abs_top_srcdir@/inscop
# Some additional setup here to ensure that variables are visible outside of the
# run function.
SOURCEFILE=""
OUTFILE=""
dirname=""
PLUTOOUT=""
# check for command-line options
for arg in $*; do
if [ $arg == "--parallel" ]; then
PARALLEL=1
elif [ $arg == "--parallelize" ]; then
PARALLEL=1
elif [ $arg == "--unroll" ]; then
UNROLL=1
elif [ $arg == "--debug" ]; then
DEBUG=1
elif [ $arg == "--moredebug" ]; then
DEBUG=1
elif [ $arg == "-i" ]; then
INDENT=1
elif [ $arg == "--indent" ]; then
INDENT=1
elif [ $arg == "--silent" ]; then
SILENT=1
fi
done
# some special processing for linearized accesses
#if [ "$SOURCEFILE" != "" ]; then
#grep __SPECIAL $SOURCEFILE > .nonlinearized
#grep __SPECIAL $SOURCEFILE | sed -e "s/.*__SPECIAL//" > .linearized
#fi
run()
{
$pluto $* || exit 1
SOURCEFILE=`cat .srcfilename`
OUTFILE=`cat .outfilename`
dirname=`dirname $SOURCEFILE`
basename=`basename $SOURCEFILE`
prefix=`basename $SOURCEFILE .c`
CLOOGFILE=`basename $OUTFILE`.pluto.cloog
PLUTOOUT=$OUTFILE
# put the original skeleton around the transformed code
$inscop $SOURCEFILE $OUTFILE $OUTFILE
if [ "$INDENT" == 1 ] && [ -x /usr/bin/clang-format ]; then
clang-format --style=LLVM -i $OUTFILE
fi
}
run "$*"
WORK=1
TEMPFILE=""
while [ $WORK -eq 1 ]
do
if grep -q "#pragma scop" "$PLUTOOUT"
then
# Move the original file into a temporary location
TEMPFILE="$SOURCEFILE""_temp"
mv $SOURCEFILE $TEMPFILE
# Move the file that still has scope in it into
# place of the original source file, so $* will pick the
# correct file
mv $PLUTOOUT $SOURCEFILE
# Run pluto again
run "$*"
# Move the original back in place
mv $TEMPFILE $SOURCEFILE
else
# No more scops
WORK=0
fi
done
cleanup() {
# An attempt to move the original file back in place
# in the event of an exception.
if [ -f "$TEMPFILE" ]
then
mv $TEMPFILE $SOURCEFILE
fi
if [ "$DEBUG" != 1 ];
then
rm -f .regtile .vectorize .pragmas .params .orcc .linearized .nonlinearized \
$CLOOGFILE .srcfilename .outfilename .distmem pi.cloog sigma.cloog \
*.sysloog .appendfilename
fi
}
trap cleanup SIGINT exit