[all-commits] [llvm/llvm-project] 05411b: [SamplePGO] Optimize the basename matching logic f...

Snehasish Kumar via All-commits all-commits at lists.llvm.org
Mon Apr 13 09:14:05 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 05411b993108a5125c04cf4e3792c1061fb5b050
      https://github.com/llvm/llvm-project/commit/05411b993108a5125c04cf4e3792c1061fb5b050
  Author: Snehasish Kumar <mail at snehasish.net>
  Date:   2026-04-13 (Mon, 13 Apr 2026)

  Changed paths:
    M llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp

  Log Message:
  -----------
  [SamplePGO] Optimize the basename matching logic for matching unused profiles (#191523)

This change optimizes the basename matching logic in
`SampleProfileMatcher::matchFunctionsWithoutProfileByBasename` by
replacing the existing O(N*M) nested loop with an O(N+M) hash-based
lookup, while strictly preserving the original matching semantics. The
previous implementation relied on a substring heuristic
(`ProfName.contains(BaseName)`) to bypass expensive demangling
operations during the nested iteration; however, in codebases with
common or overlapping function names, this heuristic frequently
evaluated to true, resulting in redundant demangling and quadratic time
complexity. The updated approach demangles each profile name exactly
once and utilizes a `StringMap` to perform O(1) lookups against the
orphan functions. This eliminates the need for the substring pre-check
while maintaining the exact same constraints: establishing a strict 1:1
mapping between orphaned IR functions and profile entries, and correctly
identifying and rejecting ambiguous matches where multiple entities
share the same demangled basename.

Results in a 9x speedup on a large module with common basenames.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list