diff options
author | 2017-06-13 20:44:27 +0200 | |
---|---|---|
committer | 2017-06-14 13:17:11 +0200 | |
commit | c61f86f56b86e442369725ad79299ccc5519b000 (patch) | |
tree | e2bde6d9fbfb321e44a761b6318895b8123e974e /src/main/java/com/google/devtools/build/lib/rules | |
parent | 94bee75ab3611c3578e9ed35099b862ebe81f249 (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java | 33 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java | 6 |
2 files changed, 29 insertions, 10 deletions
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=<profile zip> 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=<profile zip> 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<Artifact> auxiliaryInputs = ImmutableSet.builder(); + auxiliaryInputs.add(fdoSupportProvider.getProfileArtifact()); + return auxiliaryInputs.build(); + } else if (fdoMode == FdoMode.AUTO_FDO) { ImmutableSet.Builder<Artifact> auxiliaryInputs = ImmutableSet.builder(); auxiliaryInputs.add(fdoSupportProvider.getProfileArtifact()); if (lipoContextProvider != null) { |