-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
142 lines (117 loc) · 3.79 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
BVA_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
ifdef BVA_FUNC
$(shell echo $(BVA_FUNC) > BVA_FUNC.txt)
endif
ifdef BVA_FILE
$(shell echo $(BVA_FILE) > BVA_FILE.txt)
endif
ifdef BVA_TYPE
$(shell echo $(BVA_TYPE) > BVA_TYPE.txt)
endif
BVA_FUNC:= $(shell cat BVA_FUNC.txt)
BVA_FILE:= $(shell cat BVA_FILE.txt)
BVA_TYPE:= $(shell cat BVA_TYPE.txt)
file := theBench.txt
ifdef bench
$(shell echo $(bench) > $(file))
endif
bva_option?=-S0 -n5 -N500
bench := $(shell cat ${file})
#BVA_FUNC?=__ieee754_j0
#BVA_FILE?=benchs/fdlibm53/e_j0.c
compilation_level?=-O0
LIBM := benchs/libm_c_ieee.a
Include := -I $(BVA_ROOT)/include -I $(BVA_ROOT)/$(dir $(BVA_FILE))
define BVA_echo
@echo "[DONE] $1 "
endef
CXX := g++ -fPIC -std=c++11
CXXFLAGS := -fno-rtti -O0 -g
CC := clang -fPIC
.PHONY: default clean
all: copy pass instrument representing_function test
debug: DB = -DDEBUG -g
debug: all
hello:
echo "hello, world"
# create .bc from source
%.bc: %.c
$(CC) $(DB) $< -c -emit-llvm -o $@ $(Include)
# create human-readable assembly (.ll) from .bc
%.ll: %.bc
llvm-dis -f $^
%.o: %.bc
$(CC) $(CXXFLAGS) -c -o $@ $<
copy: build/loader.cpp build/loader.py build/test.cpp build/foo_raw.c build/cov.c
$(BVA_echo) Copy some dependencies
build/foo_raw.c: $(BVA_FILE)
@mkdir -p build
cp $^ $@
build/loader.py: src/Type_$(BVA_TYPE)/loader.py
@mkdir -p build
cp $^ $@
build/loader.cpp: src/Type_$(BVA_TYPE)/loader.cpp
@mkdir -p build
cp $^ $@
build/test.cpp: src/Type_$(BVA_TYPE)/test.cpp
@mkdir -p build
cp $^ $@
build/cov.c: src/Type_$(BVA_TYPE)/cov.c
@mkdir -p build
cp $^ $@
instrument: build/foo_i.bc
$(BVA_echo) The instrumented program in LLVM bitcode: $<
build/foo_i.bc : build/foo_raw.bc
opt -lowerswitch $< -o $<
opt -load lib/libATGMO.so -hello2 -funcname=$(BVA_FUNC) < $< -o $@
pass: lib/libATGMO.so
$(BVA_echo) The shared library of the LLVM transformation pass: $<
lib/libATGMO.so: build/ATGMO.o
@mkdir -p lib
$(CXX) $(CXXFLAGS) $(DB) $< -Wall -shared -o $@ -fPIC $(Include)
build/ATGMO.o: src/ATGMO.cpp
@mkdir -p build
$(CXX) $(CXXFLAGS) $(DB) $< -Wall -c -fno-rtti `llvm-config --cppflags` -g -fPIC -o $@ $(Include)
#Put penalty wraper and the instrumented code together (so we have a double->double representing function)
representing_function: build/libr.so
$(BVA_echo) The shared library for the representing function: $<
build/libr.so: lib/pen.o lib/r.o build/foo_i.o build/loader.o benchs/libm_c_ieee.a #the last one is for fdlibm only
$(CXX) $(CXXFLAGS) $(DB) $^ -Wall -shared -o $@ $(Include)
lib/r.o: src/r.cpp
$(CXX) $(CXXFLAGS) $(DB) -c $^ -o $@ $(Include)
lib/pen.o: src/pen.cpp
$(CXX) $(CXXFLAGS) $(DB) -c $^ -o $@ $(Include)
# A very simple test. Usage: LD_LIBRARY_PATH=build build/simple_test
test: build/simple_test
$(BVA_echo) Making sanity test
build/simple_test: build/test.o
g++ -std=c++11 $(DB) $< -Wall -lr -L build -lm -o $@ $(Include)
build/test.o: build/test.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
run_test: build/simple_test
LD_LIBRARY_PATH=build/ $<
clean:
rm -rf build/*
rm -rf lib/*
rm -rf output/*
#for debug purpose
diff: build/foo_raw.ll build/foo_i.ll
diff -u $^
benchmark: all
python src/mcmc.py
make gcov_bva;\
make gcov_rand
br:
cat output/brInfo.txt
gcov_bva: $(BVA_ROOT)/build/cov.c $(BVA_ROOT)/build/foo_raw.c $(BVA_ROOT)/$(LIBM)
cd build;\
gcc -DROOT=\"$(BVA_ROOT)\" -DFUNC=$(BVA_FUNC) $^ -fno-builtin-$(BVA_FUNC) -fprofile-arcs -ftest-coverage -o cov $(Include);\
./cov 0;\
echo ;\
gcov -f $(BVA_ROOT)/build/foo_raw.c -b
gcov_rand: $(BVA_ROOT)/build/cov.c $(BVA_ROOT)/build/foo_raw.c $(BVA_ROOT)/$(LIBM)
cd build;\
gcc -DROOT=\"$(BVA_ROOT)\" -DFUNC=$(BVA_FUNC) $^ -fno-builtin-$(BVA_FUNC) -fprofile-arcs -ftest-coverage -o cov $(Include);\
./cov 1;\
echo ;\
gcov -f $(BVA_ROOT)/build/foo_raw.c -b