summaryrefslogtreecommitdiff
path: root/lld/ELF/CallGraphSort.cpp
AgeCommit message (Collapse)Author
2025-01-05[ELF] Allow --symbol-ordering-file and call graph profile to be used togetherFangrui Song
Port https://reviews.llvm.org/D117354 from the MachO port. If both --symbol-ordering-file and call graph profile are present, the --symbol-ordering-file takes precedence, but the call graph profile is still used for symbols that don't appear in the order file. In addition, call graph profile described sections are now ordered before other sections.
2025-01-05[ELF] Internalize computeCacheDirectedSortOrder. NFCFangrui Song
and delete an incorremtn comment about ctx.arg.callGraphProfile
2024-11-06[ELF] Replace error(...) with ErrAlways or ErrFangrui Song
Most are migrated to ErrAlways mechanically. In the future we should change most to Err.
2024-10-11[ELF] Pass Ctx &Fangrui Song
2024-09-22[ELF] Replace remnant config-> with ctx.arg.Fangrui Song
2024-09-21[ELF] Replace config-> with ctx.arg.Fangrui Song
2023-11-08[ELF] Fix assertion in cdsort (#71708)spupyrev
It seems that some functions (.text.unlikely.xxx) may have zero size, which makes some builds with enabled assertions fail. Removing the assertion and extending one test to fix the build. The sorting can process such zero-sized functions so no changes there are needed
2023-09-26[ELF] A new code layout algorithm for function reordering [3a/3]spupyrev
We are brining a new algorithm for function layout (reordering) based on the call graph (extracted from a profile data). The algorithm is an improvement of top of a known heuristic, C^3. It tries to co-locate hot and frequently executed together functions in the resulting ordering. Unlike C^3, it explores a larger search space and have an objective closely tied to the performance of instruction and i-TLB caches. Hence, the name CDS = Cache-Directed Sort. The algorithm can be used at the linking or post-linking (e.g., BOLT) stage. Refer to https://reviews.llvm.org/D152834 for the actual implementation of the reordering algorithm. This diff adds a linker option to replace the existing C^3 heuristic with CDS. The new behavior can be turned on by passing "--use-cache-directed-sort". (the plan is to make it default in a next diff) **Perf-impact** clang-10 binary (built with LTO+AutoFDO/CSSPGO): wins on top of C^3 in [0.3%..0.8%] rocksDB-8 binary (built with LTO+CSSPGO): wins on top of C^3 in [0.8%..1.5%] Note that function layout affects the perf the most on older machines (with smaller instruction/iTLB caches) and when huge pages are not enabled. The impact on newer processors with huge pages enabled is likely neutral/minor. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D152840
2022-07-29[ELF] CallGraphSort: replace vector<int> with unique_ptr<int[]>. NFCFangrui Song
We can't use C++20 make_unique_for_overwrite yet.
2022-02-23[ELF] Don't rely on Symbols.h's transitive inclusion of InputFiles.h. NFCFangrui Song
2022-02-07[ELF] Clean up headers. NFCFangrui Song
2021-12-24[ELF] Avoid referencing SectionBase::repl after ICFFangrui Song
It is fairly easy to forget SectionBase::repl after ICF. Let ICF rewrite a Defined symbol's `section` field to avoid references to SectionBase::repl in subsequent passes. This slightly improves the --icf=none performance due to less indirection (maybe for --icf={safe,all} as well if most symbols are Defined). With this change, there is only one reference to `repl` (--gdb-index D89751). We can undo f4fb5fd7523f8e3c3b3966d43c0a28457b59d1d8 (`Move Repl to SectionBase.`) but move `repl` to `InputSection` instead. Reviewed By: ikudrin Differential Revision: https://reviews.llvm.org/D116093
2021-10-25[ELF] Update comments/diagnostics for some long options to use the canonical ↵Fangrui Song
two-dash form Rewrite some comments as appropriate.
2020-07-30[COFF] Port CallGraphSort to COFF from ELFZequan Wu
2020-05-15[ELF] Use namespace qualifiers (lld:: or elf::) instead of `namespace lld { ↵Fangrui Song
namespace elf {` Similar to D74882. This reverts much code from commit bd8cfe65f5fee4ad573adc2172359c9552e8cdc0 (D68323) and fixes some problems before D68323. Sorry for the churn but D68323 was a mistake. Namespace qualifiers avoid bugs where the definition does not match the declaration from the header. See https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions (D74515) Differential Revision: https://reviews.llvm.org/D79982
2020-04-02[lld] NFC: fix trivial typos in commentsKazuaki Ishizaki
Differential Revision: https://reviews.llvm.org/D72339
2019-10-28Fix a few typos in lld/ELF to cycle botsNico Weber
2019-10-07[ELF] Wrap things in `namespace lld { namespace elf {`, NFCFangrui Song
This makes it clear `ELF/**/*.cpp` files define things in the `lld::elf` namespace and simplifies `elf::foo` to `foo`. Reviewed By: atanasyan, grimar, ruiu Differential Revision: https://reviews.llvm.org/D68323 llvm-svn: 373885
2019-10-04[ELF] Use union-find set and doubly linked list in Call-Chain Clustering ↵Fangrui Song
(C³) heuristic Before, SecToClusters[*] was used to track the belonged cluster. During a merge (From -> Into), every element of From has to be updated. Use a union-find set to speed up this use case. Also, replace `std::vector<int> Sections;` with a doubly-linked pointers: int Next, Prev; Reviewed By: Bigcheese Differential Revision: https://reviews.llvm.org/D46228 llvm-svn: 373708
2019-08-05Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFCFangrui Song
F_{None,Text,Append} are kept for compatibility since r334221. llvm-svn: 367800
2019-07-16[ELF] Fix variable names in comments after VariableName -> variableName changeFangrui Song
Also fix some typos. llvm-svn: 366181
2019-07-10[Coding style change] Rename variables so that they start with a lowercase ↵Rui Ueyama
letter This patch is mechanically generated by clang-llvm-rename tool that I wrote using Clang Refactoring Engine just for creating this patch. You can see the source code of the tool at https://reviews.llvm.org/D64123. There's no manual post-processing; you can generate the same patch by re-running the tool against lld's code base. Here is the main discussion thread to change the LLVM coding style: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html In the discussion thread, I proposed we use lld as a testbed for variable naming scheme change, and this patch does that. I chose to rename variables so that they are in camelCase, just because that is a minimal change to make variables to start with a lowercase letter. Note to downstream patch maintainers: if you are maintaining a downstream lld repo, just rebasing ahead of this commit would cause massive merge conflicts because this patch essentially changes every line in the lld subdirectory. But there's a remedy. clang-llvm-rename tool is a batch tool, so you can rename variables in your downstream repo with the tool. Given that, here is how to rebase your repo to a commit after the mass renaming: 1. rebase to the commit just before the mass variable renaming, 2. apply the tool to your downstream repo to mass-rename variables locally, and 3. rebase again to the head. Most changes made by the tool should be identical for a downstream repo and for the head, so at the step 3, almost all changes should be merged and disappear. I'd expect that there would be some lines that you need to merge by hand, but that shouldn't be too many. Differential Revision: https://reviews.llvm.org/D64121 llvm-svn: 365595
2019-04-23Use llvm::stable_sortFangrui Song
Make some small adjustment while touching the code: make parameters const, use less_first(), etc. Differential Revision: https://reviews.llvm.org/D60989 llvm-svn: 358943
2019-04-01Replace `typedef A B` with `using B = A`. NFC.Rui Ueyama
I did this using Perl. Differential Revision: https://reviews.llvm.org/D60003 llvm-svn: 357372
2019-03-27[ELF] Dump symbols ordered by profiled guided section layout to file.Rui Ueyama
Patch by Tiancong Wang. In D36351, Call-Chain Clustering (C3) heuristic is implemented with option --call-graph-ordering-file <file>. This patch adds a flag --print-symbol-order=<file> to LLD, and when specified, it prints out the symbols ordered by the heuristics to the file. The symbols printout is helpful to those who want to understand the heuristics and want to reproduce the ordering with --symbol-ordering-file in later pass. Differential Revision: https://reviews.llvm.org/D59311 llvm-svn: 357133
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-10-12Simplify. NFC.Rui Ueyama
- Removed redundant `llvm::` - Typedef a long type name - Initialize members by member initializers llvm-svn: 344427
2018-08-28[LLD][ELF] - Simplify Call-Chain Clustering implementation a bit.George Rimar
Looking at the current implementation and algorithm description, it does not seem we need to keep vector with all edges for each cluster and can just remember the best one. This is NFC change. Differential revision: https://reviews.llvm.org/D50609 llvm-svn: 340806
2018-08-12[LLF][ELF] - Simplify. NFC.George Rimar
llvm-svn: 339510
2018-04-24[ELF] - Never use std::sort.George Rimar
It turns out we should not use the std::sort anymore. r327219 added a new wrapper llvm::sort (D39245). When EXPENSIVE_CHECKS is defined, it shuffles the input container and that helps to find non-deterministic ordering. Patch changes code to use llvm::sort and std::stable_sort instead of std::sort Differential revision: https://reviews.llvm.org/D45969 llvm-svn: 330702
2018-04-23[ELF] - Simplify. NFC.George Rimar
llvm-svn: 330597
2018-04-17[ELF] Add profile guided section layoutMichael J. Spencer
This adds profile guided layout using the Call-Chain Clustering (C³) heuristic from https://research.fb.com/wp-content/uploads/2017/01/cgo2017-hfsort-final1.pdf . RFC: [llvm-dev] [RFC] Profile guided section layout http://lists.llvm.org/pipermail/llvm-dev/2017-June/114178.html Pass `--call-graph-ordering-file <file>` to read a call graph profile where each line has the format: <from symbol> <to symbol> <call count> Differential Revision: https://reviews.llvm.org/D36351 llvm-svn: 330234