[llvm] [Sample Profile] Expand functionality of llvm-profdata function filter (PR #101615)
Lei Wang via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 22:55:56 PDT 2024
================
@@ -278,6 +279,110 @@ void FunctionSamples::findAllNames(DenseSet<FunctionId> &NameSet) const {
}
}
+namespace {
+// A class to keep a string invariant where it is appended with contents in a
+// recursive function.
+struct ScopedString {
+ std::string &String;
+
+ size_t Length;
+
+ ScopedString(std::string &String) : String(String), Length(String.length()) {}
+
+ ~ScopedString() {
+ assert(String.length() > Length);
+ String.resize(Length);
+ }
+};
+} // namespace
+
+// CanonicalName is invariant in this function. It should already contain the
+// canonical name of the current FunctionSamples.
+uint64_t FunctionSamples::eraseInlinedCallsites(const llvm::Regex &Re,
+ std::string &CanonicalName,
+ bool MatchCallTargets,
+ bool EraseMatch) {
+ uint64_t Result = 0;
+
+ ScopedString SaveString1(CanonicalName);
----------------
wlei-llvm wrote:
I was confused why it created a variable but never used.. then I found it leveraged a dtor to resize string.. can we avoid this? is it possible just use a length or create a tmp string to do this?
https://github.com/llvm/llvm-project/pull/101615
More information about the llvm-commits
mailing list