This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
forked from banach-space/llvm-tutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driverLSQ.sh
executable file
·89 lines (74 loc) · 3.32 KB
/
driverLSQ.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
84
85
86
87
88
89
#!/bin/bash
# $1 - sim/emu/hw
# $2 - filename to compile
# $3 - Q_SIZE (optional, default 8)
# $4 - -d (Debug flag, optional. If passed, temporary files are preserved.)
set -e
SRC_FILE="$2"
Q_SIZE=${3:-8}
if [[ "$3" == *"-d"* ]] # Case with a debug flag but no Q_SIZE specified.
then
Q_SIZE=8
fi
CANONICALIZED_SRC_FILE="$2".format.cpp
AST_TRANSFORMED_SRC_FILE="$2".tmp.cpp
SRC_FILE_BASENAME=`basename "$2"`
SRC_FILE_DIR=`dirname "$2"`
LOOP_REPORT_FILE="$SRC_FILE_DIR/loop-raw-report.json"
mkdir -p "$SRC_FILE_DIR/bin"
FINAL_BINARY="$SRC_FILE_DIR/bin/${SRC_FILE_BASENAME%.*}.lsq_$Q_SIZE.fpga_$1"
###
### STAGE 0: Ensure a canonical kernel call: queue.single_task<> submission on one line, no empty lines, no commnets.
###
gcc -fpreprocessed -dD -E $SRC_FILE > "$SRC_FILE"_no_comments
sed -i '1,1d' "$SRC_FILE"_no_comments # gcc adds a line --> remove it
$LT_LLVM_INSTALL_DIR/build/bin/clang-format --style="{ColumnLimit: 2000, MaxEmptyLinesToKeep: 0}" "$SRC_FILE"_no_comments > $CANONICALIZED_SRC_FILE
rm "$SRC_FILE"_no_comments
###
### STAGE 1: Get IR of original source and prepare it for mem dep analysis.
###
./scripts/compilation/compile_to_bc.sh "$1" $CANONICALIZED_SRC_FILE
./scripts/compilation/prepare_ir.sh $CANONICALIZED_SRC_FILE.bc
###
### STAGE 2: Generate analysis json report.
###
export LOOP_RAW_REPORT=$LOOP_REPORT_FILE
$LT_LLVM_INSTALL_DIR/build/bin/opt -load-pass-plugin $LLVM_SYCL_PASSES_DIR/build/lib/libDataHazardAnalysisPrinter.so \
-passes=data-hazard-report $CANONICALIZED_SRC_FILE.bc -o /dev/null > $LOOP_REPORT_FILE
###
### STAGE 3: Generate kernel & pipe scaffolding code based on report.
###
# Given json report, make kernel copies and pipe read/write calls from correct kernels.
# The json report provides a precise src location range for the kernel body.
# Nothing else is required (no variable/array names, etc.).
python3 scripts/ast/ASTTransformLSQ.py $LOOP_REPORT_FILE $CANONICALIZED_SRC_FILE $AST_TRANSFORMED_SRC_FILE $Q_SIZE
# Make the AST transformed code pretty
$LT_LLVM_INSTALL_DIR/build/bin/clang-format $AST_TRANSFORMED_SRC_FILE > $AST_TRANSFORMED_SRC_FILE.tmp
mv $AST_TRANSFORMED_SRC_FILE.tmp $AST_TRANSFORMED_SRC_FILE
###
### STAGE 4: Fix IR inside kernels.
###
echo ">> Running lsq-transform"
# Get IR of source with kernels and pipes instantiated.
./scripts/compilation/compile_to_bc.sh "$1" $AST_TRANSFORMED_SRC_FILE
./scripts/compilation/prepare_ir.sh $AST_TRANSFORMED_SRC_FILE.bc
$LT_LLVM_INSTALL_DIR/build/bin/opt -load-pass-plugin $LLVM_SYCL_PASSES_DIR/build/lib/libLoadStoreQueueTransform.so \
-passes=lsq-transform $AST_TRANSFORMED_SRC_FILE.bc -o $AST_TRANSFORMED_SRC_FILE.out.bc
###
### STAGE 5: Produce final binary.
###
echo ">> Compiling $FINAL_BINARY"
# Cleanup the transformed IR. The transformation leaves a lot of dead code, unused kernel args, etc.
./scripts/compilation/cleanup_ir.sh $AST_TRANSFORMED_SRC_FILE.out.bc
./scripts/compilation/compile_from_bc.sh $1 $AST_TRANSFORMED_SRC_FILE.out.bc $AST_TRANSFORMED_SRC_FILE $FINAL_BINARY
# Remove created temporaried, if the "-d" flag was not supplied.
if [[ "$*" != *"-d"* ]]
then
rm -f $CANONICALIZED_SRC_FILE
rm -f $CANONICALIZED_SRC_FILE.bc
rm -f $AST_TRANSFORMED_SRC_FILE
rm -f $AST_TRANSFORMED_SRC_FILE.bc
rm -f $AST_TRANSFORMED_SRC_FILE.out.bc
rm -f $LOOP_REPORT_FILE
fi
echo "done"