[all-commits] [llvm/llvm-project] d0388c: Optimize the basename matching logic.

Snehasish Kumar via All-commits all-commits at lists.llvm.org
Fri Apr 10 14:03:55 PDT 2026


  Branch: refs/heads/users/snehasish/04-10-optimize_the_basename_matching_logic
  Home:   https://github.com/llvm/llvm-project
  Commit: d0388c40ff02d273bc02ba05541b9814c9fdfb5b
      https://github.com/llvm/llvm-project/commit/d0388c40ff02d273bc02ba05541b9814c9fdfb5b
  Author: Snehasish Kumar <snehasishk at google.com>
  Date:   2026-04-10 (Fri, 10 Apr 2026)

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

  Log Message:
  -----------
  Optimize the basename matching logic.

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