From c61f86f56b86e442369725ad79299ccc5519b000 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 13 Jun 2017 20:44:27 +0200 Subject: Map LIPO to ThinLTO when LLVM compiler is used. This change maps LIPO to ThinLTO when a LLVM compiler is used for building, with a warning. This change is necessary for the following reason. The compiler team is planning to flip the default compiler from GCC to LLVM and this change will migrate all LIPO users of GCC to LLVM with ThinLTO + FDO (LIPO equivalent) without any changes to build scripts. RELNOTES[NEW]: LIPO maps to ThinLTO for LLVM builds. PiperOrigin-RevId: 158875330 --- .../build/lib/rules/cpp/CppConfiguration.java | 33 ++++++++++++++++------ .../devtools/build/lib/rules/cpp/FdoSupport.java | 6 +++- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules') diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index 617fce8bf2..0add9e977a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -1596,16 +1596,19 @@ public class CppConfiguration extends BuildConfiguration.Fragment { return cppOptions.isFdo(); } + public boolean isLLVMCompiler() { + // TODO(tmsriram): Checking for "llvm" does not handle all the cases. This + // is temporary until the crosstool configuration is modified to add fields that + // indicate which flavor of fdo is being used. + return toolchainIdentifier.contains("llvm"); + } + /** Returns true if LLVM FDO Optimization should be applied for this configuration. */ public boolean isLLVMOptimizedFdo() { - return cppOptions.isFdo() - && cppOptions.getFdoOptimize() != null + return cppOptions.getFdoOptimize() != null && (CppFileTypes.LLVM_PROFILE.matches(cppOptions.getFdoOptimize()) || CppFileTypes.LLVM_PROFILE_RAW.matches(cppOptions.getFdoOptimize()) - // TODO(tmsriram): Checking for "llvm" does not handle all the cases. This - // is temporary until the crosstool configuration is modified to add fields that - // indicate which flavor of fdo is being used. - || (getToolchainIdentifier().contains("llvm") + || (isLLVMCompiler() && cppOptions.getFdoOptimize().endsWith(".zip"))); } @@ -1984,12 +1987,19 @@ public class CppConfiguration extends BuildConfiguration.Fragment { } if (cppOptions.lipoContextForBuild != null) { - if (cppOptions.getLipoMode() != LipoMode.BINARY || cppOptions.getFdoOptimize() == null) { + if (isLLVMCompiler()) { + reporter.handle( + Event.warn("LIPO options are not applicable with a LLVM compiler and will be " + + "converted to ThinLTO")); + } else if (cppOptions.getLipoMode() != LipoMode.BINARY + || cppOptions.getFdoOptimize() == null) { reporter.handle(Event.warn("The --lipo_context option can only be used together with " + "--fdo_optimize= and --lipo=binary. LIPO context will be ignored.")); } } else { - if (cppOptions.getLipoMode() == LipoMode.BINARY && cppOptions.getFdoOptimize() != null) { + if (!isLLVMCompiler() + && cppOptions.getLipoMode() == LipoMode.BINARY + && cppOptions.getFdoOptimize() != null) { reporter.handle(Event.error("The --lipo_context option must be specified when using " + "--fdo_optimize= and --lipo=binary")); } @@ -2129,7 +2139,12 @@ public class CppConfiguration extends BuildConfiguration.Fragment { requestedFeatures.add(CppRuleClasses.AUTOFDO); } if (isLipoOptimizationOrInstrumentation()) { - requestedFeatures.add(CppRuleClasses.LIPO); + // Map LIPO to ThinLTO for LLVM builds. + if (isLLVMCompiler() && cppOptions.getFdoOptimize() != null) { + requestedFeatures.add(CppRuleClasses.THIN_LTO); + } else { + requestedFeatures.add(CppRuleClasses.LIPO); + } } if (ruleContext.getConfiguration().isCodeCoverageEnabled()) { requestedFeatures.add(CppRuleClasses.COVERAGE); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java index 781061b79b..472daf4635 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java @@ -577,7 +577,11 @@ public class FdoSupport { // If --fdo_optimize was not specified, we don't have any additional inputs. if (fdoProfile == null) { return ImmutableSet.of(); - } else if (fdoMode == FdoMode.AUTO_FDO || fdoMode == FdoMode.LLVM_FDO) { + } else if (fdoMode == FdoMode.LLVM_FDO) { + ImmutableSet.Builder auxiliaryInputs = ImmutableSet.builder(); + auxiliaryInputs.add(fdoSupportProvider.getProfileArtifact()); + return auxiliaryInputs.build(); + } else if (fdoMode == FdoMode.AUTO_FDO) { ImmutableSet.Builder auxiliaryInputs = ImmutableSet.builder(); auxiliaryInputs.add(fdoSupportProvider.getProfileArtifact()); if (lipoContextProvider != null) { -- cgit v1.2.3