Bug 1464170 - Support PGO in clang builds on Linux. r=dmajor
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 08 Aug 2018 11:08:48 +0900
changeset 430822 3c4564c2f2d5b0b5fe4a0c1f80896484a0b0f5d7
parent 430821 45b401d8443fe6b6ca4d08ec5a32cd56038a12f0
child 430823 479342879a30961cd7d0cec6b31fb0b5d4e4d8eb
push id106284
push usermh@glandium.org
push dateThu, 09 Aug 2018 20:55:05 +0000
treeherdermozilla-inbound@3c4564c2f2d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdmajor
bugs1464170
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 1464170 - Support PGO in clang builds on Linux. r=dmajor This uses the same code path as for clang-cl builds.
Makefile.in
build/moz.configure/toolchain.configure
--- a/Makefile.in
+++ b/Makefile.in
@@ -299,36 +299,34 @@ update-packaging:
 	$(MAKE) -C tools/update-packaging
 
 .PHONY: package-generated-sources
 package-generated-sources:
 	$(call py_action,package_generated_sources,'$(DIST)/$(PKG_PATH)$(GENERATED_SOURCE_FILE_PACKAGE)')
 
 #XXX: this is a hack, since we don't want to clobber for MSVC
 # PGO support, but we can't do this test in client.mk
-ifneq ($(OS_ARCH)_$(GNU_CC), WINNT_)
 # No point in clobbering if PGO has been explicitly disabled.
-ifndef NO_PROFILE_GUIDED_OPTIMIZE
+ifdef NO_PROFILE_GUIDED_OPTIMIZE
+maybe_clobber_profiledbuild:
+else
+ifneq ($(CC_TYPE),msvc)
 maybe_clobber_profiledbuild: clean
-else
-maybe_clobber_profiledbuild:
+ifneq (,$(findstring clang,$(CC_TYPE)))
+# 32-bit Windows PGO is currently blocked by bug 1479800
+ifneq ($(CC_TYPE)_$(CPU_ARCH),clang-cl_x86)
+	$(LLVM_PROFDATA) merge -o $(DEPTH)/merged.profdata $(DEPTH)/*.profraw
 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
+endif # msvc
+endif # NO_PROFILE_GUIDED_OPTIMIZE
 
 .PHONY: maybe_clobber_profiledbuild
 
 # Look for R_386_PC32 relocations in shared libs, these
 # break x86_64 builds and SELinux users.
 ifeq ($(OS_TARGET)_$(TARGET_XPCOM_ABI),Linux_x86-gcc3)
 check::
 	@relcount=`find $(DIST)/bin -name '*.so' | xargs objdump -R | grep R_386_PC32 | wc -l` && if test $$relcount -gt 0; then echo 'FAILED: R_386_PC32 relocations detected in a shared library.  Did you use a system header without adding it to config/system-headers?'; exit 1; else echo 'PASSED'; fi
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1245,37 +1245,45 @@ set_config('VISIBILITY_FLAGS', visibilit
 @depends(c_compiler, check_build_environment, target)
 @imports('multiprocessing')
 @imports(_from='__builtin__', _import='min')
 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'):
+    if compiler.type == 'gcc':
         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':
+    if compiler.type in ('clang-cl', 'clang'):
         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-out-of-date',
-                          '-Wno-error=profile-instr-unprofiled'],
-              use_ldflags=[],
-          )
+        if compiler.type == 'clang-cl':
+            # 32-bit PGO is currently blocked by bug 1479800
+            if target.cpu == 'x86_64':
+                gen_ldflags = ['clang_rt.profile-x86_64.lib']
+            else:
+                gen_ldflags = None
+        else:
+            gen_ldflags = ['-fprofile-instr-generate']
+
+        if gen_ldflags:
+            return namespace(
+                gen_cflags=['-fprofile-instr-generate'],
+                gen_ldflags=gen_ldflags,
+                use_cflags=['-fprofile-instr-use=%s' % profdata,
+                            '-Wno-error=profile-instr-out-of-date',
+                            '-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],