summaryrefslogtreecommitdiff
path: root/bolt/lib/Profile/DataReader.cpp
AgeCommit message (Collapse)Author
2025-10-20[BOLT][NFC] Use brstack in guides and user outputs (#163950)Paschalis Mpeis
Update guides to use brstack, with a mention to BRBE for AArch64. Use brstack in user-facing outputs. --------- Co-authored-by: Amir Ayupov <aaupov@fb.com>
2025-10-14[bolt] Fix typos discovered by codespell (#124726)Christian Clauss
https://github.com/codespell-project/codespell ```bash codespell bolt --skip="*.yaml,Maintainers.txt" --write-changes \ --ignore-words-list=acount,alledges,ans,archtype,defin,iself,mis,mmaped,othere,outweight,vas ```
2025-06-10[BOLT] Expose external entry count for functions (#141674)Amir Ayupov
Record the number of function invocations from external code - code outside the binary, which may include JIT code and DSOs. Accounting external entry counts improves the fidelity of call graph flow conservation analysis. Test Plan: updated shrinkwrapping.test
2025-05-17[BOLT] Avoid repeated hash lookups (NFC) (#140426)Kazu Hirata
We can use try_emplace to succinctly implement GetOrCreateFuncEntry and GetOrCreateFuncMemEntry. Since it's a bit mouthful to say FuncBasicSampleData::ContainerTy(), this patch changes the second parameters to default ones.
2025-05-12[BOLT][NFC] Disambiguate sample as basic sample (#139350)Amir Ayupov
Sample is a general term covering both basic (IP) and branch (LBR) profiles. Find and replace ambiguous uses of sample in a basic sample sense. Rename `RawBranchCount` into `RawSampleCount` reflecting its use for both kinds of profile. Rename `PF_LBR` profile type as `PF_BRANCH` reflecting non-LBR based branch profiles (non-brstack SPE, synthesized brstack ETM/PT). Follow-up to #137644. Test Plan: NFC
2025-05-10[BOLT] Use StringRef::consume_front (NFC) (#139432)Kazu Hirata
2025-05-10[BOLT] Support profile density with basic samples (#137644)Amir Ayupov
For profile with LBR samples, binary function profile density is computed as a ratio of executed bytes to function size in bytes. For profile with IP samples, use the size of basic block containing the sample IP as a numerator. Test Plan: updated perf_test.test
2024-05-22[BOLT][NFC] Make estimateEdgeCounts a BinaryFunctionPass (#93074)Amir Ayupov
2024-05-13[BOLT] Allow pass-through blocks in YAMLProfileReader (#91828)Amir Ayupov
2024-05-12Use StringRef::operator== instead of StringRef::equals (NFC) (#91864)Kazu Hirata
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 276 under llvm-project/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-03-31[BOLT][NFC] Clean includes, add license headers (#87200)Amir Ayupov
2023-12-13[BOLT] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-11-13[BOLT] Make instruction size a first-class annotation (#72167)Maksim Panchenko
When NOP instructions are used to reserve space in the code, e.g. for patching, it becomes critical to preserve their original size while emitting the code. On x86, we rely on "Size" annotation for NOP instructions size, as the original instruction size is lost in the disassembly/assembly process. This change makes instruction size a first-class annotation and is affectively NFCI. A follow-up diff will use the annotation for code emission.
2023-09-11[BOLT][NFC] Use formatv in DataAggregator/DataReader printsAmir Ayupov
Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D154120
2023-05-17[BOLT][NFC] Use llvm::make_rangeAmir Ayupov
Use `llvm::make_range` convenience wrapper from ADT. Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D145887
2023-03-03[BOLT] Remove dependency on StringMap iteration orderMaksim Panchenko
Remove the usage of StringMap in places where the iteration order affects the output since the iteration over StringMap is non-deterministic. Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D145194
2023-01-20[BOLT][NFC] Move getLTOCommonName to UtilsAmir Ayupov
Reuse getLTOCommonName in components other than Profile (to be used in Core) Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D142259
2023-01-20[BOLT] Handle __uniq suffix added by -funique-internal-linkage-namesAmir Ayupov
In profile matching, if `.__uniq` suffix added for internal linkage symbols with `-funique-internal-linkage-names` prevents BOLT from matching to a binary function, try to strip the suffix and perform fuzzy name matching. Follow-up to D124117. Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D142073
2023-01-03[BOLT][NFC] Use llvm::reverseAmir Ayupov
Use llvm::reverse instead of `for (auto I = rbegin(), E = rend(); I != E; ++I)` Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D140516
2023-01-03[BOLT] Check no-LBR samples in mayHaveProfileDataAmir Ayupov
No-LBR mode wasn't tested and slipped when mayHaveProfileData was added for Lite mode. This enables processing of profiles collected without LBR and converted with `perf2bolt -nl` option. Test Plan: bin/llvm-lit -a tools/bolt/test/X86/nolbr.s https://github.com/rafaelauler/bolt-tests/pull/20 Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D140256
2022-12-11[BOLT][NFC] Use std::optional for getLTOCommonNameAmir Ayupov
2022-12-02[BOLT] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-20Use None consistently (NFC)Kazu Hirata
This patch replaces NoneType() and NoneType::None with None in preparation for migration from llvm::Optional to std::optional. In the std::optional world, we are not guranteed to be able to default-construct std::nullopt_t or peek what's inside it, so neither NoneType() nor NoneType::None has a corresponding expression in the std::optional world. Once we consistently use None, we should even be able to replace the contents of llvm/include/llvm/ADT/None.h with something like: using NoneType = std::nullopt_t; inline constexpr std::nullopt_t None = std::nullopt; to ease the migration from llvm::Optional to std::optional. Differential Revision: https://reviews.llvm.org/D138376
2022-08-24[BOLT] Towards FunctionLayout const-correctnessFabian Parzefall
A const-qualified reference to function layout allows accessing non-const qualified basic blocks on a const-qualified function. This patch adds or removes const-qualifiers where necessary to indicate where basic blocks are used in a non-const manner. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D132049
2022-08-24Revert "[BOLT] Towards FunctionLayout const-correctness"Fabian Parzefall
This reverts commit 587d2653420d75ef10f30bd612d86f1e08fe9ea7.
2022-08-24[BOLT] Towards FunctionLayout const-correctnessFabian Parzefall
A const-qualified reference to function layout allows accessing non-const qualified basic blocks on a const-qualified function. This patch adds or removes const-qualifiers where necessary to indicate where basic blocks are used in a non-const manner. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D132049
2022-07-31[BOLT] Use boolean literals (NFC)Kazu Hirata
Identified with modernize-use-bool-literals.
2022-07-16[BOLT] Add function layout classFabian Parzefall
This patch adds a dedicated class to keep track of each function's layout. It also lays the groundwork for splitting functions into multiple fragments (as opposed to a strict hot/cold split). Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D129518
2022-06-23[BOLT][NFC] Use range-based STL wrappersAmir Ayupov
Replace `std::` algorithms taking begin/end iterators with `llvm::` counterparts accepting ranges. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D128154
2022-05-13[BOLT][NFC] Use refs for loop variables to avoid copiesAmir Ayupov
Addresses warnings when built with Apple Clang. Reviewed By: yota9 Differential Revision: https://reviews.llvm.org/D125483
2022-05-03[BOLT] [NFC] Remove unused variablePaul Kirth
This patch fixes a warning from -Wunused-but-set-variable MismatchedBranches are counted, but are never reported. Since evaluateProfileData() should already identify and report these cases, we can safely remove the unused variable. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D124588
2022-04-20[BOLT] Add fuzzy function name matching for LLVM LTOMaksim Panchenko
LLVM with LTO can generate function names in the form func.llvm.<number>, where <number> could vary based on the compilation environment. As a result, if a profiled binary originated from a different build than a corresponding binary used for BOLT optimization, then profiles for such LTO functions will be ignored. To fix the problem, use "fuzzy" matching with "func.llvm.*" form. Reviewed By: yota9, Amir Differential Revision: https://reviews.llvm.org/D124117
2022-02-15Cleanup LLVMDWARFDebugInfoserge-sans-paille
As usual with that header cleanup series, some implicit dependencies now need to be explicit: llvm/DebugInfo/DWARF/DWARFContext.h no longer includes: - "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" - "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" - "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" - "llvm/DebugInfo/DWARF/DWARFDebugAranges.h" - "llvm/DebugInfo/DWARF/DWARFDebugFrame.h" - "llvm/DebugInfo/DWARF/DWARFDebugLoc.h" - "llvm/DebugInfo/DWARF/DWARFDebugMacro.h" - "llvm/DebugInfo/DWARF/DWARFGdbIndex.h" - "llvm/DebugInfo/DWARF/DWARFSection.h" - "llvm/DebugInfo/DWARF/DWARFTypeUnit.h" - "llvm/DebugInfo/DWARF/DWARFUnitIndex.h" Plus llvm/Support/Errc.h not included by a bunch of llvm/DebugInfo/DWARF/DWARF*.h files Preprocessed lines to build llvm on my setup: after: 1065629059 before: 1066621848 Which is a great diff! Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119723
2022-01-18[BOLT][NFC] Move Offset annotation to Group 1Amir Ayupov
Summary: Move the annotation to avoid dynamic memory allocations. Improves the CPU time of instrumenting a large binary by 1% (+-0.8%, p-value 0.01) Test Plan: NFC Reviewers: maksfb FBD30091656
2021-12-28[BOLT][NFC] Fix braces usage in ProfileAmir Ayupov
Summary: Refactor bolt/*/Profile to follow the braces rule for if/else/loop from [LLVM Coding Standards](https://llvm.org/docs/CodingStandards.html). (cherry picked from FBD33345741)
2021-12-21[BOLT][NFC] Fix file-description commentsMaksim Panchenko
Summary: Fix comments at the start of source files. (cherry picked from FBD33274597)
2021-12-02[BOLT][NFC] Remove another unused functionMaksim Panchenko
Summary: Remove DataReader::getBranchRange(). (cherry picked from FBD32810933)
2021-12-18[BOLT] Fix profile and tests for nop-removal passMaksim Panchenko
Summary: Since nops are now removed in a separate pass, the profile is consumed on a CFG with nops. If previously a profile was generated without nops, the offsets in the profile could be different if branches included nops either as a source or a destination. This diff adjust offsets to make the profile reading backwards compatible. (cherry picked from FBD33231254)
2021-12-18[BOLT] Move disassemble optimizations to optimization passesVladislav Khmelevsky
Summary: The patch moves the shortenInstructions and nop remove to separate binary passes. As a result when llvm-bolt optimizations stage will begin the instructions of the binary functions will be absolutely the same as it was in the binary. This is needed for the golang support by llvm-bolt. Some of the tests must be changed, since bb alignment nops might create unreachable BBs in original functions. Vladislav Khmelevsky, Advanced Software Technology Lab, Huawei (cherry picked from FBD32896517)
2021-12-14[BOLT][NFC] Reformat with clang-formatMaksim Panchenko
Summary: Selectively apply clang-format to BOLT code base. (cherry picked from FBD33119052)
2021-10-08Rebase: [NFC] Refactor sources to be buildable in shared modeRafael Auler
Summary: Moves source files into separate components, and make explicit component dependency on each other, so LLVM build system knows how to build BOLT in BUILD_SHARED_LIBS=ON. Please use the -c merge.renamelimit=230 git option when rebasing your work on top of this change. To achieve this, we create a new library to hold core IR files (most classes beginning with Binary in their names), a new library to hold Utils, some command line options shared across both RewriteInstance and core IR files, a new library called Rewrite to hold most classes concerned with running top-level functions coordinating the binary rewriting process, and a new library called Profile to hold classes dealing with profile reading and writing. To remove the dependency from BinaryContext into X86-specific classes, we do some refactoring on the BinaryContext constructor to receive a reference to the specific backend directly from RewriteInstance. Then, the dependency on X86 or AArch64-specific classes is transfered to the Rewrite library. We can't have the Core library depend on targets because targets depend on Core (which would create a cycle). Files implementing the entry point of a tool are transferred to the tools/ folder. All header files are transferred to the include/ folder. The src/ folder was renamed to lib/. (cherry picked from FBD32746834)