[llvm] [SampleFDO] Improve stale profile matching by diff algorithm (PR #87375)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 16:54:25 PDT 2024
================
@@ -19,6 +19,59 @@
namespace llvm {
+// Callsite location based matching anchor.
+struct Anchor {
+ LineLocation Loc;
+ FunctionId FuncId;
+
+ Anchor(const LineLocation &Loc, const FunctionId &FuncId)
+ : Loc(Loc), FuncId(FuncId) {}
+ Anchor(const LineLocation &Loc, StringRef &FName) : Loc(Loc), FuncId(FName) {}
+ bool operator==(const Anchor &Other) const {
+ return this->FuncId == Other.FuncId;
+ }
+};
+
+// This class implements the Myers diff algorithm used for stale profile
+// matching. The algorithm provides a simple and efficient way to find the
+// Longest Common Subsequence(LCS) or the Shortest Edit Script(SES) of two
+// sequences. For more details, refer to the paper 'An O(ND) Difference
+// Algorithm and Its Variations' by Eugene W. Myers.
+// In the scenario of profile fuzzy matching, the two sequences are the IR
+// callsite anchors and profile callsite anchors. The subsequence equivalent
+// parts from the resulting SES are used to remap the IR locations to the
+// profile locations. As the number of function callsite is usually not big, we
+// currently just implements the basic greedy version(page 6 of the paper).
+class MyersDiff {
+public:
+ struct DiffResult {
----------------
WenleiHe wrote:
I hope we can simplify this. The abstractions here seem unnecessary -- 1) `MyersDiff` is entirely stateless, so no need for class / instances. 2) `DiffResult` is really just a `LocToLocMap` if we remove all the test/debug related stuff.
https://github.com/llvm/llvm-project/pull/87375
More information about the llvm-commits
mailing list