aboutsummaryrefslogtreecommitdiff
path: root/bolt/tools
AgeCommit message (Collapse)AuthorFilesLines
2024-03-31[BOLT][NFC] Clean includes, add license headers (#87200)Amir Ayupov2-5/+18
2024-03-05Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (#83702)Mehdi Amini1-1/+1
The base class llvm::ThreadPoolInterface will be renamed llvm::ThreadPool in a subsequent commit. This is a breaking change: clients who use to create a ThreadPool must now create a DefaultThreadPool instead.
2024-02-19Rename `ThreadPool::getThreadCount()` to `getMaxConcurrency()` (NFC) (#82296)Mehdi Amini1-1/+2
This is addressing a long-time TODO to rename this misleading API. The old one is preserved for now but marked deprecated.
2024-02-12[BOLT][NFC] Log through JournalingStreams (#81524)Amir Ayupov2-2/+26
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
2024-01-18[BOLT] Fix unconditional output of boltedcollection in merge-fdata (#78653)Amir Ayupov1-1/+1
Fix the bug where merge-fdata unconditionally outputs boltedcollection line, regardless of whether input files have it set. Test Plan: Added bolt/test/X86/merge-fdata-nobat-mode.test which fails without this fix.
2024-01-18Revert "[BOLT] Fix unconditional output of boltedcollection in merge-fdata ↵Amir Ayupov1-1/+1
(#78653)" This reverts commit 82bc33ea3f1a539be50ed46919dc53fc6b685da9. Accidentally pushed unrelated changes.
2024-01-18[BOLT] Fix unconditional output of boltedcollection in merge-fdata (#78653)Amir Ayupov1-1/+1
Fix the bug where merge-fdata unconditionally outputs boltedcollection line, regardless of whether input files have it set. Test Plan: Added bolt/test/X86/merge-fdata-nobat-mode.test which fails without this fix.
2024-01-15[BOLT] Use SmallString::operator std::string (NFC)Kazu Hirata3-3/+3
2023-12-13[BOLT] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata1-2/+2
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-06-01[BOLT][CMake] Redo the build and install targetsPetr Hosek5-38/+4
The existing BOLT install targets are broken on Windows becase they don't properly handle the output extension. We cannot use the existing LLVM macros since those make assumptions that don't hold for BOLT. This change instead implements custom macros following the approach used by Clang and LLD. Differential Revision: https://reviews.llvm.org/D151595
2023-06-01Revert "[BOLT][CMake] Redo the build and install targets"Petr Hosek5-4/+38
This reverts commit f99a7d3e38095cfdaf7e729289a8894dd31c7efa since it broke the bolt-aarch64-ubuntu-clang-shared bot.
2023-06-01[BOLT][CMake] Redo the build and install targetsPetr Hosek5-38/+4
The existing BOLT install targets are broken on Windows becase they don't properly handle the output extension. We cannot use the existing LLVM macros since those make assumptions that don't hold for BOLT. This change instead implements custom macros following the approach used by Clang and LLD. Differential Revision: https://reviews.llvm.org/D151595
2023-05-30Revert "[BOLT][CMake] Use LLVM macros for install targets"Petr Hosek3-8/+14
This reverts commit 627d5e16127bd8034b893e66ab0c86eacf2d939a.
2023-05-30[BOLT][CMake] Use LLVM macros for install targetsPetr Hosek3-14/+8
The existing BOLT install targets are broken on Windows becase they don't properly handle output extension. Rather than reimplementing this logic in BOLT, reuse the existing LLVM macros which already handle this aspect correctly. Differential Revision: https://reviews.llvm.org/D151595
2023-05-22Reland^2 "[BOLT] Parallelize legacy profile merging"Yi Kong1-22/+51
Resovled the issue that when number of tasks is fewer than cores, we end up creating as many threads as the number of cores, making the performance worse than the single thread version.
2023-05-18Revert "Reland "[BOLT] Parallelize legacy profile merging""Yi Kong1-49/+22
This reverts commit 611fb179b19857ffb87df81c926902fc7e3412ab. Broken tests
2023-05-18Reland "[BOLT] Parallelize legacy profile merging"Yi Kong1-22/+49
This reverts commit 78d8d016490909ac759c6f76c5f8679bc7a58b2e.
2023-04-28Revert "[BOLT] Parallelize legacy profile merging"Yi Kong1-47/+22
This reverts commit 35af20d9e036deeed250b73fd3ae86d6455173c5. The patch caused a test failure.
2023-04-27[BOLT] Parallelize legacy profile mergingYi Kong1-22/+47
Merging profiles is quite expensive, but easily paralleizable. 8359 profiles on n2d-standard-128: single-thread: 808s multi-thread: 200s (~75% speed up) Differential Revision: https://reviews.llvm.org/D149014
2023-04-01[BOLT][NFC] Simplify code using std::optionalYi Kong1-5/+4
Use std::optional instead of tracking if it is the first profile seen. Differential Revision: https://reviews.llvm.org/D147308
2023-02-02[BOLT][NFC] Rename {MachO,}RewriteInstance::create methodsAmir Ayupov3-12/+6
Follow the code style of fallible constructors in [LLVM Programmer's Manual] (https://llvm.org/docs/ProgrammersManual.html#fallible-constructors) and rename `RewriteInstance::createRewriteInstance` to `RewriteInstance::create` Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D143119
2023-02-02[BOLT][NFC] Use llvm::make_second_rangeAmir Ayupov1-3/+3
Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D143019
2023-01-10Move from llvm::makeArrayRef to ArrayRef deduction guides - last partserge-sans-paille3-5/+5
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141298
2023-01-03[BOLT][CMake] Add merge-fdata to bolt componentAmir Ayupov1-0/+7
Build and install `merge-fdata` tool as part of `bolt` component: ``` $ ninja bolt # builds llvm-bolt, perf2bolt and merge-fdata $ cmake --install . --component bolt --prefix $HOME/test-install-bolt -- Install configuration: "Release" -- Install configuration: "Release" -- Installing: /home/aaupov/test-install-bolt/lib/libbolt_rt_instr.a -- Installing: /home/aaupov/test-install-bolt/lib/libbolt_rt_hugify.a -- Installing: /home/aaupov/test-install-bolt/lib/libbolt_rt_instr_osx.a -- Installing: /home/aaupov/test-install-bolt/bin/llvm-bolt -- Installing: /home/aaupov/test-install-bolt/bin/perf2bolt -- Installing: /home/aaupov/test-install-bolt/bin/llvm-boltdiff -- Installing: /home/aaupov/test-install-bolt/bin/merge-fdata ``` Fixes #57249. Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D139972
2022-09-23[BOLT] Support building bolt when LLVM_LINK_LLVM_DYLIB is ONserge-sans-paille5-0/+9
This does *not* link with libLLVM, but with static archives instead. Not super-great, but at least the build works, which is probably better than failing. Related to #57551 Differential Revision: https://reviews.llvm.org/D134434
2022-09-22[BOLT] Fix (part of) dylib compatibilityserge-sans-paille1-1/+4
Non-LLVM components should not be listed as part of LLVM_LINK_COMPONENTS. Differential Revision: https://reviews.llvm.org/D134278
2022-09-22Revert "[bolt] Fix (part of) dylib compatibility"serge-sans-paille1-0/+1
This reverts commit 34ad83d883cc4505412a7c3e1e3da74e5408aa82.
2022-09-22[bolt] Fix (part of) dylib compatibilityserge-sans-paille1-1/+0
Non-LLVM component should not be listed as part of LLVM_LINK_COMPONENTS Differential Revision: https://reviews.llvm.org/D134278
2022-08-02CommandLine: add and use cl::SubCommand::get{All,TopLevel}Nicolai Hähnle1-1/+1
Prefer using these accessors to access the special sub-commands corresponding to the top-level (no subcommand) and all sub-commands. This is a preparatory step towards removing the use of ManagedStatic: with a subsequent change, these global instances will be moved to be regular function-scope statics. It is split up to give downstream projects a (albeit short) window in which they can switch to using the accessors in a forward-compatible way. Differential Revision: https://reviews.llvm.org/D129118
2022-07-29Add BAT testing frameworkRafael Auler3-0/+191
This patch refactors BAT to be testable as a library, so we can have open-source tests on it. This further fixes an issue with basic blocks that lack a valid input offset, making BAT omit those when writing translation tables. Test Plan: new testcases added, new testing tool added (llvm-bat-dump) Differential Revision: https://reviews.llvm.org/D129382
2022-07-21[cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymoreJohn Ericson4-5/+19
First of all, `LLVM_TOOLS_INSTALL_DIR` put there breaks our NixOS builds, because `LLVM_TOOLS_INSTALL_DIR` defined the same as `CMAKE_INSTALL_BINDIR` becomes an *absolute* path, and then when downstream projects try to install there too this breaks because our builds always install to fresh directories for isolation's sake. Second of all, note that `LLVM_TOOLS_INSTALL_DIR` stands out against the other specially crafted `LLVM_CONFIG_*` variables substituted in `llvm/cmake/modules/LLVMConfig.cmake.in`. @beanz added it in d0e1c2a550ef348aae036d0fe78cab6f038c420c to fix a dangling reference in `AddLLVM`, but I am suspicious of how this variable doesn't follow the pattern. Those other ones are carefully made to be build-time vs install-time variables depending on which `LLVMConfig.cmake` is being generated, are carefully made relative as appropriate, etc. etc. For my NixOS use-case they are also fine because they are never used as downstream install variables, only for reading not writing. To avoid the problems I face, and restore symmetry, I deleted the exported and arranged to have many `${project}_TOOLS_INSTALL_DIR`s. `AddLLVM` now instead expects each project to define its own, and they do so based on `CMAKE_INSTALL_BINDIR`. `LLVMConfig` still exports `LLVM_TOOLS_BINARY_DIR` which is the location for the tools defined in the usual way, matching the other remaining exported variables. For the `AddLLVM` changes, I tried to copy the existing pattern of internal vs non-internal or for LLVM vs for downstream function/macro names, but it would good to confirm I did that correctly. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D117977
2022-06-23[BOLT][NFC] Use range-based STL wrappersAmir Ayupov1-8/+7
Replace `std::` algorithms taking begin/end iterators with `llvm::` counterparts accepting ranges. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D128154
2022-06-10Revert "[cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymore"John Ericson4-19/+5
This reverts commit d5daa5c5b091cafb9b7ffd19b5dfa2daadef3229.
2022-06-10[cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymoreJohn Ericson4-5/+19
First of all, `LLVM_TOOLS_INSTALL_DIR` put there breaks our NixOS builds, because `LLVM_TOOLS_INSTALL_DIR` defined the same as `CMAKE_INSTALL_BINDIR` becomes an *absolute* path, and then when downstream projects try to install there too this breaks because our builds always install to fresh directories for isolation's sake. Second of all, note that `LLVM_TOOLS_INSTALL_DIR` stands out against the other specially crafted `LLVM_CONFIG_*` variables substituted in `llvm/cmake/modules/LLVMConfig.cmake.in`. @beanz added it in d0e1c2a550ef348aae036d0fe78cab6f038c420c to fix a dangling reference in `AddLLVM`, but I am suspicious of how this variable doesn't follow the pattern. Those other ones are carefully made to be build-time vs install-time variables depending on which `LLVMConfig.cmake` is being generated, are carefully made relative as appropriate, etc. etc. For my NixOS use-case they are also fine because they are never used as downstream install variables, only for reading not writing. To avoid the problems I face, and restore symmetry, I deleted the exported and arranged to have many `${project}_TOOLS_INSTALL_DIR`s. `AddLLVM` now instead expects each project to define its own, and they do so based on `CMAKE_INSTALL_BINDIR`. `LLVMConfig` still exports `LLVM_TOOLS_BINARY_DIR` which is the location for the tools defined in the usual way, matching the other remaining exported variables. For the `AddLLVM` changes, I tried to copy the existing pattern of internal vs non-internal or for LLVM vs for downstream function/macro names, but it would good to confirm I did that correctly. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D117977
2022-06-02[BOLT] Add `-o` option to merge-fdataYi Kong1-3/+21
Differential Revision: https://reviews.llvm.org/D126788
2022-06-01[BOLT] Allow merge-fdata to take a directory as inputYi Kong1-4/+25
and recursively merge all files under said directory. This is similar to `llvm-profdata merge`. Differential Revision: https://reviews.llvm.org/D126695
2022-05-31[BOLT][NFC] Don't over-specify the size of SmallVectorYi Kong1-1/+1
This is the recommended way, should make merging profiles ever so slightly faster.
2022-05-13[BOLT] Fix merge-fdata handling of BAT profilesRafael Auler1-2/+3
When a profile is collected in a BOLTed binary, the generated profile is tagged with a header string "boltedcollection" in the first line of the fdata file. Fix merge-fdata to recognize this header string and preserve it into the output. Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D125591
2022-05-13[BOLT][CMAKE] Fix DYLIB buildAmir Ayupov2-6/+14
Move BOLT libraries out of `LLVM_LINK_COMPONENTS` to `target_link_libraries`. Addresses issue #55432. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D125568
2022-05-03[BOLT][CMAKE] Fix llvm-bolt-fuzzer buildAmir Ayupov1-0/+1
Add X86/AArch64 targets to resolve missing dependencies, e.g.: `undefined reference to `LLVMInitializeX86AsmParser'` Follow-up to D124206 Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D124886
2022-04-12[BOLT] Compact legacy profilesYi Kong1-1/+18
Merging multiple legacy profiles (produced by instrumentation BOLT) can easily reach GiBs. Let merge-fdata compact the profiles during merge to significantly reduce space usage. Differential Revision: https://reviews.llvm.org/D123513
2022-03-07[BOLT][CMAKE] Remove CMake 3.13.4 incompatible parameterAmir Ayupov1-1/+1
Remove `TYPE BIN` parameter that is introduced in CMake 3.14 and revert back to the equivalent compatible form `DESTINATION ${CMAKE_INSTALL_BINDIR}`. Addresses https://github.com/llvm/llvm-project/issues/54099 Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D121012
2022-02-23[BOLT][NFC] Report errors from RewriteInstance `discoverStorage` and `run`Amir Ayupov3-5/+10
Further improve error handling in BOLT by reporting `RewriteInstance` errors in a library and fuzzer-friendly way instead of exiting. Follow-up to D119658 Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D120224
2022-02-20[BOLT] Added fuzzer target (llvm-bolt-fuzzer)Amir Ayupov3-0/+78
This adds a target that would consume random binary as an input ELF file. TBD: add structured input support (ELF). Build: ``` cmake /path/to/llvm-project/llvm -GNinja \ -DLLVM_TARGETS_TO_BUILD="X86;AArch64" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_ASSERTIONS=1 \ -DCMAKE_C_COMPILER=<sanitizer-capable clang> \ -DCMAKE_CXX_COMPILER=<sanitizer-capable clang++> \ -DLLVM_ENABLE_PROJECTS="bolt" \ -DLLVM_USE_SANITIZER=Address \ -DLLVM_USE_SANITIZE_COVERAGE=On ninja llvm-bolt-fuzzer ``` Test Plan: ninja llvm-bolt-fuzzer Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D120016
2022-02-17[BOLT][NFC] Report errors from createBinaryContext and RewriteInstance ctorAmir Ayupov2-5/+26
Refactor createBinaryContext and RewriteInstance/MachORewriteInstance constructors to report an error in a library and fuzzer-friendly way instead of returning a nullptr or exiting. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D119658
2022-02-15Cleanup LLVMDWARFDebugInfoserge-sans-paille2-0/+2
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-02-07[BOLT] Refactor heatmap to be standalone toolVladislav Khmelevsky5-42/+115
Separate heatmap from bolt and build it as standalone tool. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D118946
2022-01-31[BOLT][CMAKE] Add extra BOLT_INCLUDE_TESTS condition for merge-fdata ↵Amir Ayupov1-1/+1
emit-relocs option Only enable --emit-relocs linker option for merge-fdata target if tests are enabled. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D118580
2022-01-27[BOLT] Prepare BOLT for unit-testingVladislav Khmelevsky1-0/+5
This patch adds unit testing support for BOLT. In order to do this we will need at least do this changes on the code level: * Make createMCPlusBuilder accessible externally * Remove positional InputFilename argument to bolt utlity sources And prepare the cmake and lit for the new tests. Vladislav Khmelevsky, Advanced Software Technology Lab, Huawei Reviewed By: maksfb, Amir Differential Revision: https://reviews.llvm.org/D118271
2021-12-28[BOLT][NFC] Fix braces usage in the rest of the codebaseAmir Ayupov1-35/+23
Summary: Refactor remaining bolt sources to follow the braces rule for if/else/loop from [LLVM Coding Standards](https://llvm.org/docs/CodingStandards.html). (cherry picked from FBD33345885)