-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathllvm-avx2.patch
More file actions
488 lines (460 loc) · 23.3 KB
/
llvm-avx2.patch
File metadata and controls
488 lines (460 loc) · 23.3 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
diff --git a/tools/clang/scripts/build.py b/tools/clang/scripts/build.py
index bb0f6e16b4649..89d3fb5299e9f 100755
--- a/tools/clang/scripts/build.py
+++ b/tools/clang/scripts/build.py
@@ -72,6 +72,8 @@ BUG_REPORT_URL = ('https://crbug.com in the Tools>LLVM component,'
LIBXML2_VERSION = 'libxml2-v2.9.12'
ZSTD_VERSION = 'zstd-1.5.5'
+MIMALLOC_URL = 'https://github.com/microsoft/mimalloc/archive/refs/tags/v3.1.4.tar.gz'
+
win_sdk_dir = None
def GetWinSDKDir():
"""Get the location of the current SDK."""
@@ -164,7 +166,7 @@ def CheckoutGitRepo(name, git_url, commit, dir):
['git', 'diff-index', '--exit-code', 'HEAD'], fail_hard=False)
and RunCommand(['git', 'fetch'], fail_hard=False)
and RunCommand(['git', 'checkout', commit], fail_hard=False)
- and RunCommand(['git', 'clean', '-f'], fail_hard=False)):
+ and RunCommand(['git', 'clean', '-ffd'], fail_hard=False)):
return
# If we can't use the current repo, delete it.
@@ -349,6 +351,13 @@ def BuildLibXml2():
'-DCMAKE_INSTALL_LIBDIR=lib',
'-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded', # /MT to match LLVM.
'-DBUILD_SHARED_LIBS=OFF',
+ '-DCMAKE_C_COMPILER=' + os.path.join(PINNED_CLANG_DIR, 'bin', 'clang'),
+ '-DCMAKE_CXX_COMPILER=' + os.path.join(PINNED_CLANG_DIR, 'bin', 'clang++'),
+ '-DCMAKE_C_FLAGS_RELEASE=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -w ',
+ '-DCMAKE_CXX_FLAGS_RELEASE=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -w ',
+ '-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -w ',
+ '-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -w ',
+ '-DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -w ',
'-DLIBXML2_WITH_C14N=OFF',
'-DLIBXML2_WITH_CATALOG=OFF',
'-DLIBXML2_WITH_DEBUG=OFF',
@@ -408,6 +417,52 @@ def BuildLibXml2():
return extra_cmake_flags, extra_cflags
+class LibMimallocDirs:
+ """
+ The set of directories where mimalloc is located.
+
+ Includes the diractories where the source is unpacked, where it is built,
+ and installed.
+ """
+ def __init__(self):
+ self.unzip_dir = LLVM_BUILD_TOOLS_DIR
+ self.src_dir = os.path.join(self.unzip_dir, 'mimalloc-3.1.4')
+ self.build_dir = os.path.join(self.src_dir, 'build')
+
+def BuildLibMimalloc():
+ """Download and build mimalloc"""
+
+ dirs = LibMimallocDirs()
+ if os.path.exists(dirs.src_dir):
+ RmTree(dirs.src_dir)
+ DownloadAndUnpack(MIMALLOC_URL, dirs.unzip_dir)
+ os.mkdir(dirs.build_dir)
+ os.chdir(dirs.build_dir)
+
+ RunCommand(
+ [
+ 'cmake',
+ '-GNinja',
+ '-DCMAKE_BUILD_TYPE=Release',
+ '-DCMAKE_C_COMPILER=' + os.path.join(PINNED_CLANG_DIR, 'bin', 'clang'),
+ '-DCMAKE_CXX_COMPILER=' + os.path.join(PINNED_CLANG_DIR, 'bin', 'clang++'),
+ '-DCMAKE_C_FLAGS_RELEASE=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -w ',
+ '-DCMAKE_CXX_FLAGS_RELEASE=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -w ',
+ '-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -w ',
+ '-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -w ',
+ '-DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -w ',
+ '-DMI_OVERRIDE=ON',
+ '-DMI_SHOW_ERRORS=OFF',
+ '..',
+ ],
+ setenv=True)
+ RunCommand(['ninja'], setenv=True)
+
+ MIMALLOC_LIB = os.path.abspath(os.path.join(LLVM_DIR, '..', 'llvm-build-tools/mimalloc-3.1.4')) + '/build/mimalloc.o'
+
+ mimalloc_ldflags = [ '' + MIMALLOC_LIB ]
+
+ return mimalloc_ldflags
class ZStdDirs:
"""
@@ -457,6 +512,13 @@ def BuildZStd():
'-DCMAKE_INSTALL_LIBDIR=lib',
'-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded', # /MT to match LLVM.
'-DZSTD_BUILD_SHARED=OFF',
+ '-DCMAKE_C_COMPILER=' + os.path.join(PINNED_CLANG_DIR, 'bin', 'clang'),
+ '-DCMAKE_CXX_COMPILER=' + os.path.join(PINNED_CLANG_DIR, 'bin', 'clang++'),
+ '-DCMAKE_C_FLAGS_RELEASE=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -w ',
+ '-DCMAKE_CXX_FLAGS_RELEASE=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -w ',
+ '-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -w ',
+ '-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -w ',
+ '-DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -w ',
'../build/cmake',
],
setenv=True)
@@ -703,21 +765,9 @@ def main():
action='store_true',
help='use the cmake from PATH instead of downloading '
'and using prebuilt cmake binaries')
- parser.add_argument('--tf-path',
- help='path to python tensorflow pip package. '
- 'Used for embedding an MLGO model')
- parser.add_argument(
- '--with-ml-inliner-model',
- help='path to MLGO inliner model to embed. Setting to '
- '\'default\', will download an official model which was '
- 'trained for Chrome on Android',
- default='default' if sys.platform.startswith('linux') else '')
parser.add_argument('--with-android', type=gn_arg, nargs='?', const=True,
help='build the Android ASan runtime (linux only)',
default=sys.platform.startswith('linux'))
- parser.add_argument('--pic',
- action='store_true',
- help='Uses PIC when building LLVM')
parser.add_argument('--with-fuchsia',
type=gn_arg,
nargs='?',
@@ -734,10 +784,6 @@ def main():
parser.add_argument('--with-ccache',
action='store_true',
help='Use ccache to build the stage 1 compiler')
- parser.add_argument('--without-zstd',
- dest='with_zstd',
- action='store_false',
- help='Disable zstd in the build')
args = parser.parse_args()
@@ -748,8 +794,14 @@ def main():
global RELEASE_VERSION
RELEASE_VERSION = '22'
- if (args.pgo or args.thinlto) and not args.bootstrap:
- print('--pgo/--thinlto requires --bootstrap')
+ if not sys.platform.startswith('linux'):
+ print('Customized build script only works with Linux')
+ return 1
+ if not args.bootstrap:
+ print('Customized build script requires --bootstrap')
+ return 1
+ if args.skip_checkout:
+ print('Customized build script does not support --skip-checkout')
return 1
if args.with_android and not os.path.exists(ANDROID_NDK_DIR):
print('Android NDK not found at ' + ANDROID_NDK_DIR)
@@ -774,10 +826,6 @@ def main():
print('for general Fuchsia build instructions.')
return 1
- if args.with_ml_inliner_model and not sys.platform.startswith('linux'):
- print('--with-ml-inliner-model only supports linux hosts')
- return 1
-
# Don't buffer stdout, so that print statements are immediately flushed.
# LLVM tests print output without newlines, so with buffering they won't be
# immediately printed.
@@ -838,12 +886,12 @@ def main():
# LLVM_ENABLE_LLD).
cc, cxx, lld = None, None, None
- cflags = []
- cxxflags = []
- ldflags = []
+ cflags = ['-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -pthread -w']
+ cxxflags = ['-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -pthread -w']
+ ldflags = ['-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -pthread -w']
targets = 'AArch64;ARM;LoongArch;Mips;PowerPC;RISCV;SystemZ;WebAssembly;X86'
- projects = 'clang;lld'
+ projects = 'clang;lld;polly'
if not args.no_tools:
projects += ';clang-tools-extra'
if args.bolt:
@@ -856,7 +904,6 @@ def main():
runtimes = 'compiler-rt'
pic_default = sys.platform == 'win32'
- pic_mode = 'ON' if args.pic or pic_default else 'OFF'
base_cmake_args = [
'-GNinja',
@@ -865,8 +912,8 @@ def main():
f'-DLLVM_ENABLE_PROJECTS={projects}',
f'-DLLVM_ENABLE_RUNTIMES={runtimes}',
f'-DLLVM_TARGETS_TO_BUILD={targets}',
- f'-DLLVM_ENABLE_PIC={pic_mode}',
- '-DLLVM_ENABLE_TERMINFO=OFF',
+ f'-DLLVM_ENABLE_PIC=ON',
+ # '-DLLVM_ENABLE_TERMINFO=OFF',
'-DLLVM_ENABLE_Z3_SOLVER=OFF',
'-DCLANG_PLUGIN_SUPPORT=OFF',
'-DCLANG_ENABLE_STATIC_ANALYZER=OFF',
@@ -890,7 +937,8 @@ def main():
# `bootstrap` tool:
# https://github.com/rust-lang/rust/blob/021861aea8de20c76c7411eb8ada7e8235e3d9b5/src/bootstrap/src/core/build_steps/llvm.rs#L348
'-DLLVM_INSTALL_UTILS=ON',
- '-DLLVM_ENABLE_ZSTD=%s' % ('ON' if args.with_zstd else 'OFF'),
+ '-DLLVM_ENABLE_ZSTD=ON',
+ '-DLLVM_ENABLE_BINDINGS=OFF'
]
if sys.platform == 'darwin':
@@ -953,6 +1001,10 @@ def main():
base_cmake_args.append('-DLLVM_WINSYSROOT="%s"' %
os.path.dirname(os.path.dirname(GetWinSDKDir())))
+ #Build mimalloc
+ libmimalloc_ldflags = BuildLibMimalloc()
+ ldflags += libmimalloc_ldflags
+
# Statically link libxml2 to make lld-link not require mt.exe on Windows,
# and to make sure lld-link output on other platforms is identical to
# lld-link on Windows (for cross-builds).
@@ -962,13 +1014,12 @@ def main():
cflags += libxml_cflags
cxxflags += libxml_cflags
- if args.with_zstd:
- # Statically link zstd to make lld support zstd compression for debug info.
- with timer.time('zstd build'):
- zstd_cmake_args, zstd_cflags = BuildZStd()
- base_cmake_args += zstd_cmake_args
- cflags += zstd_cflags
- cxxflags += zstd_cflags
+ # Statically link zstd to make lld support zstd compression for debug info.
+ with timer.time('zstd build'):
+ zstd_cmake_args, zstd_cflags = BuildZStd()
+ base_cmake_args += zstd_cmake_args
+ cflags += zstd_cflags
+ cxxflags += zstd_cflags
lit_excludes = []
if sys.platform.startswith('linux'):
@@ -1027,7 +1078,7 @@ def main():
bootstrap_targets += ';ARM;AArch64'
bootstrap_args = base_cmake_args + ccache_cmake_args + [
'-DLLVM_TARGETS_TO_BUILD=' + bootstrap_targets,
- '-DLLVM_ENABLE_PROJECTS=clang;lld',
+ '-DLLVM_ENABLE_PROJECTS=clang;lld;polly',
'-DLLVM_ENABLE_RUNTIMES=' + ';'.join(runtimes),
'-DCMAKE_INSTALL_PREFIX=' + LLVM_BOOTSTRAP_INSTALL_DIR,
'-DCMAKE_C_FLAGS=' + ' '.join(cflags),
@@ -1085,6 +1136,9 @@ def main():
print('Bootstrap compiler installed.')
+ cflags += ['-mllvm -polly']
+ cxxflags += ['-mllvm -polly']
+
if args.pgo:
print('Building instrumented compiler')
if os.path.exists(LLVM_INSTRUMENTED_DIR):
@@ -1098,9 +1152,9 @@ def main():
cxxflags += ['-Wno-backend-plugin']
instrument_args = base_cmake_args + [
- '-DLLVM_ENABLE_PROJECTS=clang',
- '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
- '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
+ '-DLLVM_ENABLE_PROJECTS=clang;polly',
+ '-DCMAKE_C_FLAGS= -mllvm -vp-counters-per-site=3 ' + ' '.join(cflags),
+ '-DCMAKE_CXX_FLAGS= -mllvm -vp-counters-per-site=3 ' + ' '.join(cxxflags),
'-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
'-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
'-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
@@ -1146,8 +1200,11 @@ def main():
with open(training_source, 'wb') as f:
DownloadUrl(CDS_URL + '/' + training_source, f)
train_cmd = [os.path.join(LLVM_INSTRUMENTED_DIR, 'bin', 'clang++'),
- '-target', 'x86_64-unknown-unknown', '-O2', '-g', '-std=c++14',
- '-fno-exceptions', '-fno-rtti', '-w', '-c', training_source]
+ '-target', 'x86_64-unknown-unknown', '-O3', '-g', '-std=c++20',
+ '-march=x86-64-v3', '-ffp-contract=fast', '-fmerge-all-constants',
+ '-fdata-sections', '-ffunction-sections', '-fno-exceptions',
+ '-fno-rtti', '-mllvm', '-polly', '-mllvm', '-polly-process-unprofitable',
+ '-Rpass-analysis=polly', '-w', '-c', training_source]
if sys.platform == 'darwin':
train_cmd.extend(['-isysroot', isysroot])
RunCommand(train_cmd, setenv=True)
@@ -1198,13 +1255,18 @@ def main():
if cxx is not None: base_cmake_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
if lld is not None: base_cmake_args.append('-DCMAKE_LINKER=' + lld)
final_install_dir = args.install_dir if args.install_dir else LLVM_BUILD_DIR
+ tf_path = subprocess.check_output(
+ ['vpython3', os.path.join(THIS_DIR, 'get_tensorflow.py')],
+ universal_newlines=True).rstrip()
+ base_cmake_args += [
+ '-DTENSORFLOW_AOT_PATH=%s' % tf_path,
+ ]
cmake_args = base_cmake_args + [
- '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
- '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
- '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
- '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
- '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
'-DCMAKE_INSTALL_PREFIX=' + final_install_dir,
+ '-DLLVM_INLINER_MODEL_CURRENT_URL=https://commondatastorage.googleapis.com/chromium-browser-clang/tools/mlgo_model3.tgz',
+ '-DLLVM_INLINER_MODEL_PATH=download',
+ '-DLLVM_RAEVICT_MODEL_CURRENT_URL=https://github.com/google/ml-compiler-opt/releases/download/regalloc-evict-v1.1/model.zip',
+ '-DLLVM_RAEVICT_MODEL_PATH=download',
]
if not args.no_tools:
cmake_args.extend([
@@ -1213,10 +1275,36 @@ def main():
os.path.join(CHROMIUM_DIR, 'tools', 'clang'),
'-DCHROMIUM_TOOLS=%s' % ';'.join(chrome_tools)
])
- if args.pgo:
+ if args.pgo and not args.thinlto:
+ cmake_args.append('-DLLVM_PROFDATA_FILE=' + LLVM_PROFDATA_FILE)
+ cmake_args.append('-DCMAKE_C_FLAGS=-mllvm -enable-ext-tsp-block-placement ' + ' '.join(cflags))
+ cmake_args.append('-DCMAKE_CXX_FLAGS=-mllvm -enable-ext-tsp-block-placement ' + ' '.join(cxxflags))
+ cmake_args.append('-DCMAKE_EXE_LINKER_FLAGS=-Wl,-z,keep-text-section-prefix ' + ' '.join(ldflags))
+ cmake_args.append('-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-z,keep-text-section-prefix ' + ' '.join(ldflags))
+ cmake_args.append('-DCMAKE_MODULE_LINKER_FLAGS=-Wl,-z,keep-text-section-prefix ' + ' '.join(ldflags))
+ if args.thinlto and not args.pgo:
+ cmake_args.append('-DLLVM_ENABLE_LTO=Thin')
+ cmake_args.append('-DLLVM_PARALLEL_LINK_JOBS=16')
+ cmake_args.append('-DCMAKE_C_FLAGS=-flto=thin -fwhole-program-vtables -fsplit-lto-unit ' + ' '.join(cflags))
+ cmake_args.append('-DCMAKE_CXX_FLAGS=-flto=thin -fwhole-program-vtables -fsplit-lto-unit ' + ' '.join(cxxflags))
+ cmake_args.append('-DCMAKE_EXE_LINKER_FLAGS=-flto=thin -fwhole-program-vtables -Wl,--lto-O3 -Wl,-mllvm,-import-instr-limit=5 -Wl,-mllvm,-polly ' + ' '.join(ldflags))
+ cmake_args.append('-DCMAKE_SHARED_LINKER_FLAGS=-flto=thin -fwhole-program-vtables -Wl,--lto-O3 -Wl,-mllvm,-import-instr-limit=5 -Wl,-mllvm,-polly ' + ' '.join(ldflags))
+ cmake_args.append('-DCMAKE_MODULE_LINKER_FLAGS=-flto=thin -fwhole-program-vtables -Wl,--lto-O3 -Wl,-mllvm,-import-instr-limit=5 -Wl,-mllvm,-polly ' + ' '.join(ldflags))
+ if args.thinlto and args.pgo:
cmake_args.append('-DLLVM_PROFDATA_FILE=' + LLVM_PROFDATA_FILE)
- if args.thinlto:
cmake_args.append('-DLLVM_ENABLE_LTO=Thin')
+ cmake_args.append('-DLLVM_PARALLEL_LINK_JOBS=16')
+ cmake_args.append('-DCMAKE_C_FLAGS=-flto=thin -fwhole-program-vtables -fsplit-lto-unit ' + ' '.join(cflags))
+ cmake_args.append('-DCMAKE_CXX_FLAGS=-flto=thin -fwhole-program-vtables -fsplit-lto-unit ' + ' '.join(cxxflags))
+ cmake_args.append('-DCMAKE_EXE_LINKER_FLAGS=-flto=thin -fwhole-program-vtables -Wl,--lto-O3 -Wl,-mllvm,-import-instr-limit=5 -Wl,-mllvm,-enable-ext-tsp-block-placement -Wl,-z,keep-text-section-prefix -Wl,-mllvm,-polly ' + ' '.join(ldflags))
+ cmake_args.append('-DCMAKE_SHARED_LINKER_FLAGS=-flto=thin -fwhole-program-vtables -Wl,--lto-O3 -Wl,-mllvm,-import-instr-limit=5 -Wl,-mllvm,-enable-ext-tsp-block-placement -Wl,-z,keep-text-section-prefix -Wl,-mllvm,-polly ' + ' '.join(ldflags))
+ cmake_args.append('-DCMAKE_MODULE_LINKER_FLAGS=-flto=thin -fwhole-program-vtables -Wl,--lto-O3 -Wl,-mllvm,-import-instr-limit=5 -Wl,-mllvm,-enable-ext-tsp-block-placement -Wl,-z,keep-text-section-prefix -Wl,-mllvm,-polly ' + ' '.join(ldflags))
+ else:
+ cmake_args.append('-DCMAKE_C_FLAGS= ' + ' '.join(cflags))
+ cmake_args.append('-DCMAKE_CXX_FLAGS= ' + ' '.join(cxxflags))
+ cmake_args.append('-DCMAKE_EXE_LINKER_FLAGS= ' + ' '.join(ldflags))
+ cmake_args.append('-DCMAKE_SHARED_LINKER_FLAGS= ' + ' '.join(ldflags))
+ cmake_args.append('-DCMAKE_MODULE_LINKER_FLAGS= ' + ' '.join(ldflags))
if sys.platform == 'win32':
cmake_args.append('-DLLVM_ENABLE_ZLIB=FORCE_ON')
@@ -1258,6 +1346,11 @@ def main():
# TODO(crbug.com/40242553): pass proper flags to i386 tests so they
# compile correctly
'LLVM_INCLUDE_TESTS=OFF',
+ 'CMAKE_C_FLAGS=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -mllvm -polly -w ',
+ 'CMAKE_CXX_FLAGS=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -mllvm -polly -w ',
+ 'CMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -mllvm -polly -w ',
+ 'CMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -mllvm -polly -w ',
+ 'CMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -mllvm -polly -w '
],
"profile":
True,
@@ -1267,6 +1360,12 @@ def main():
runtimes_triples_args['x86_64-unknown-linux-gnu'] = {
"args": [
'CMAKE_SYSROOT=%s' % sysroot_amd64,
+ 'CMAKE_C_FLAGS=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -mllvm -polly -w ',
+ 'CMAKE_CXX_FLAGS=-O3 -march=x86-64-v3 -fdata-sections -ffunction-sections -mllvm -polly -w ',
+ 'CMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -mllvm -polly -w ',
+ 'CMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -mllvm -polly -w ',
+ 'CMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld -Wl,-O2 -Wl,--gc-sections -Wl,--icf=all -mllvm -polly -w ',
+
],
"profile": True,
"sanitizers": True,
@@ -1450,32 +1549,6 @@ def main():
"profile": build_profile
}
- # Embed MLGO inliner model. If tf_path is not specified, a vpython3 env
- # will be created which contains the necessary source files for compilation.
- # MLGO is only officially supported on linux. This condition is checked at
- # the top of main()
- if args.with_ml_inliner_model:
- if args.with_ml_inliner_model == 'default':
- model_path = ('https://commondatastorage.googleapis.com/'
- 'chromium-browser-clang/tools/mlgo_model3.tgz')
- else:
- model_path = args.with_ml_inliner_model
- if not args.tf_path:
- with timer.time('get tensorflow'):
- tf_path = subprocess.check_output(
- ['vpython3', os.path.join(THIS_DIR, 'get_tensorflow.py')],
- universal_newlines=True).rstrip()
- else:
- tf_path = args.tf_path
- print('Embedding MLGO inliner model at %s using Tensorflow at %s' %
- (model_path, tf_path))
- cmake_args += [
- '-DLLVM_INLINER_MODEL_PATH=%s' % model_path,
- '-DTENSORFLOW_AOT_PATH=%s' % tf_path,
- # Disable Regalloc model generation since it is unused
- '-DLLVM_RAEVICT_MODEL_PATH=none'
- ]
-
# Convert FOO=BAR CMake flags per triple into
# -DBUILTINS_$triple_FOO=BAR/-DRUNTIMES_$triple_FOO=BAR and build up
# -DLLVM_BUILTIN_TARGETS/-DLLVM_RUNTIME_TARGETS.
@@ -1534,7 +1607,7 @@ def main():
with timer.time('bolt instrument'):
RunCommand([
'bin/llvm-bolt', 'bin/clang', '-o', 'bin/clang-bolt.inst',
- '-instrument', '--instrumentation-file-append-pid',
+ '-lite=false', '-instrument', '--instrumentation-file-append-pid',
'--instrumentation-file=' +
os.path.join(bolt_profiles_dir, 'prof.fdata')
])
@@ -1547,14 +1620,18 @@ def main():
# Train by building a part of Clang.
os.mkdir('bolt-training')
os.chdir('bolt-training')
+ if args.pgo:
+ cflags += ['-mllvm -enable-ext-tsp-block-placement']
+ cxxflags += ['-mllvm -enable-ext-tsp-block-placement']
+ ldflags += ['-Wl,-z,keep-text-section-prefix']
bolt_train_cmake_args = base_cmake_args + [
'-DLLVM_TARGETS_TO_BUILD=X86',
'-DLLVM_ENABLE_PROJECTS=clang',
- '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
- '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
- '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
- '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
- '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
+ '-DCMAKE_C_FLAGS=-g -fmerge-all-constants -Rpass-analysis=polly ' + ' '.join(cflags),
+ '-DCMAKE_CXX_FLAGS=-g -fmerge-all-constants -Rpass-analysis=polly ' + ' '.join(cxxflags),
+ '-DCMAKE_EXE_LINKER_FLAGS= ' + ' '.join(ldflags),
+ '-DCMAKE_SHARED_LINKER_FLAGS= ' + ' '.join(ldflags),
+ '-DCMAKE_MODULE_LINKER_FLAGS= ' + ' '.join(ldflags),
'-DCMAKE_C_COMPILER=' +
os.path.join(LLVM_BUILD_DIR, 'bin/clang-bolt.inst'),
'-DCMAKE_CXX_COMPILER=' +
@@ -1563,6 +1640,8 @@ def main():
os.path.join(LLVM_BUILD_DIR, 'bin/clang-bolt.inst'),
'-DCMAKE_ASM_COMPILER_ID=Clang',
]
+ if args.pgo:
+ bolt_train_cmake_args.append('-DLLVM_PROFDATA_FILE=' + LLVM_PROFDATA_FILE)
with timer.time('bolt training cmake'):
RunCommand(['cmake'] + bolt_train_cmake_args +
[os.path.join(LLVM_DIR, 'llvm')])
@@ -1582,9 +1661,15 @@ def main():
])
RunCommand([
'bin/llvm-bolt', 'bin/clang', '-o', 'bin/clang-bolt.opt', '-data',
- 'merged.fdata', '-reorder-blocks=ext-tsp', '-reorder-functions=hfsort+',
- '-split-functions', '-split-all-cold', '-split-eh', '-dyno-stats',
- '-icf=1', '-use-gnu-stack', '-use-old-text'
+ 'merged.fdata', '-reorder-blocks=ext-tsp', '-reorder-functions=cdsort',
+ '-split-functions', '-split-strategy=cdsplit',
+ '-split-all-cold', '-split-eh', '-dyno-stats',
+ '-icf=all', '-use-gnu-stack', '-peepholes=all', '-elim-link-veneers',
+ '-group-stubs', '-align-blocks', '-sctc-mode=heuristic',
+ '-jump-tables=aggressive', '-simplify-rodata-loads',
+ '-tail-duplication=cache', '-indirect-call-promotion=all', '-icp-eliminate-loads',
+ '-hot-data', '-x86-strip-redundant-address-size', '-reorder-functions-use-hot-size',
+ '-reorder-data-algo=funcs', '-lite=false',
])
# Overwrite clang, preserving its timestamp so ninja doesn't rebuild it.
@@ -1593,8 +1678,7 @@ def main():
VerifyVersionOfBuiltClangMatchesVERSION()
VerifyZlibSupport()
- if args.with_zstd:
- VerifyZStdSupport()
+ VerifyZStdSupport()
# Run tests.
if (chrome_tools and (args.run_tests or args.llvm_force_head_revision)):
@@ -1612,6 +1696,8 @@ def main():
WriteStampFile(PACKAGE_VERSION, STAMP_FILE)
WriteStampFile(PACKAGE_VERSION, FORCE_HEAD_REVISION_FILE)
+ RunCommand(['ln', '--symbolic', '--relative', '-f', 'bin/clang', 'bin/clang++'])
+ RunCommand(['ln', '--symbolic', '--relative', '-f', 'bin/clang', 'bin/clang-cl'])
print('Clang build was successful.')