This repository has been archived by the owner on Oct 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 320
/
buildPGO.sh
66 lines (55 loc) · 1.73 KB
/
buildPGO.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
#!/bin/sh
# This build is used to compile an instrumented version of the binary, run it, and then optimize the binary with the profiling data.
# LTO is also enabled by default by this script.
# On clang, this results in a +60% speed boost compared to using just "make" (w/o LTO)
#
# Rom files must be copied to the PGOHelper/PGOGames folder beforehand - all *.nes files in that folder will be executed as part of the profiling process.
# Using a variety of roms is recommended (e.g different mappers, etc.)
#
# You can run this script via make:
# For clang, run "make pgo"
# For GCC, run "USE_GCC=true make pgo"
#
# Note: While GCC runs through this script just fine, the runtime performance is pretty terrible (something must be wrong with the way this is built)
#
# This will produce the following binary: bin/x64/Release/Mesen.exe
if [ "$MESENPLATFORM" = x86 ]; then
PLAT="x86"
else
PLAT="x64"
fi
if [ "$BUILDTARGET" = libretro ]; then
TARG="libretro"
else
TARG="core"
fi
OBJ="PGOHelper/obj.${PLAT}/"
FLAGS="LTO=true STATICLINK=true MESENPLATFORM=${PLAT}"
eval ${FLAGS} make clean
#create instrumented binary
eval ${FLAGS} PGO=profile make ${TARG} -j 16
eval ${FLAGS} PGO=profile make pgohelper -B
eval cp bin/pgohelperlib.so ${OBJ}
#run the instrumented binary
cd ${OBJ}
./pgohelper
cd ..
if [ "$USE_GCC" != true ]; then
#clang-specific steps to convert the profiling data and clean the files
llvm-profdata merge -output=pgo.profdata pgo.profraw
cd ..
eval ${FLAGS} make clean
else
cd ..
fi
if [ "$BUILDTARGET" = "" ]; then
TARG=""
fi
#rebuild using the profiling data to optimize
eval ${FLAGS} PGO=optimize make ${TARG} -j 16 -B
if [ "$USE_GCC" != true ]; then
rm PGOHelper/pgo.profdata
rm PGOHelper/pgo.profraw
else
rm ./*.gcda
fi