[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.
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.