diff options
author | Googler <noreply@google.com> | 2017-12-20 08:10:21 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-12-20 09:17:54 -0800 |
commit | 8e3afccd8bea45105752ddeb33bde111c556fb8b (patch) | |
tree | 05042e2f8958acddaeb7b5defe358f173e927db3 /src/main/java | |
parent | de65ce90a648776788ac2fb0e7267e58163db501 (diff) |
Support for ThinLTO to be enabled implicitly with AFDO
Allows for ThinLTO to be enabled once the --features=autofdo_implicit_thinlto feature is enabled in the crosstool. Also allows for --features=-thin_lto to override and prevent ThinLTO from being enabled.
RELNOTES: None.
PiperOrigin-RevId: 179687743
Diffstat (limited to 'src/main/java')
4 files changed, 39 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java index 86339dab1b..b5d083486a 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java @@ -222,24 +222,30 @@ public final class RuleContext extends TargetContext Set<String> globallyEnabled = new HashSet<>(); Set<String> globallyDisabled = new HashSet<>(); parseFeatures(getConfiguration().getDefaultFeatures(), globallyEnabled, globallyDisabled); + Set<String> packageEnabled = new HashSet<>(); + Set<String> packageDisabled = new HashSet<>(); + parseFeatures(getRule().getPackage().getFeatures(), packageEnabled, packageDisabled); + Set<String> ruleEnabled = new HashSet<>(); + Set<String> ruleDisabled = new HashSet<>(); + if (attributes().has("features", Type.STRING_LIST)) { + parseFeatures(attributes().get("features", Type.STRING_LIST), ruleEnabled, ruleDisabled); + } + Set<String> ruleDisabledFeatures = + Sets.union(ruleDisabled, Sets.difference(packageDisabled, ruleEnabled)); + Set<String> disabledFeatures = Sets.union(ruleDisabledFeatures, globallyDisabled); for (ImmutableMap.Entry<Class<? extends Fragment>, Fragment> entry : getConfiguration().getAllFragments().entrySet()) { if (isLegalFragment(entry.getKey())) { - globallyEnabled.addAll(entry.getValue().configurationEnabledFeatures(this)); + globallyEnabled.addAll( + entry + .getValue() + .configurationEnabledFeatures(this, ImmutableSortedSet.copyOf(disabledFeatures))); } } - Set<String> packageEnabled = new HashSet<>(); - Set<String> packageDisabled = new HashSet<>(); - parseFeatures(getRule().getPackage().getFeatures(), packageEnabled, packageDisabled); Set<String> packageFeatures = Sets.difference(Sets.union(globallyEnabled, packageEnabled), packageDisabled); - Set<String> ruleFeatures = packageFeatures; - if (attributes().has("features", Type.STRING_LIST)) { - Set<String> ruleEnabled = new HashSet<>(); - Set<String> ruleDisabled = new HashSet<>(); - parseFeatures(attributes().get("features", Type.STRING_LIST), ruleEnabled, ruleDisabled); - ruleFeatures = Sets.difference(Sets.union(packageFeatures, ruleEnabled), ruleDisabled); - } + Set<String> ruleFeatures = + Sets.difference(Sets.union(packageFeatures, ruleEnabled), ruleDisabled); return ImmutableSortedSet.copyOf(Sets.difference(ruleFeatures, globallyDisabled)); } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java index e6e6a36b16..c3b6c41818 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java @@ -173,10 +173,9 @@ public class BuildConfiguration implements BuildEvent { return ImmutableMap.of(); } - /** - * Return set of features enabled by this configuration. - */ - public ImmutableSet<String> configurationEnabledFeatures(RuleContext ruleContext) { + /** Return set of features enabled by this configuration. */ + public ImmutableSet<String> configurationEnabledFeatures( + RuleContext ruleContext, ImmutableSet<String> disabledFeatures) { return ImmutableSet.of(); } 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 974551fd70..d843154454 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 @@ -1292,11 +1292,12 @@ public class CppConfiguration extends BuildConfiguration.Fragment { } /** - * Return set of features enabled by the CppConfiguration, specifically - * the FDO and LIPO related features enabled by options. + * Return set of features enabled by the CppConfiguration, specifically the FDO and LIPO related + * features enabled by options. */ @Override - public ImmutableSet<String> configurationEnabledFeatures(RuleContext ruleContext) { + public ImmutableSet<String> configurationEnabledFeatures( + RuleContext ruleContext, ImmutableSet<String> disabledFeatures) { ImmutableSet.Builder<String> requestedFeatures = ImmutableSet.builder(); if (cppOptions.getFdoInstrument() != null) { requestedFeatures.add(CppRuleClasses.FDO_INSTRUMENT); @@ -1308,6 +1309,11 @@ public class CppConfiguration extends BuildConfiguration.Fragment { } if (isFdo && CppFileTypes.GCC_AUTO_PROFILE.matches(fdoZip)) { requestedFeatures.add(CppRuleClasses.AUTOFDO); + // For LLVM, support implicit enabling of ThinLTO for AFDO unless it has been + // explicitly disabled. + if (isLLVMCompiler() && !disabledFeatures.contains(CppRuleClasses.THIN_LTO)) { + requestedFeatures.add(CppRuleClasses.ENABLE_AFDO_THINLTO); + } } if (isLipoOptimizationOrInstrumentation()) { // Map LIPO to ThinLTO for LLVM builds. diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java index ed54a38f70..af37c28c56 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java @@ -287,6 +287,16 @@ public class CppRuleClasses { */ public static final String THIN_LTO = "thin_lto"; + /* + * A string constant for allowing implicit ThinLTO enablement for AFDO. + */ + public static final java.lang.String AUTOFDO_IMPLICIT_THINLTO = "autofdo_implicit_thinlto"; + + /* + * A string constant for enabling ThinLTO for AFDO implicitly. + */ + public static final java.lang.String ENABLE_AFDO_THINLTO = "enable_afdo_thinlto"; + /** * A string constant for allowing use of shared LTO backend actions for linkstatic tests building * with ThinLTO. |