Bug 1341525: Enable PGO in 64-bit clang-cl builds. r=froydnj
authorDavid Major <dmajor@mozilla.com>
Wed, 01 Aug 2018 17:59:23 -0400
changeset 487602 084b1e903489a2c5643f99da82b2c788f786bd61
parent 487601 f6c28d1e8a4bee80201f26c5a6bf4d007618bd1a
child 487603 15bfb5802548bef7c5424add0840ea3281617e3f
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [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,14 @@
 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
+    if $(cd $topsrcdir/clang/lib/clang/* && test -d lib/windows); then
+        CLANG_LIB_DIR="$(cd $topsrcdir/clang/lib/clang/* && cd lib/windows && pwd)"
+        export LIB=$LIB:$CLANG_LIB_DIR
+        mk_export_correct_style LIB
+    fi
 fi
 
 export CC=clang-cl
 export CXX=clang-cl