94 lines · bash
1#!/bin/sh -a2 3echo "--> 1. Create LLVM-IR from C"4clang -S -emit-llvm matmul.c -Xclang -disable-O0-optnone -o matmul.ll5 6echo "--> 2. Prepare the LLVM-IR for Polly"7opt -S -polly-canonicalize matmul.ll -o matmul.preopt.ll8 9echo "--> 3. Show the SCoPs detected by Polly"10opt -basic-aa -polly-ast -analyze matmul.preopt.ll \11 -polly-process-unprofitable -polly-use-llvm-names12 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 graphviz15# which would require user interaction to continue the script.16# opt -basic-aa -view-scops -disable-output matmul.preopt.ll17opt -basic-aa -dot-scops -disable-output matmul.preopt.ll -polly-use-llvm-names18 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 calls22# graphviz which would require user interaction to continue the script.23# opt -basic-aa -view-scops-only -disable-output matmul.preopt.ll24opt -basic-aa -dot-scops-only -disable-output matmul.preopt.ll -polly-use-llvm-names25 26echo "--> 4.3 Create .png files from the .dot files"27for i in `ls *.dot`; do dot -Tpng $i > $i.png; done28 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-names32 33echo "--> 6. Show the dependences for the SCoPs"34opt -basic-aa -polly-dependences -analyze matmul.preopt.ll \35 -polly-process-unprofitable -polly-use-llvm-names36 37echo "--> 7. Export jscop files"38opt -basic-aa -polly-export-jscop matmul.preopt.ll \39 -polly-process-unprofitable -disable-output -polly-use-llvm-names40 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-names44opt -basic-aa -polly-import-jscop -polly-ast -analyze matmul.preopt.ll \45 -polly-import-jscop-postfix=interchanged -polly-process-unprofitable -polly-use-llvm-names46opt -basic-aa -polly-import-jscop -polly-ast -analyze matmul.preopt.ll \47 -polly-import-jscop-postfix=interchanged+tiled -polly-process-unprofitable -polly-use-llvm-names48opt -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-names51 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.ll56opt -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.ll60opt -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.ll64opt -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.ll68opt -S matmul.preopt.ll | opt -O3 -S -o matmul.normalopt.ll69 70echo "--> 10. Create the executables"71llc matmul.polly.interchanged.ll -o matmul.polly.interchanged.s -relocation-model=pic72gcc matmul.polly.interchanged.s -o matmul.polly.interchanged.exe73llc matmul.polly.interchanged+tiled.ll -o matmul.polly.interchanged+tiled.s -relocation-model=pic74gcc matmul.polly.interchanged+tiled.s -o matmul.polly.interchanged+tiled.exe75llc matmul.polly.interchanged+tiled+vector.ll -o matmul.polly.interchanged+tiled+vector.s -relocation-model=pic76gcc matmul.polly.interchanged+tiled+vector.s -o matmul.polly.interchanged+tiled+vector.exe77llc matmul.polly.interchanged+tiled+vector+openmp.ll -o matmul.polly.interchanged+tiled+vector+openmp.s -relocation-model=pic78gcc matmul.polly.interchanged+tiled+vector+openmp.s -lgomp -o matmul.polly.interchanged+tiled+vector+openmp.exe79llc matmul.normalopt.ll -o matmul.normalopt.s -relocation-model=pic80gcc matmul.normalopt.s -lgomp -o matmul.normalopt.exe81 82echo "--> 11. Compare the runtime of the executables"83 84echo "time ./matmul.normalopt.exe"85time -f "%E real, %U user, %S sys" ./matmul.normalopt.exe86echo "time ./matmul.polly.interchanged.exe"87time -f "%E real, %U user, %S sys" ./matmul.polly.interchanged.exe88echo "time ./matmul.polly.interchanged+tiled.exe"89time -f "%E real, %U user, %S sys" ./matmul.polly.interchanged+tiled.exe90echo "time ./matmul.polly.interchanged+tiled+vector.exe"91time -f "%E real, %U user, %S sys" ./matmul.polly.interchanged+tiled+vector.exe92echo "time ./matmul.polly.interchanged+tiled+vector+openmp.exe"93time -f "%E real, %U user, %S sys" ./matmul.polly.interchanged+tiled+vector+openmp.exe94