[llvm-branch-commits] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/95156 Test Plan: tbd ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung edited 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
[llvm-branch-commits] Updated CommandLineArgumentReference.md (PR #95160)
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/95160 Test Plan: tbd ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Updated CommandLineArgumentReference.md (PR #95160)
https://github.com/shawbyoung closed https://github.com/llvm/llvm-project/pull/95160 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/2] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/2] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/3] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/3] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 3/3] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
@@ -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 ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) +return false; shawbyoung wrote: I’m leaning towards the block count heuristic now. I think the 1M and 4x1K exec count block case is likely pretty common – I imagine functions with loops would look a lot like this. Having some blocks matched exactly would suggest to me that there would likely be a reasonable amount of similarity between the profiled function and existing function relationally, which block coldness likely doesn’t have an outsized bearing on. I think having a reasonably high threshold for matched blocks would conservatively allow us to drop functions in high discrepancy – I’ll test this on a production binary. 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
[llvm-branch-commits] Using matched block counts to measure discrepancy (PR #95486)
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/95486 Test Plan: tbd ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Using matched block counts to measure discrepancy (PR #95486)
https://github.com/shawbyoung closed https://github.com/llvm/llvm-project/pull/95486 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/4] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/4] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 3/4] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 4/4] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of blocks ma
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/5] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/5] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 3/5] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 4/5] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of blocks ma
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/5] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/5] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 3/5] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 4/5] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of blocks ma
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/5] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/5] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 3/5] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 4/5] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of blocks ma
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
@@ -180,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of blocks matched loosely. + uint64_t MatchedLooseBlocks{0}; + /// The number of execution counts matched. + uint64_t MatchedExecCounts{0}; shawbyoung wrote: Left this for possible extensibility of our definition for the threshold, but since these aren't being used at the moment, I'll remove them 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
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung edited 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
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/6] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/6] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 3/6] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 4/6] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of blocks ma
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
@@ -51,6 +51,12 @@ cl::opt cl::desc("Infer counts from stale profile data."), cl::init(false), cl::Hidden, cl::cat(BoltOptCategory)); +cl::opt StaleMatchingMinMatchedBlock( +"stale-matching-min-matched-block", +cl::desc("Percentage threshold of matched basic blocks at which stale " + "profile inference is executed."), +cl::init(50), cl::Hidden, cl::cat(BoltOptCategory)); shawbyoung wrote: Yes, changed the default to 0 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
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/7] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/7] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 3/7] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 4/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of blocks ma
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/8] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/8] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 3/8] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 4/8] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of blocks ma
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung edited 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
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung edited 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
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung edited 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
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 1/9] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 2/9] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 3/9] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 4/9] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of blocks ma
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 01/10] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 02/10] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 03/10] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 04/10] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of b
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 01/11] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 02/11] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 03/11] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 04/11] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of b
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 01/12] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 02/12] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 03/12] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 04/12] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of b
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
@@ -394,7 +400,7 @@ createFlowFunction(const BinaryFunction::BasicBlockOrderType &BlockOrder) { void matchWeightsByHashes(BinaryContext &BC, const BinaryFunction::BasicBlockOrderType &BlockOrder, const yaml::bolt::BinaryFunctionProfile &YamlBF, - FlowFunction &Func) { + FlowFunction &Func, uint64_t &MatchedBlocksCount) { shawbyoung wrote: In the case that we want to build upon our profile discrepancy heuristic, I think it makes sense to pass in a reference to "something" (variable, struct) that maintains information related to the heuristic, similarly how to the flow function is treated by this function. But I don't have strong feelings about this - if you do I'm happy to change it. 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
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
@@ -394,7 +400,7 @@ createFlowFunction(const BinaryFunction::BasicBlockOrderType &BlockOrder) { void matchWeightsByHashes(BinaryContext &BC, const BinaryFunction::BasicBlockOrderType &BlockOrder, const yaml::bolt::BinaryFunctionProfile &YamlBF, - FlowFunction &Func) { + FlowFunction &Func, uint64_t &MatchedBlocksCount) { shawbyoung wrote: Sounds good 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
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 01/13] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 02/13] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 03/13] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 04/13] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of b
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 01/14] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 02/14] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 03/14] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 04/14] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of b
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95156 >From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 11 Jun 2024 11:43:13 -0700 Subject: [PATCH 01/15] Summary: Functions with little exact matching Created using spr 1.3.4 --- bolt/docs/CommandLineArgumentReference.md | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 8887d1f5d5bd4..bdc1d9dfd735c 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -614,6 +614,17 @@ - `--lite-threshold-pct=` + Threshold (in percent) of matched profile at which stale profile inference is + applied to functions. Argument corresponds to the sum of matched execution + counts of function blocks divided by the sum of execution counts of function + blocks. E.g if the sum of a function blocks' execution counts is 100, the sum + of the function blocks' matched execution counts is 10, and the argument is 15 + (15%), profile inference will not be applied to that function. A higher + threshold will correlate with fewer functions to process in cases of stale + profile. Default set to %5. + +- `--matched-profile-threshold=` + Threshold (in percent) for selecting functions to process in lite mode. Higher threshold means fewer functions to process. E.g threshold of 90 means only top 10 percent of functions with profile will be processed. @@ -1161,4 +1172,4 @@ - `--print-options` - Print non-default options after command line parsing \ No newline at end of file + Print non-default options after command line parsing >From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:40 -0700 Subject: [PATCH 02/15] Update SampleProfileInference.h --- llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h index c654715c0ae9f..9ccbd0fa88f3d 100644 --- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h @@ -58,6 +58,7 @@ struct FlowFunction { std::vector 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}; }; >From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001 From: shaw young <58664393+shawbyo...@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:39:28 -0700 Subject: [PATCH 03/15] Update StaleProfileMatching.cpp --- bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 41afa6b4bbb19..47335163263a4 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func, if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize) return false; - if (Func.MatchedExecCount / YamlBF.ExecCount >= - opts::MatchedProfileThreshold / 100) + if ((double)Func.MatchedExecCount / YamlBF.ExecCount >= + opts::MatchedProfileThreshold / 100.0) return false; bool HasExitBlocks = llvm::any_of( >From 3fc6d72d866333d8ce964fdfaa748791d4f8d2b4 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Fri, 14 Jun 2024 08:38:19 -0700 Subject: [PATCH 04/15] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/StaleProfileMatching.cpp | 37 +++ .../Transforms/Utils/SampleProfileInference.h | 3 -- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index 47335163263a4..cb356afdd2948 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -53,9 +53,9 @@ cl::opt cl::opt MatchedProfileThreshold( "matched-profile-threshold", -cl::desc("Percentage threshold of matched execution counts at which stale " +cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), -cl::init(5), cl::Hidden, cl::cat(BoltOptCategory)); +cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); cl::opt StaleMatchingMaxFuncSize( "stale-matching-max-func-size", @@ -186,6 +186,17 @@ struct BlendedBlockHash { uint8_t SuccHash{0}; }; +/// A data object containing function matching information. +struct FunctionMatchingData { +public: + /// The number of blocks matched exactly. + uint64_t MatchedExactBlocks{0}; + /// The number of b
[llvm-branch-commits] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/95821 Using the hashes of binary and profiled functions to recover functions with changed names. Test Plan: tbd ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)
https://github.com/shawbyoung closed 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
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 1/2] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 2/2] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 1/3] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 2/3] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 3/3] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 1/4] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 2/4] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 3/4] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 4/4] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 1/5] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 2/5] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 3/5] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 4/5] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 5/5] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) dif
[llvm-branch-commits] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/95884 Matching functions based on edit distance. Test Plan: tbd ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 1/6] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 2/6] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 3/6] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 4/6] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 5/6] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) dif
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 3/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 4/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 5/7] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) dif
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 1/8] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 2/8] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 3/8] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 4/8] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 5/8] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) dif
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 1/9] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 2/9] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 3/9] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 4/9] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 5/9] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) dif
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/10] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/10] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/10] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/10] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/10] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/11] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/11] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/11] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/11] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/11] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/12] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/12] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/12] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/12] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/12] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/13] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/13] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/13] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/13] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/13] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung edited https://github.com/llvm/llvm-project/pull/95821 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/14] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/14] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/14] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/14] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/14] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/2] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/2] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
@@ -415,6 +422,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF)) matchProfileToFunction(YamlBF, *BF); + // Uses name similarity to match functions that were not matched by name. + uint64_t MatchedWithDemangledName = 0; + + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { + int Status = 0; + char *DemangledName = abi::__cxa_demangle(String, +nullptr, nullptr, &Status); + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); +} + +for (auto YamlBF : YamlBP.Functions) { + if (YamlBF.Used) +continue; + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) +continue; + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +continue; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); shawbyoung wrote: For the sake of matching - is not a good idea to apply the same function name transformation to both the YamlBF and BF function names? https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung deleted https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/3] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/3] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
@@ -374,15 +393,34 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // the profile. Function.setExecutionCount(BinaryFunction::COUNT_NO_PROFILE); -// Recompute hash once per function. -if (!opts::IgnoreHash) - Function.computeHash(YamlBP.Header.IsDFSOrder, - YamlBP.Header.HashFunction); - -if (profileMatches(YamlBF, Function)) +if (profileMatches(YamlBF, Function)) { matchProfileToFunction(YamlBF, Function); + ++MatchedWithExactName; +} } + // Uses the strict hash of profiled and binary functions to match functions + // that are not matched by name or common name. + if (opts::MatchingFunctionsWithHash) { shawbyoung wrote: In BOLT, a strict hash captures a binary function's block order as well as each blocks' instructions & opcodes. So, the goal of this PR is to recover block-identical functions that have been simply been renamed. https://github.com/llvm/llvm-project/pull/95821 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/3] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/3] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/3] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/3] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/4] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/4] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/5] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/5] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/6] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/6] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
@@ -1161,4 +1165,4 @@ - `--print-options` - Print non-default options after command line parsing shawbyoung wrote: Didn't touch this line - diff return nothing when applied to "added" and "deleted" line - maybe it's some git corner case? https://github.com/llvm/llvm-project/pull/95821 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung edited https://github.com/llvm/llvm-project/pull/95821 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/15] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/15] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/15] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/15] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/15] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/16] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/16] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/16] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/16] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/16] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/17] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/17] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/17] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/17] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/17] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/18] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/18] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/18] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/18] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/18] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/19] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/19] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/19] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/19] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/19] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/20] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/20] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [llvm] [BOLT] Hash-based function matching (PR #95821)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95821 >From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:02 -0700 Subject: [PATCH 01/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index f0fcb1c130002..2bca83c9d11ec 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto& [_, BF] : BC.getBinaryFunctions()) { +if (!ProfiledFunctions.count(&BF)) + continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } >From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:39:39 -0700 Subject: [PATCH 02/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 2bca83c9d11ec..56474a67307ed 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses the strict hash of profiled and binary functions to match functions // that are not matched by name or common name. - std::unordered_map StrictBinaryFunctionHashes; + std::unordered_map StrictBinaryFunctionHashes; StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); - for (auto& [_, BF] : BC.getBinaryFunctions()) { + for (auto &[_, BF] : BC.getBinaryFunctions()) { if (!ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; @@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { for (auto YamlBF : YamlBP.Functions) { auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); -if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { +if (It != StrictBinaryFunctionHashes.end() && +!ProfiledFunctions.count(It->second)) { auto *BF = It->second; matchProfileToFunction(YamlBF, *BF); } >From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:55:58 -0700 Subject: [PATCH 03/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 +- bolt/test/X86/profile-passthrough-block.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 56474a67307ed..779d60bce3b66 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size()); for (auto &[_, BF] : BC.getBinaryFunctions()) { -if (!ProfiledFunctions.count(&BF)) +if (ProfiledFunctions.count(&BF)) continue; StrictBinaryFunctionHashes[BF.getHash()] = &BF; } diff --git a/bolt/test/X86/profile-passthrough-block.test b/bolt/test/X86/profile-passthrough-block.test index 1b875885260dc..ed2a8117ddfc4 100644 --- a/bolt/test/X86/profile-passthrough-block.test +++ b/bolt/test/X86/profile-passthrough-block.test @@ -57,7 +57,7 @@ header: functions: - name:main fid: 0 -hash:0x +hash:0x0001 exec:1 nblocks: 6 blocks: >From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 15:58:22 -0700 Subject: [PATCH 04/20] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 779d60bce3b66..e3d30bfdb74e4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { } for (auto YamlBF : YamlBP.Functions) { +if (YamlBF.Used) + continue; auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash); if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) { >From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 17 Jun 2024 16:00:27 -0700 Subject: [PATCH 05/20] spr amend Created using spr 1.3.4 --- bolt/test/X86/profile-passthrough-block.test | 2 +- 1 file changed, 1 insertion(+), 1 deleti
[llvm-branch-commits] [BOLT][NFC] Move opts::Lite to CommandLineOpts.cpp (PR #96571)
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/96571 Test Plan: n/a ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT][NFC] Move opts::Lite to CommandLineOpts.cpp (PR #96571)
https://github.com/shawbyoung closed https://github.com/llvm/llvm-project/pull/96571 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung converted_to_draft https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [BOLT] Function matching with function calls as anchors (PR #96596)
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/96596 Test Plan: tbd ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Function matching with function calls as anchors (PR #96596)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/96596 >From 05d59574d6260b98a469921eb2fccf5398bfafb6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 24 Jun 2024 23:00:59 -0700 Subject: [PATCH] Added call to matchWithCallsAsAnchors Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index aafffac3d4b1c..1a0e5d239d252 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -479,6 +479,9 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF)) matchProfileToFunction(YamlBF, *BF); + uint64_t MatchedWithCallsAsAnchors = 0; + matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Function matching with function calls as anchors (PR #96596)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/96596 >From 05d59574d6260b98a469921eb2fccf5398bfafb6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 24 Jun 2024 23:00:59 -0700 Subject: [PATCH 1/2] Added call to matchWithCallsAsAnchors Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index aafffac3d4b1c..1a0e5d239d252 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -479,6 +479,9 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF)) matchProfileToFunction(YamlBF, *BF); + uint64_t MatchedWithCallsAsAnchors = 0; + matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 77ef0008f4f5987719555e6cc3e32da812ae0f31 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 24 Jun 2024 23:11:43 -0700 Subject: [PATCH 2/2] Changed CallHashToBF representation Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 1a0e5d239d252..91b01a99c7485 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -29,6 +29,10 @@ static llvm::cl::opt cl::desc("ignore hash while reading function profile"), cl::Hidden, cl::cat(BoltOptCategory)); +llvm::cl::opt MatchWithCallsAsAnchors("match-with-calls-as-anchors", + cl::desc("Matches with calls as anchors"), + cl::Hidden, cl::cat(BoltOptCategory)); + llvm::cl::opt ProfileUseDFS("profile-use-dfs", cl::desc("use DFS order for YAML profile"), cl::Hidden, cl::cat(BoltOptCategory)); @@ -353,7 +357,7 @@ void YAMLProfileReader::matchWithCallsAsAnchors( llvm_unreachable("Unhandled HashFunction"); }; - std::unordered_map CallHashToBF; + std::unordered_map CallHashToBF; for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { if (ProfiledFunctions.count(BF)) @@ -375,12 +379,12 @@ void YAMLProfileReader::matchWithCallsAsAnchors( for (const std::string &FunctionName : FunctionNames) HashString.append(FunctionName); } -CallHashToBF.emplace(ComputeCallHash(HashString), BF); +CallHashToBF[ComputeCallHash(HashString)] = BF; } std::unordered_map ProfiledFunctionIdToName; - for (const yaml::bolt::BinaryFunctionProfile YamlBF : YamlBP.Functions) + for (const yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) ProfiledFunctionIdToName[YamlBF.Id] = YamlBF.Name; for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) { @@ -401,7 +405,7 @@ void YAMLProfileReader::matchWithCallsAsAnchors( auto It = CallHashToBF.find(Hash); if (It == CallHashToBF.end()) continue; -matchProfileToFunction(YamlBF, It->second); +matchProfileToFunction(YamlBF, *It->second); ++MatchedWithCallsAsAnchors; } } @@ -480,7 +484,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { matchProfileToFunction(YamlBF, *BF); uint64_t MatchedWithCallsAsAnchors = 0; - matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); + if (opts::MatchWithCallsAsAnchors) +matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
shawbyoung wrote: > Can you please also note the runtime of the namespace-filtered pairwise > checks? This would guide us in whether to add a BB count filtering. Ran BOLT on the adpublisher binary – with name similarity function matching, total execution time of rewrite passes was 2235.2883 seconds (1989.1823 wall clock) with an edit distance threshold of 20 and 2194.1708 seconds (1986.2007 wall clock) with an edit distance threshold of 10. Without name similarity matching, total execution time of rewrite passes was 520.4121 seconds (296.4178 wall clock). https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Function matching with function calls as anchors (PR #96596)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/96596 >From 05d59574d6260b98a469921eb2fccf5398bfafb6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 24 Jun 2024 23:00:59 -0700 Subject: [PATCH 1/3] Added call to matchWithCallsAsAnchors Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index aafffac3d4b1c..1a0e5d239d252 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -479,6 +479,9 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF)) matchProfileToFunction(YamlBF, *BF); + uint64_t MatchedWithCallsAsAnchors = 0; + matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 77ef0008f4f5987719555e6cc3e32da812ae0f31 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 24 Jun 2024 23:11:43 -0700 Subject: [PATCH 2/3] Changed CallHashToBF representation Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 1a0e5d239d252..91b01a99c7485 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -29,6 +29,10 @@ static llvm::cl::opt cl::desc("ignore hash while reading function profile"), cl::Hidden, cl::cat(BoltOptCategory)); +llvm::cl::opt MatchWithCallsAsAnchors("match-with-calls-as-anchors", + cl::desc("Matches with calls as anchors"), + cl::Hidden, cl::cat(BoltOptCategory)); + llvm::cl::opt ProfileUseDFS("profile-use-dfs", cl::desc("use DFS order for YAML profile"), cl::Hidden, cl::cat(BoltOptCategory)); @@ -353,7 +357,7 @@ void YAMLProfileReader::matchWithCallsAsAnchors( llvm_unreachable("Unhandled HashFunction"); }; - std::unordered_map CallHashToBF; + std::unordered_map CallHashToBF; for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { if (ProfiledFunctions.count(BF)) @@ -375,12 +379,12 @@ void YAMLProfileReader::matchWithCallsAsAnchors( for (const std::string &FunctionName : FunctionNames) HashString.append(FunctionName); } -CallHashToBF.emplace(ComputeCallHash(HashString), BF); +CallHashToBF[ComputeCallHash(HashString)] = BF; } std::unordered_map ProfiledFunctionIdToName; - for (const yaml::bolt::BinaryFunctionProfile YamlBF : YamlBP.Functions) + for (const yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) ProfiledFunctionIdToName[YamlBF.Id] = YamlBF.Name; for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) { @@ -401,7 +405,7 @@ void YAMLProfileReader::matchWithCallsAsAnchors( auto It = CallHashToBF.find(Hash); if (It == CallHashToBF.end()) continue; -matchProfileToFunction(YamlBF, It->second); +matchProfileToFunction(YamlBF, *It->second); ++MatchedWithCallsAsAnchors; } } @@ -480,7 +484,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { matchProfileToFunction(YamlBF, *BF); uint64_t MatchedWithCallsAsAnchors = 0; - matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); + if (opts::MatchWithCallsAsAnchors) +matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) >From ea7cb68ab9e8e158412c2e752986968968a60d93 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 25 Jun 2024 09:28:39 -0700 Subject: [PATCH 3/3] Changed BF called FunctionNames to multiset Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 91b01a99c7485..3b3d73f7af023 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -365,7 +365,7 @@ void YAMLProfileReader::matchWithCallsAsAnchors( std::string HashString; for (const auto &BB : BF->blocks()) { - std::set FunctionNames; + std::multiset FunctionNames; for (const MCInst &Instr : BB) { // Skip non-call instructions. if (!BC.MIB->isCall(Instr)) @@ -397,9 +397,8 @@ void YAMLProfileReader::matchWithCallsAsAnchors( std::string &FunctionName = ProfiledFunctionIdToName[CallSite.DestId]; FunctionNames.insert(FunctionName);
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung ready_for_review https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Function matching with function calls as anchors (PR #96596)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/96596 >From 05d59574d6260b98a469921eb2fccf5398bfafb6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 24 Jun 2024 23:00:59 -0700 Subject: [PATCH 1/4] Added call to matchWithCallsAsAnchors Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index aafffac3d4b1c..1a0e5d239d252 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -479,6 +479,9 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF)) matchProfileToFunction(YamlBF, *BF); + uint64_t MatchedWithCallsAsAnchors = 0; + matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 77ef0008f4f5987719555e6cc3e32da812ae0f31 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Mon, 24 Jun 2024 23:11:43 -0700 Subject: [PATCH 2/4] Changed CallHashToBF representation Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 1a0e5d239d252..91b01a99c7485 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -29,6 +29,10 @@ static llvm::cl::opt cl::desc("ignore hash while reading function profile"), cl::Hidden, cl::cat(BoltOptCategory)); +llvm::cl::opt MatchWithCallsAsAnchors("match-with-calls-as-anchors", + cl::desc("Matches with calls as anchors"), + cl::Hidden, cl::cat(BoltOptCategory)); + llvm::cl::opt ProfileUseDFS("profile-use-dfs", cl::desc("use DFS order for YAML profile"), cl::Hidden, cl::cat(BoltOptCategory)); @@ -353,7 +357,7 @@ void YAMLProfileReader::matchWithCallsAsAnchors( llvm_unreachable("Unhandled HashFunction"); }; - std::unordered_map CallHashToBF; + std::unordered_map CallHashToBF; for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { if (ProfiledFunctions.count(BF)) @@ -375,12 +379,12 @@ void YAMLProfileReader::matchWithCallsAsAnchors( for (const std::string &FunctionName : FunctionNames) HashString.append(FunctionName); } -CallHashToBF.emplace(ComputeCallHash(HashString), BF); +CallHashToBF[ComputeCallHash(HashString)] = BF; } std::unordered_map ProfiledFunctionIdToName; - for (const yaml::bolt::BinaryFunctionProfile YamlBF : YamlBP.Functions) + for (const yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) ProfiledFunctionIdToName[YamlBF.Id] = YamlBF.Name; for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) { @@ -401,7 +405,7 @@ void YAMLProfileReader::matchWithCallsAsAnchors( auto It = CallHashToBF.find(Hash); if (It == CallHashToBF.end()) continue; -matchProfileToFunction(YamlBF, It->second); +matchProfileToFunction(YamlBF, *It->second); ++MatchedWithCallsAsAnchors; } } @@ -480,7 +484,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { matchProfileToFunction(YamlBF, *BF); uint64_t MatchedWithCallsAsAnchors = 0; - matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); + if (opts::MatchWithCallsAsAnchors) +matchWithCallsAsAnchors(BC, MatchedWithCallsAsAnchors); for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) >From ea7cb68ab9e8e158412c2e752986968968a60d93 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Tue, 25 Jun 2024 09:28:39 -0700 Subject: [PATCH 3/4] Changed BF called FunctionNames to multiset Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 91b01a99c7485..3b3d73f7af023 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -365,7 +365,7 @@ void YAMLProfileReader::matchWithCallsAsAnchors( std::string HashString; for (const auto &BB : BF->blocks()) { - std::set FunctionNames; + std::multiset FunctionNames; for (const MCInst &Instr : BB) { // Skip non-call instructions. if (!BC.MIB->isCall(Instr)) @@ -397,9 +397,8 @@ void YAMLProfileReader::matchWithCallsAsAnchors( std::string &FunctionName = ProfiledFunctionIdToName[CallSite.DestId]; FunctionNames.insert(FunctionName);
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
shawbyoung wrote: > Thank you for checking the runtime, and it's quite high. We'll need extra > filtering by block count to keep runtime low - please add it as we discussed. >if (BF->size() != YamlBF.NumBasicBlocks) > continue; Functions are filtered by block size here @aaupov https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung edited https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung edited https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung edited https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung updated https://github.com/llvm/llvm-project/pull/95884 >From 34652b2eebc62218c50a23509ce99937385c30e6 Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:42:00 -0700 Subject: [PATCH 1/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 73 -- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 66cabc236f4b2..c9f6d88f0b13a 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -424,36 +424,75 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { // Uses name similarity to match functions that were not matched by name. uint64_t MatchedWithDemangledName = 0; - if (opts::NameSimilarityFunctionMatchingThreshold > 0) { - -std::unordered_map NameToBinaryFunction; -NameToBinaryFunction.reserve(BC.getBinaryFunctions().size()); -for (auto &[_, BF] : BC.getBinaryFunctions()) { + if (opts::NameSimilarityFunctionMatchingThreshold > 0) { +auto DemangleName = [&](const char* String) { int Status = 0; - char *DemangledName = abi::__cxa_demangle(BF.getOneName().str().c_str(), + char *DemangledName = abi::__cxa_demangle(String, nullptr, nullptr, &Status); - if (Status == 0) -NameToBinaryFunction[std::string(DemangledName)] = &BF; + return Status == 0 ? new std::string(DemangledName) : nullptr; +}; + +auto DeriveNameSpace = [&](std::string DemangledName) { + size_t LParen = std::string(DemangledName).find("("); + std::string FunctionName = std::string(DemangledName).substr(0, LParen); + size_t ScopeResolutionOperator = std::string(FunctionName).rfind("::"); + return ScopeResolutionOperator == std::string::npos ? std::string("") : std::string(DemangledName).substr(0, ScopeResolutionOperator); +}; + +std::unordered_map> NamespaceToBFs; +NamespaceToBFs.reserve(BC.getBinaryFunctions().size()); + +for (BinaryFunction *BF : BC.getAllBinaryFunctions()) { + std::string* DemangledName = DemangleName(BF->getOneName().str().c_str()); + if (!DemangledName) +continue; + std::string Namespace = DeriveNameSpace(*DemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) +NamespaceToBFs[Namespace] = {BF}; + else +It->second.push_back(BF); } for (auto YamlBF : YamlBP.Functions) { if (YamlBF.Used) continue; - int Status = 0; - char *DemangledName = - abi::__cxa_demangle(YamlBF.Name.c_str(), nullptr, nullptr, &Status); - if (Status != 0) + std::string* YamlBFDemangledName = DemangleName(YamlBF.Name.c_str()); + if (!YamlBFDemangledName) continue; - auto It = NameToBinaryFunction.find(DemangledName); - if (It == NameToBinaryFunction.end()) + std::string Namespace = DeriveNameSpace(*YamlBFDemangledName); + auto It = NamespaceToBFs.find(Namespace); + if (It == NamespaceToBFs.end()) continue; - BinaryFunction *BF = It->second; - matchProfileToFunction(YamlBF, *BF); - ++MatchedWithDemangledName; + std::vector BFs = It->second; + + unsigned MinEditDistance = UINT_MAX; + BinaryFunction *ClosestNameBF = nullptr; + + for (BinaryFunction *BF : BFs) { +if (ProfiledFunctions.count(BF)) + continue; +std::string *BFDemangledName = DemangleName(BF->getOneName().str().c_str()); +if (!BFDemangledName) + continue; +unsigned BFEditDistance = StringRef(*BFDemangledName).edit_distance(*YamlBFDemangledName); +if (BFEditDistance < MinEditDistance) { + MinEditDistance = BFEditDistance; + ClosestNameBF = BF; +} + } + + if (ClosestNameBF && +MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold) { +matchProfileToFunction(YamlBF, *ClosestNameBF); +++MatchedWithDemangledName; + } } } + outs() << MatchedWithDemangledName << ": functions matched by name similarity\n"; + for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) if (!YamlBF.Used && opts::Verbosity >= 1) errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name >From 2d23bbd6b9ce4f0786ae8ceb39b1b008b4ca9c4d Mon Sep 17 00:00:00 2001 From: shawbyoung Date: Thu, 20 Jun 2024 23:45:27 -0700 Subject: [PATCH 2/7] spr amend Created using spr 1.3.4 --- bolt/lib/Profile/YAMLProfileReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index c9f6d88f0b13a..cf4a5393df8f4 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -491,8 +491,6 @@ Error YAMLProfileReader::read
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung edited https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
https://github.com/shawbyoung edited https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits