summaryrefslogtreecommitdiff
path: root/bolt/lib/Passes/FrameAnalysis.cpp
AgeCommit message (Collapse)Author
2025-10-14[BOLT][NFC] Fix for a dangling reference UB (#163344)Slava Gurevich
Fix UB caused by accessing the top element of the stack via a dangling reference after a call to .pop() This is tripping static analysis. No functional changes. Performance impact is negligible, but alt. implementation of the fix is possible if needed. Testing: Both functional and unit tests are passing.
2025-05-17[BOLT] Remove unused local variables (NFC) (#140421)Kazu Hirata
While I'm at it, this patch removes GetExecutablePath, which becomes unused after removing the sole use.
2024-06-27[BOLT][NFC] Move CallGraph from Passes to Core (#96922)shaw young
Moved CallGraph and BinaryFunctionCallGraph from Passes to Core for future use in stale matching.
2024-05-08[NFC][BOLT] Remove dead code (SPTAllocatorsId) (#91477)Kristof Beyls
It seems that SPTAllocatorsId is no longer used in FrameAnalysis, so let's remove it. It seems the use of SPTAllocatorsId was removed back in 2019, in commit cc8415406c7.
2024-02-12[BOLT][NFC] Log through JournalingStreams (#81524)Amir Ayupov
Make core BOLT functionality more friendly to being used as a library instead of in our standalone driver llvm-bolt. To accomplish this, we augment BinaryContext with journaling streams that are to be used by most BOLT code whenever something needs to be logged to the screen. Users of the library can decide if logs should be printed to a file, no file or to the screen, as before. To illustrate this, this patch adds a new option `--log-file` that allows the user to redirect BOLT logging to a file on disk or completely hide it by using `--log-file=/dev/null`. Future BOLT code should now use `BinaryContext::outs()` for printing important messages instead of `llvm::outs()`. A new test log.test enforces this by verifying that no strings are print to screen once the `--log-file` option is used. In previous patches we also added a new BOLTError class to report common and fatal errors, so code shouldn't call exit(1) now. To easily handle problems as before (by quitting with exit(1)), callers can now use `BinaryContext::logBOLTErrorsAndQuitOnFatal(Error)` whenever code needs to deal with BOLT errors. To test this, we have fatal.s that checks we are correctly quitting and printing a fatal error to the screen. Because this is a significant change by itself, not all code was yet ported. Code from Profiler libs (DataAggregator and friends) still print errors directly to screen. Co-authored-by: Rafael Auler <rafaelauler@fb.com> Test Plan: NFC
2023-03-14[BOLT][NFC] Use llvm::is_containedAmir Ayupov
Apply the replacement throughout BOLT. Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D145464
2022-08-27[BOLT][NFC] Use llvm::any_ofAmir Ayupov
Replace the imperative pattern of the following kind ``` bool IsTrue = false; for (Element : Range) { if (Condition(Element)) { IsTrue = true; break; } } ``` with functional style `llvm::any_of`: ``` bool IsTrue = llvm::any_of(Range, [&](Element) { return Condition(Element); }); ``` Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D132276
2022-08-09LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song
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-07-11[BOLT] Increase coverage of shrink wrapping [5/5]Rafael Auler
Add -experimental-shrink-wrapping flag to control when we want to move callee-saved registers even when addresses of the stack frame are captured and used in pointer arithmetic, making it more challenging to do alias analysis to prove that we do not access optimized stack positions. This alias analysis is not yet implemented, hence, it is experimental. In practice, though, no compiler would emit code to do pointer arithmetic to access a saved callee-saved register unless there is a memory bug or we are failing to identify a callee-saved reg, so I'm not sure how useful it would be to formally prove that. Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D126115
2022-07-11[BOLT] Increase coverage of shrink wrapping [1/5]Rafael Auler
Change how function score is calculated and provide more detailed statistics when reporting back frame optimizer and shrink wrapping results. In this new statistics, we provide dynamic coverage numbers. The main metric for shrink wrapping is the number of executed stores that were saved because of shrink wrapping (push instructions that were either entirely moved away from the hot block or converted to a stack adjustment instruction). There is still a number of reduced load instructions (pop) that we are not counting at the moment. Also update alloc combiner to report dynamic numbers, as well as frame optimizer. For debugging purposes, we also include a list of top 10 functions optimized by shrink wrapping. These changes are aimed at better understanding the impact of shrink wrapping in a given binary. We also remove an assertion in dataflow analysis to do not choke on empty functions (which makes no sense). Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D126111
2022-06-05[bolt] Remove unneeded cl::ZeroOrMore for cl::opt optionsFangrui Song
2022-02-09Add missing MC includes in bolt/serge-sans-paille
Changes needed after ef736a1c39f27ef4 that removes some implicit dependencies from MrCV headers.
2021-12-28[BOLT][NFC] Fix braces usage in PassesAmir Ayupov
Summary: Refactor bolt/*/Passes to follow the braces rule for if/else/loop from [LLVM Coding Standards](https://llvm.org/docs/CodingStandards.html). (cherry picked from FBD33344642)
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-14[BOLT][NFC] Reformat with clang-formatMaksim Panchenko
Summary: Selectively apply clang-format to BOLT code base. (cherry picked from FBD33119052)
2021-10-26[BOLT][NFC] Do not pass BinaryContext alongside BinaryFunctionMaksim Panchenko
Summary: BinaryContext is available via BinaryFunction::getBinaryContext(), hence there's no reason to pass both as arguments to a function. In a similar fashion, BinaryBasicBlock has an access to BinaryFunction via getFunction(). Eliminate unneeded arguments. (cherry picked from FBD31921680)
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)