From 1b07f74e222e0949133e6a4c2578cbb5b4b625fb Mon Sep 17 00:00:00 2001 From: Luca Di Grazia Date: Sun, 4 Sep 2022 20:06:59 +0200 Subject: [PATCH] Do not try to unzip fdo profile in the host configuration https://github.com/bazelbuild/bazel/issues/6516 RELNOTES: None. PiperOrigin-RevId: 241523004 --- .../build/lib/rules/cpp/FdoHelper.java | 106 +----------------- 1 file changed, 6 insertions(+), 100 deletions(-) diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoHelper.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoHelper.java index aab809c0a9e..124ac706932 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoHelper.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoHelper.java @@ -44,7 +44,6 @@ public static FdoContext getFdoContext( CppToolchainInfo toolchainInfo) throws InterruptedException, RuleErrorException { FdoInputFile fdoInputFile = null; - FdoInputFile csFdoInputFile = null; FdoInputFile prefetchHints = null; Artifact protoProfileArtifact = null; Pair fdoInputs = null; @@ -88,26 +87,6 @@ public static FdoContext getFdoContext( != null) { fdoInputs = getFdoInputs(ruleContext, attributes.getXFdoProfileProvider()); } - - Pair csFdoInputs = null; - PathFragment csFdoZip = cppConfiguration.getCSFdoAbsolutePath(); - if (csFdoZip != null) { - csFdoInputFile = FdoInputFile.fromAbsolutePath(csFdoZip); - } else if (cppConfiguration.getCSFdoProfileLabel() != null) { - csFdoInputs = getFdoInputs(ruleContext, attributes.getCSFdoProfileProvider()); - } - if (csFdoInputs != null) { - csFdoInputFile = csFdoInputs.getFirst(); - } - } - - if (ruleContext.hasErrors()) { - return null; - } - - if (fdoInputs != null) { - fdoInputFile = fdoInputs.getFirst(); - protoProfileArtifact = fdoInputs.getSecond(); } if (ruleContext.hasErrors()) { @@ -136,12 +115,6 @@ public static FdoContext getFdoContext( ruleContext.ruleError("invalid extension for FDO profile file."); return null; } - // Check if this is LLVM_CS_FDO - if (branchFdoMode == BranchFdoMode.LLVM_FDO) { - if (csFdoInputFile != null) { - branchFdoMode = BranchFdoMode.LLVM_CS_FDO; - } - } if (branchFdoMode != BranchFdoMode.XBINARY_FDO && cppConfiguration.getXFdoProfileLabelUnsafeSinceItCanReturnValueFromWrongConfiguration() != null) { @@ -157,7 +130,7 @@ public static FdoContext getFdoContext( if (branchFdoMode == BranchFdoMode.LLVM_FDO) { profileArtifact = convertLLVMRawProfileToIndexed( - attributes, fdoInputFile, toolchainInfo, ruleContext, cppConfiguration, "fdo"); + attributes, fdoInputFile, toolchainInfo, ruleContext, cppConfiguration); if (ruleContext.hasErrors()) { return null; } @@ -171,33 +144,6 @@ public static FdoContext getFdoContext( profileArtifact, fdoInputFile, "Symlinking FDO profile " + fdoInputFile.getBasename()); - } else if (branchFdoMode == BranchFdoMode.LLVM_CS_FDO) { - Artifact nonCSProfileArtifact = - convertLLVMRawProfileToIndexed( - attributes, fdoInputFile, toolchainInfo, ruleContext, cppConfiguration, "fdo"); - if (ruleContext.hasErrors()) { - return null; - } - Artifact csProfileArtifact = - convertLLVMRawProfileToIndexed( - attributes, csFdoInputFile, toolchainInfo, ruleContext, cppConfiguration, "csfdo"); - if (ruleContext.hasErrors()) { - return null; - } - if (nonCSProfileArtifact != null && csProfileArtifact != null) { - profileArtifact = - mergeLLVMProfiles( - attributes, - toolchainInfo, - ruleContext, - nonCSProfileArtifact, - csProfileArtifact, - "mergedfdo", - "MergedCS.profdata"); - if (ruleContext.hasErrors()) { - return null; - } - } } branchFdoProfile = new FdoContext.BranchFdoProfile(branchFdoMode, profileArtifact, protoProfileArtifact); @@ -263,43 +209,6 @@ private static void symlinkTo( } } - /** This function merges profile1 and profile2 and generates mergedOutput. */ - private static Artifact mergeLLVMProfiles( - CcToolchainAttributesProvider attributes, - CppToolchainInfo toolchainInfo, - RuleContext ruleContext, - Artifact profile1, - Artifact profile2, - String fdoUniqueArtifactName, - String mergedOutput) { - Artifact profileArtifact = - ruleContext.getUniqueDirectoryArtifact( - fdoUniqueArtifactName, mergedOutput, ruleContext.getBinOrGenfilesDirectory()); - - // Merge LLVM profiles. - ruleContext.registerAction( - new SpawnAction.Builder() - .addInput(profile1) - .addInput(profile2) - .addTransitiveInputs(attributes.getAllFilesMiddleman()) - .addOutput(profileArtifact) - .useDefaultShellEnvironment() - .setExecutable(toolchainInfo.getToolPathFragment(Tool.LLVM_PROFDATA)) - .setProgressMessage("LLVMProfDataAction: Generating %s", profileArtifact.prettyPrint()) - .setMnemonic("LLVMProfDataMergeAction") - .addCommandLine( - CustomCommandLine.builder() - .add("merge") - .add("-o") - .addExecPath(profileArtifact) - .addExecPath(profile1) - .addExecPath(profile2) - .build()) - .build(ruleContext)); - - return profileArtifact; - } - /* * This function checks the format of the input profile data and converts it to * the indexed format (.profdata) if necessary. @@ -309,15 +218,14 @@ private static Artifact convertLLVMRawProfileToIndexed( FdoInputFile fdoProfile, CppToolchainInfo toolchainInfo, RuleContext ruleContext, - CppConfiguration cppConfiguration, - String fdoUniqueArtifactName) { + CppConfiguration cppConfiguration) { if (cppConfiguration.isThisHostConfigurationDoNotUseWillBeRemovedFor129045294()) { return null; } Artifact profileArtifact = ruleContext.getUniqueDirectoryArtifact( - fdoUniqueArtifactName, + "fdo", getLLVMProfileFileName(fdoProfile, CppFileTypes.LLVM_PROFILE), ruleContext.getBinOrGenfilesDirectory()); @@ -355,14 +263,12 @@ private static Artifact convertLLVMRawProfileToIndexed( } rawProfileArtifact = ruleContext.getUniqueDirectoryArtifact( - fdoUniqueArtifactName, rawProfileFileName, ruleContext.getBinOrGenfilesDirectory()); + "fdo", rawProfileFileName, ruleContext.getBinOrGenfilesDirectory()); // Symlink to the zipped profile file to extract the contents. Artifact zipProfileArtifact = ruleContext.getUniqueDirectoryArtifact( - fdoUniqueArtifactName, - fdoProfile.getBasename(), - ruleContext.getBinOrGenfilesDirectory()); + "fdo", fdoProfile.getBasename(), ruleContext.getBinOrGenfilesDirectory()); symlinkTo( ruleContext, zipProfileArtifact, @@ -391,7 +297,7 @@ private static Artifact convertLLVMRawProfileToIndexed( } else { rawProfileArtifact = ruleContext.getUniqueDirectoryArtifact( - fdoUniqueArtifactName, + "fdo", getLLVMProfileFileName(fdoProfile, CppFileTypes.LLVM_PROFILE_RAW), ruleContext.getBinOrGenfilesDirectory()); symlinkTo(