-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
106 lines (78 loc) · 4.75 KB
/
Makefile
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
CSICLANG?=$(LLVM_BIN)/clang
CSICLANGPP?=$(LLVM_BIN)/clang++
LLVMLINK?=$(LLVM_BIN)/llvm-link
CLANGVER?=7.0.0
EXTRAFLAGS?=""
ifdef BACKTRACELIB
EXTRAFLAGS+= -DUSE_BACKTRACE
endif
CXXFLAGS?=-O3 -g -std=c++11 $(EXTRAFLAGS)
BCFLAGS?=$(CXXFLAGS)
all: check-vars check-files instr normal debug
check-vars:
ifndef LLVM_DIR
$(error LLVM_DIR is undefined - please define LLVM_DIR as the directory containing the source of LLVM, e.g. /whatever/llvm)
endif
ifndef LLVM_BIN
$(error LLVM_BIN is undefined - please define LLVM_BIN as the directory containing the binaries of LLVM, e.g. /whatever/llvm/build/bin)
endif
memoryhook.so: MemoryHook.cpp
ifdef BACKTRACELIB
$(CSICLANGPP) $(CXXFLAGS) -I $(BACKTRACELIB) -fPIC -shared MemoryHook.cpp -o memoryhook.so
else
$(CSICLANGPP) $(CXXFLAGS) -fPIC -shared MemoryHook.cpp -o memoryhook.so
endif
# Some checks that files exist.
check-files:
@test -s $(LLVM_DIR)/projects/compiler-rt/lib/csi/csirt.c || { echo "LLVM does not contain CSI in projects/compiler-rt! Exiting."; exit 1; }
@test -s $(LLVM_BIN)/../lib/clang/$(CLANGVER)/lib/linux/libclang_rt.csi-x86_64.a || { echo "LLVM does not contain the CSI runtime in the lib folder! Exiting."; exit 1; }
toolheaders: OutputPrinter.h MemPoolVector.h SeriesParallelDAG.h hooks.h common.h SPEdgeProducer.h Nullable.h SingleThreadPool.h
touch toolheaders
# These targets build the tool (first compiling to IR, and then to object files).
tool1.bc: hooks.cpp toolheaders
$(CSICLANGPP) $(BCFLAGS) -O3 -S -emit-llvm hooks.cpp -o tool1.bc
tool2.bc: hooks2.cpp toolheaders
$(CSICLANGPP) $(BCFLAGS) -O3 -S -emit-llvm hooks2.cpp -o tool2.bc
tool3.bc: FullSPDAG.cpp toolheaders
$(CSICLANGPP) $(BCFLAGS) -O3 -S -emit-llvm FullSPDAG.cpp -o tool3.bc
tool4.bc: SPComponent.cpp toolheaders
$(CSICLANGPP) $(BCFLAGS) -O3 -S -emit-llvm SPComponent.cpp -o tool4.bc
tool5.bc: BareboneSPDAG.cpp toolheaders
$(CSICLANGPP) $(BCFLAGS) -O3 -S -emit-llvm BareboneSPDAG.cpp -o tool5.bc
tool.bc: tool1.bc tool2.bc tool3.bc tool4.bc tool5.bc
$(LLVMLINK) tool1.bc tool2.bc tool3.bc tool4.bc tool5.bc -o tool.bc
hooks1.o: hooks.cpp toolheaders
$(CSICLANGPP) $(CXXFLAGS) -c hooks.cpp -o hooks1.o
hooks2.o: hooks2.cpp toolheaders
$(CSICLANGPP) $(CXXFLAGS) -c hooks2.cpp -o hooks2.o
hooks3.o: FullSPDAG.cpp toolheaders
$(CSICLANGPP) $(CXXFLAGS) -c FullSPDAG.cpp -o hooks3.o
hooks4.o: SPComponent.cpp toolheaders
$(CSICLANGPP) $(CXXFLAGS) -c SPComponent.cpp -o hooks4.o
hooks5.o: BareboneSPDAG.cpp toolheaders
$(CSICLANGPP) $(CXXFLAGS) -c BareboneSPDAG.cpp -o hooks5.o
tool.o: hooks1.o hooks2.o hooks3.o hooks4.o hooks5.o
ld -r hooks1.o hooks2.o hooks3.o hooks4.o hooks5.o -o tool.o
# This is where the Cilk program is instrumented. This uses compile-time instrumentation, so it needs the tool's bitcode.
instr.o: tool.bc test.cpp csirt.bc config.txt
$(CSICLANGPP) -fcilkplus $(CXXFLAGS) -c -fcsi=aftertapirloops test.cpp -mllvm -csi-config-mode -mllvm "whitelist" -mllvm -csi-config-filename -mllvm "config.txt" -mllvm -csi-tool-bitcode -mllvm "tool.bc" -mllvm -csi-runtime-bitcode -mllvm "csirt.bc" -mllvm -csi-instrument-basic-blocks=false -mllvm -csi-instrument-memory-accesses=false -mllvm -csi-instrument-atomics=false -mllvm -csi-instrument-memintrinsics=false -mllvm -csi-instrument-allocfn=false -mllvm -csi-instrument-alloca=false -o instr.o
# This target outputs some extra information like the IR and the ASM of the Cilk program after instrumentation.
debug: tool.bc test.cpp csirt.bc
$(CSICLANGPP) -fcilkplus $(CXXFLAGS) -S -emit-llvm -fcsi=aftertapirloops test.cpp -mllvm -csi-tool-bitcode -mllvm "tool.bc" -mllvm -csi-runtime-bitcode -mllvm "csirt.bc" -o ir.txt
$(CSICLANGPP) -fcilkplus -O3 -fverbose-asm -S -masm=intel -fcsi=aftertapirloops test.cpp -mllvm -csi-tool-bitcode -mllvm "tool.bc" -mllvm -csi-runtime-bitcode -mllvm "csirt.bc" -o asm.txt
touch debug
# This target simply builds the Cilk program with no instrumentation at all.
normal: test.cpp
$(CSICLANGPP) $(CXXFLAGS) -fcilkplus test.cpp -o normal
# Link the instrumented program together.
instr: tool.o instr.o memoryhook.so
ifdef BACKTRACELIB
$(CSICLANGPP) $(CXXFLAGS) ./memoryhook.so instr.o tool.o $(LLVM_BIN)/../lib/clang/$(CLANGVER)/lib/linux/libclang_rt.csi-x86_64.a $(BACKTRACELIB)/.libs/libbacktrace.so -lcilkrts -lpthread -o instr
else
$(CSICLANGPP) $(CXXFLAGS) ./memoryhook.so instr.o tool.o $(LLVM_BIN)/../lib/clang/$(CLANGVER)/lib/linux/libclang_rt.csi-x86_64.a -lcilkrts -lpthread -o instr
endif
# Get the bitcode of the CSI runtime.
csirt.bc: $(LLVM_DIR)/projects/compiler-rt/lib/csi/csirt.c
$(CSICLANG) -O3 -c -emit-llvm -std=c11 $(LLVM_DIR)/projects/compiler-rt/lib/csi/csirt.c -o csirt.bc
clean:
rm -f normal instr *.o *.bc ir.txt asm.txt *.so