Bug 1341525: Enable PGO in 64-bit clang-cl builds. r=froydnj
☠☠ backed out by b2b6bfdafb1d ☠ ☠
authorDavid Major <dmajor@mozilla.com>
Wed, 01 Aug 2018 17:59:23 -0400
changeset 484835 2011dae40293da2aceba942e8c7d95d0a4dfffbf
parent 484834 90eb11dc5e8f052799ed9da9cea51060e5af203b
child 484836 1a5c1ee48c9102ef8939bca79fa02686cea56b8e
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1341525
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1341525: Enable PGO in 64-bit clang-cl builds. r=froydnj
Makefile.in
build/moz.configure/toolchain.configure
build/mozconfig.clang-cl
--- a/Makefile.in
+++ b/Makefile.in
@@ -309,16 +309,20 @@ ifneq ($(OS_ARCH)_$(GNU_CC), WINNT_)
 ifndef NO_PROFILE_GUIDED_OPTIMIZE
 maybe_clobber_profiledbuild: clean
 else
 maybe_clobber_profiledbuild:
 endif
 else
 ifdef CLANG_CL
 maybe_clobber_profiledbuild: clean
+# 32-bit PGO is currently blocked by bug 1479800
+ifeq ($(CPU_ARCH),x86_64)
+	$(LLVM_PROFDATA) merge -o $(DEPTH)/merged.profdata $(DEPTH)/*.profraw
+endif
 else
 maybe_clobber_profiledbuild:
 	$(RM) $(DIST)/bin/*.pgc
 	find $(DIST)/$(MOZ_APP_NAME) -name '*.pgc' -exec mv {} $(DIST)/bin \;
 endif # CLANG_CL
 endif
 
 .PHONY: maybe_clobber_profiledbuild
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1235,29 +1235,45 @@ def wrap_system_includes(target, visibil
 set_define('HAVE_VISIBILITY_HIDDEN_ATTRIBUTE',
            depends(visibility_flags)(lambda v: bool(v) or None))
 set_define('HAVE_VISIBILITY_ATTRIBUTE',
            depends(visibility_flags)(lambda v: bool(v) or None))
 set_config('WRAP_SYSTEM_INCLUDES', wrap_system_includes)
 set_config('VISIBILITY_FLAGS', visibility_flags)
 
 
-@depends(c_compiler)
+@depends(c_compiler, check_build_environment, target)
 @imports('multiprocessing')
 @imports(_from='__builtin__', _import='min')
-def pgo_flags(compiler):
+def pgo_flags(compiler, build_env, target):
+    topobjdir = build_env.topobjdir
+    if topobjdir.endswith('/js/src'):
+        topobjdir = topobjdir[:-7]
+
     if compiler.type in ('gcc', 'clang'):
         return namespace(
             gen_cflags=['-fprofile-generate'],
             gen_ldflags=['-fprofile-generate'],
             use_cflags=['-fprofile-use', '-fprofile-correction',
                         '-Wcoverage-mismatch'],
             use_ldflags=['-fprofile-use'],
         )
 
+    if compiler.type == 'clang-cl':
+        profdata = os.path.join(topobjdir, 'merged.profdata')
+        # 32-bit PGO is currently blocked by bug 1479800
+        if target.cpu == 'x86_64':
+          return namespace(
+              gen_cflags=['-fprofile-instr-generate'],
+              gen_ldflags=['clang_rt.profile-x86_64.lib'],
+              use_cflags=['-fprofile-instr-use=%s' % profdata,
+                          '-Wno-error=profile-instr-unprofiled'],
+              use_ldflags=[],
+          )
+
     if compiler.type == 'msvc':
         num_cores = min(8, multiprocessing.cpu_count())
         cgthreads = '-CGTHREADS:%s' % num_cores
 
         return namespace(
             gen_cflags=['-GL'],
             gen_ldflags=['-LTCG:PGINSTRUMENT', '-PogoSafeMode', cgthreads],
             # XXX: PGO builds can fail with warnings treated as errors,
@@ -1277,16 +1293,21 @@ def pgo_flags(compiler):
         )
 
 
 set_config('PROFILE_GEN_CFLAGS', pgo_flags.gen_cflags)
 set_config('PROFILE_GEN_LDFLAGS', pgo_flags.gen_ldflags)
 set_config('PROFILE_USE_CFLAGS', pgo_flags.use_cflags)
 set_config('PROFILE_USE_LDFLAGS', pgo_flags.use_ldflags)
 
+llvm_profdata = check_prog('LLVM_PROFDATA', ['llvm-profdata'],
+                           allow_missing=True)
+
+add_old_configure_assignment('LLVM_PROFDATA', llvm_profdata)
+
 
 @depends(c_compiler)
 def preprocess_option(compiler):
     # The uses of PREPROCESS_OPTION depend on the spacing for -o/-Fi.
     if compiler.type in ('gcc', 'clang'):
         return '-E -o '
     else:
         return '-P -Fi'
--- a/build/mozconfig.clang-cl
+++ b/build/mozconfig.clang-cl
@@ -1,9 +1,12 @@
 if test -d "$topsrcdir/clang/bin"; then
     CLANG_DIR=`cd "$topsrcdir/clang/bin" ; pwd`
     export PATH="${CLANG_DIR}:${PATH}"
+    mk_export_correct_style PATH
 
-    mk_export_correct_style PATH
+    CLANG_LIB_DIR="$(cd $topsrcdir/clang/lib/clang/* && cd lib/windows && pwd)"
+    export LIB=$LIB:$CLANG_LIB_DIR
+    mk_export_correct_style LIB
 fi
 
 export CC=clang-cl
 export CXX=clang-cl