llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-llvm-transforms Author: shaw young (shawbyoung) <details> <summary>Changes</summary> Test Plan: tbd --- Full diff: https://github.com/llvm/llvm-project/pull/95156.diff 2 Files Affected: - (modified) bolt/lib/Profile/StaleProfileMatching.cpp (+14-2) - (modified) llvm/include/llvm/Transforms/Utils/SampleProfileInference.h (+2-1) ``````````diff diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 5969f4b9bcbc1..41afa6b4bbb19 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -51,6 +51,12 @@ cl::opt<bool> cl::desc("Infer counts from stale profile data."), cl::init(false), cl::Hidden, cl::cat(BoltOptCategory)); +cl::opt<unsigned> MatchedProfileThreshold( + "matched-profile-threshold", + cl::desc("Percentage threshold of matched execution counts at which stale " + "profile inference is executed."), + cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); + cl::opt<unsigned> StaleMatchingMaxFuncSize( "stale-matching-max-func-size", cl::desc("The maximum size of a function to consider for inference."), @@ -451,6 +457,7 @@ void matchWeightsByHashes(BinaryContext &BC, if (Matcher.isHighConfidenceMatch(BinHash, YamlHash)) { ++BC.Stats.NumMatchedBlocks; BC.Stats.MatchedSampleCount += YamlBB.ExecCount; + Func.MatchedExecCount += YamlBB.ExecCount; LLVM_DEBUG(dbgs() << " exact match\n"); } else { LLVM_DEBUG(dbgs() << " loose match\n"); @@ -592,10 +599,15 @@ void preprocessUnreachableBlocks(FlowFunction &Func) { /// Decide if stale profile matching can be applied for a given function. /// Currently we skip inference for (very) large instances and for instances /// having "unexpected" control flow (e.g., having no sink basic blocks). -bool canApplyInference(const FlowFunction &Func) { +bool canApplyInference(const FlowFunction &Func, + const yaml::bolt::BinaryFunctionProfile &YamlBF) { if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; + if (Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100) + return false; + bool HasExitBlocks = llvm::any_of( Func.Blocks, [&](const FlowBlock &Block) { return Block.isExit(); }); if (!HasExitBlocks) @@ -756,7 +768,7 @@ bool YAMLProfileReader::inferStaleProfile( preprocessUnreachableBlocks(Func); // Check if profile inference can be applied for the instance. - if (!canApplyInference(Func)) + if (!canApplyInference(Func, YamlBF)) return false; // Apply the profile inference algorithm. diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index 70a80b91405d0..c654715c0ae9f 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,7 +58,8 @@ struct FlowFunction { std::vector<FlowJump> Jumps; /// The index of the entry block. uint64_t Entry{0}; - uint64_t Sink{UINT64_MAX}; + // Matched execution count for the function. + uint64_t MatchedExecCount{0}; }; /// Various thresholds and options controlling the behavior of the profile `````````` </details> https://github.com/llvm/llvm-project/pull/95156 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits