1#!/bin/sh -a 2 3echo "--> 1. Create LLVM-IR from C" 4clang -S -emit-llvm matmul.c -Xclang -disable-O0-optnone -o matmul.ll 5 6echo "--> 2. Prepare the LLVM-IR for Polly" 7opt -S -polly-canonicalize matmul.ll -o matmul.preopt.ll 8 9echo "--> 3. Show the SCoPs detected by Polly" 10opt -basic-aa -polly-ast -analyze matmul.preopt.ll \ 11 -polly-process-unprofitable -polly-use-llvm-names 12 13echo "--> 4.1 Highlight the detected SCoPs in the CFGs of the program" 14# We only create .dot files, as directly -view-scops directly calls graphviz 15# which would require user interaction to continue the script. 16# opt -basic-aa -view-scops -disable-output matmul.preopt.ll 17opt -basic-aa -dot-scops -disable-output matmul.preopt.ll -polly-use-llvm-names 18 19echo "--> 4.2 Highlight the detected SCoPs in the CFGs of the program (print \ 20no instructions)" 21# We only create .dot files, as directly -view-scops-only directly calls 22# graphviz which would require user interaction to continue the script. 23# opt -basic-aa -view-scops-only -disable-output matmul.preopt.ll 24opt -basic-aa -dot-scops-only -disable-output matmul.preopt.ll -polly-use-llvm-names 25 26echo "--> 4.3 Create .png files from the .dot files" 27for i in `ls *.dot`; do dot -Tpng $i > $i.png; done 28 29echo "--> 5. View the polyhedral representation of the SCoPs" 30opt -basic-aa -polly-scops -analyze matmul.preopt.ll \ 31 -polly-process-unprofitable -polly-use-llvm-names 32 33echo "--> 6. Show the dependences for the SCoPs" 34opt -basic-aa -polly-dependences -analyze matmul.preopt.ll \ 35 -polly-process-unprofitable -polly-use-llvm-names 36 37echo "--> 7. Export jscop files" 38opt -basic-aa -polly-export-jscop matmul.preopt.ll \ 39 -polly-process-unprofitable -disable-output -polly-use-llvm-names 40 41echo "--> 8. Import the updated jscop files and print the new SCoPs. (optional)" 42opt -basic-aa -polly-import-jscop -polly-ast -analyze matmul.preopt.ll \ 43 -polly-process-unprofitable -polly-use-llvm-names 44opt -basic-aa -polly-import-jscop -polly-ast -analyze matmul.preopt.ll \ 45 -polly-import-jscop-postfix=interchanged -polly-process-unprofitable -polly-use-llvm-names 46opt -basic-aa -polly-import-jscop -polly-ast -analyze matmul.preopt.ll \ 47 -polly-import-jscop-postfix=interchanged+tiled -polly-process-unprofitable -polly-use-llvm-names 48opt -basic-aa -polly-import-jscop -polly-ast -analyze matmul.preopt.ll \ 49 -polly-import-jscop-postfix=interchanged+tiled+vector \ 50 -polly-process-unprofitable -polly-use-llvm-names 51 52echo "--> 9. Codegenerate the SCoPs" 53opt -S -basic-aa -polly-import-jscop -polly-import-jscop-postfix=interchanged \ 54 -polly-codegen -polly-process-unprofitable -polly-use-llvm-names \ 55 matmul.preopt.ll | opt -O3 -S -o matmul.polly.interchanged.ll 56opt -S -basic-aa -polly-import-jscop \ 57 -polly-import-jscop-postfix=interchanged+tiled -polly-codegen \ 58 matmul.preopt.ll -polly-process-unprofitable -polly-use-llvm-names \ 59 | opt -O3 -S -o matmul.polly.interchanged+tiled.ll 60opt -S -basic-aa -polly-import-jscop -polly-process-unprofitable\ 61 -polly-import-jscop-postfix=interchanged+tiled+vector -polly-codegen \ 62 matmul.preopt.ll -polly-vectorizer=polly -polly-use-llvm-names \ 63 | opt -O3 -S -o matmul.polly.interchanged+tiled+vector.ll 64opt -S -basic-aa -polly-import-jscop -polly-process-unprofitable\ 65 -polly-import-jscop-postfix=interchanged+tiled+vector -polly-codegen \ 66 matmul.preopt.ll -polly-vectorizer=polly -polly-parallel -polly-use-llvm-names \ 67 | opt -O3 -S -o matmul.polly.interchanged+tiled+vector+openmp.ll 68opt -S matmul.preopt.ll | opt -O3 -S -o matmul.normalopt.ll 69 70echo "--> 10. Create the executables" 71llc matmul.polly.interchanged.ll -o matmul.polly.interchanged.s -relocation-model=pic 72gcc matmul.polly.interchanged.s -o matmul.polly.interchanged.exe 73llc matmul.polly.interchanged+tiled.ll -o matmul.polly.interchanged+tiled.s -relocation-model=pic 74gcc matmul.polly.interchanged+tiled.s -o matmul.polly.interchanged+tiled.exe 75llc matmul.polly.interchanged+tiled+vector.ll -o matmul.polly.interchanged+tiled+vector.s -relocation-model=pic 76gcc matmul.polly.interchanged+tiled+vector.s -o matmul.polly.interchanged+tiled+vector.exe 77llc matmul.polly.interchanged+tiled+vector+openmp.ll -o matmul.polly.interchanged+tiled+vector+openmp.s -relocation-model=pic 78gcc matmul.polly.interchanged+tiled+vector+openmp.s -lgomp -o matmul.polly.interchanged+tiled+vector+openmp.exe 79llc matmul.normalopt.ll -o matmul.normalopt.s -relocation-model=pic 80gcc matmul.normalopt.s -lgomp -o matmul.normalopt.exe 81 82echo "--> 11. Compare the runtime of the executables" 83 84echo "time ./matmul.normalopt.exe" 85time -f "%E real, %U user, %S sys" ./matmul.normalopt.exe 86echo "time ./matmul.polly.interchanged.exe" 87time -f "%E real, %U user, %S sys" ./matmul.polly.interchanged.exe 88echo "time ./matmul.polly.interchanged+tiled.exe" 89time -f "%E real, %U user, %S sys" ./matmul.polly.interchanged+tiled.exe 90echo "time ./matmul.polly.interchanged+tiled+vector.exe" 91time -f "%E real, %U user, %S sys" ./matmul.polly.interchanged+tiled+vector.exe 92echo "time ./matmul.polly.interchanged+tiled+vector+openmp.exe" 93time -f "%E real, %U user, %S sys" ./matmul.polly.interchanged+tiled+vector+openmp.exe 94