-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.sh
236 lines (210 loc) · 5.99 KB
/
utils.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/env bash
# Some common functions and varibles to be sourced by our build scripts
####################
# Global variables #
####################
BUILDDIR="$(pwd)"
export BUILDDIR
export SHALLOW_CLONE=0
export AVX_OPT=0
############
# Jemalloc #
############
export USE_JEMALLOC=0
export JEMALLOC_BUILD_DIR="${BUILDDIR}/jemalloc-build"
jemalloc_fetch_vars() {
if [[ -e "${JEMALLOC_BUILD_DIR}/bin/jemalloc-config" ]]; then
export JEMALLOC_LIB_DIR="$(${JEMALLOC_BUILD_DIR}/bin/jemalloc-config --libdir)"
export JEMALLOC_LIBS="$(${JEMALLOC_BUILD_DIR}/bin/jemalloc-config --libs)"
export JEMALLOC_FLAGS="-L${JEMALLOC_LIB_DIR} -Wl,--push-state -Wl,-whole-archive -ljemalloc_pic -Wl,--pop-state ${JEMALLOC_LIBS}"
export NO_JEMALLOC=0
else
export NO_JEMALLOC=1
fi
}
jemalloc_clone() {
if ! git clone "https://github.com/jemalloc/jemalloc.git" -b "$1" "$2"; then
echo "jemalloc git clone: Failed" >&2
exit 1
fi
}
jemalloc_fetch() {
if ! git "$1" "https://github.com/jemalloc/jemalloc.git" "$2" "$3"; then
echo "jemalloc git $1: Failed" >&2
exit 1
fi
}
################
# LLVM Builder #
################
export CLEAN_BUILD=1
export POLLY_OPT=0
export BOLT_OPT=0
export LLVM_OPT=0
export USE_MOLD=0
export FINAL_INSTALL_DIR="install"
export CI=0
llvm_fetch() {
if ! git "$1" https://github.com/llvm/llvm-project.git "$2"; then
echo "llvm-project git ${1}: Failed" >&2
exit 1
fi
}
get_linux_tarball() {
if [[ -e linux-"$1".tar.xz ]]; then
echo "Existing linux-$1 tarball found, skipping download"
else
echo "Downloading linux-$1 tarball"
wget "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-$1.tar.xz"
fi
tar xf linux-"$1".tar.xz
}
####################
# Binutils builder #
####################
export BINUTILS_DIR="${BUILDDIR}/binutils-gdb"
export INSTALL_DIR="${BUILDDIR}/install"
export BINUTILS_BUILD="${BUILDDIR}/binutils-build"
export NO_UPDATE=0
export COMMON_BINUTILS_ARGS=(
'--disable-docs'
'--disable-gdb'
'--disable-gdbserver'
'--disable-libdecnumber'
'--disable-readline'
'--disable-sim'
'--enable-deterministic-archives'
'--enable-gold'
'--enable-ld=default'
'--enable-lto'
'--enable-new-dtags'
'--enable-plugins'
'--enable-threads'
'--quiet'
'--with-pkgversion=Neutron Binutils'
'--disable-werror'
'--disable-compressed-debug-sections'
)
binutils_clone() {
if ! git clone "https://sourceware.org/git/binutils-gdb.git" -b "binutils-$1-branch" "$2"; then
echo "binutils git clone: Failed" >&2
exit 1
fi
}
binutils_fetch() {
if ! git "$1" "https://sourceware.org/git/binutils-gdb.git" "binutils-$2-branch" "$3"; then
echo "binutils git $1: Failed" >&2
exit 1
fi
}
######################
# Optimization flags #
######################
# AVX2 OPT
export NO_AVX_FLAGS="-mtune=generic"
export BARE_AVX_FLAGS="-mavx -mavx2 -mfma -msse3 -mssse3 -msse4.1 -msse4.2 -mf16c -mprefer-vector-width=256"
export AVX_FLAGS="-mtune=haswell ${BARE_AVX_FLAGS}"
# Polly
export POLLY_PASS_FLAGS=(
"-mllvm -polly"
"-mllvm -polly-vectorizer=stripmine"
"-mllvm -polly-tiling"
"-mllvm -polly-scheduling=dynamic"
"-mllvm -polly-scheduling-chunksize=1"
"-mllvm -polly-run-inliner"
"-mllvm -polly-run-dce"
"-mllvm -polly-reschedule"
"-mllvm -polly-postopts"
"-mllvm -polly-optimizer=isl"
"-mllvm -polly-omp-backend=LLVM"
"-mllvm -polly-num-threads=0"
"-mllvm -polly-loopfusion-greedy"
"-mllvm -polly-isl-arg=--no-schedule-serialize-sccs"
"-mllvm -polly-invariant-load-hoisting"
"-mllvm -polly-dependences-computeout=0"
"-mllvm -polly-dependences-analysis-type=value-based"
"-mllvm -polly-ast-use-context"
)
# Extra LLVM passes
export LLVM_PASS_FLAGS=(
"-mllvm -vectorizer-maximize-bandwidth"
"-mllvm -unroll-runtime-multi-exit"
"-mllvm -slp-vectorize-hor-store"
"-mllvm -extra-vectorizer-passes"
"-mllvm -enable-unroll-and-jam"
"-mllvm -enable-masked-interleaved-mem-accesses"
"-mllvm -enable-loopinterchange"
"-mllvm -enable-loop-flatten"
"-mllvm -enable-loop-distribute"
"-mllvm -enable-interleaved-mem-accesses"
"-mllvm -enable-gvn-hoist=1"
"-mllvm -enable-ext-tsp-block-placement=1"
"-mllvm -enable-dfa-jump-thread=1"
"-mllvm -enable-cond-stores-vec"
"-mllvm -aggressive-ext-opt"
"-mllvm -adce-remove-loops"
)
# BOLT
export BOLT_ARGS=(
"--dyno-stats"
"--eliminate-unreachable"
"--frame-opt=hot"
"--icf=1"
"--plt=hot"
"--reorder-blocks=ext-tsp"
"--reorder-functions=hfsort+"
"--split-all-cold"
"--split-eh"
"--split-functions"
"--thread-count=$(getconf _NPROCESSORS_ONLN)"
"--use-gnu-stack"
)
# Clang
export CLANG_OPT_LDFLAGS="-Wl,-O3,--sort-common,--as-needed,-z,now,--lto-O3,--strip-debug,--gc-sections"
export CLANG_OPT_CFLAGS=(
"-O3"
"-mharden-sls=none"
"-funroll-loops"
"-fsplit-machine-functions"
"-fsplit-lto-unit"
"-freciprocal-math"
"-fomit-frame-pointer"
"-fno-unique-section-names"
"-fno-trapping-math"
"-fno-semantic-interposition"
"-fno-math-errno"
"-flto=thin"
"-ffunction-sections"
"-ffp-contract=fast"
"-fexcess-precision=fast"
"-fdata-sections"
"-fcf-protection=none"
"-falign-functions=32"
)
# GCC
export GCC_OPT_LDFLAGS="-Wl,-O3,--sort-common,--as-needed,-z,now,--strip-debug"
export GCC_OPT_CFLAGS=(
'-O3'
'-ffp-contract=fast'
'-pipe'
'-ffunction-sections'
'-fdata-sections'
'-fgraphite-identity'
'-floop-nest-optimize'
'-falign-functions=32'
'-fno-math-errno'
'-fno-trapping-math'
'-fomit-frame-pointer'
'-mharden-sls=none'
)
########
# Misc #
########
tgsend() {
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" -d chat_id="@neutron_updates" -d "disable_web_page_preview=true" -d "parse_mode=html" -d text="$1"
}
clear_if_unused() {
if [[ $1 -eq 0 ]]; then
unset "$2"
fi
}