aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
AgeCommit message (Collapse)AuthorFilesLines
17 hours[Support] Deprecate one form of support::endian::byte_swap (NFC) (#161045)Kazu Hirata1-6/+6
This is a follow-up to #156140 and #160979, which deprecated one form of write and read, respectively. We have two forms of byte_swap: template <typename value_type> [[nodiscard]] inline value_type byte_swap(value_type value, endianness endian) template <typename value_type, endianness endian> [[nodiscard]] inline value_type byte_swap(value_type value) The difference is that endian is a function parameter in the former but a template parameter in the latter. This patch streamlines the code by migrating the use of the latter to the former while deprecating the latter because the latter is just forwarded to the former.
2025-08-13[nfc][pgo] `const`-ify some APIs in `InstrProfSymtab` (#153284)Mircea Trofin1-1/+1
The main reason some `const` - sounding APIs weren't const was because their state is lazily updated (ensuring ordering).
2024-11-19[ProfileData] Remove unused includes (NFC) (#116751)Kazu Hirata1-2/+0
Identified with misc-include-cleaner.
2024-10-24Reland: [llvm-cov][WebAssembly] Read `__llvm_prf_names` from data segments ↵Yuta Saito1-18/+74
(#112569) On WebAssembly, most coverage metadata contents read by llvm-cov (like `__llvm_covmap` and `__llvm_covfun`) are stored in custom sections because they are not referenced at runtime. However, `__llvm_prf_names` is referenced at runtime by the profile runtime library and is read by llvm-cov post-processing tools, so it needs to be stored in a data segment, which is allocatable at runtime and accessible by tools as long as "name" section is present in the binary. This patch changes the way llvm-cov reads `__llvm_prf_names` on WebAssembly. Instead of looking for a section, it looks for a data segment with the same name. This reverts commit 157f10ddf2d851125a85a71e530dc9d50cb032a2 and fixes PE/COFF `.lprfn$A` section handling.
2024-10-16Revert "[llvm-cov][WebAssembly] Read `__llvm_prf_names` from data segments" ↵Yuta Saito1-55/+9
(#112520) This reverts commit efc9dd4118a7ada7d8c898582f16db64827f7ce0 in order to fix Windows test failure: https://github.com/llvm/llvm-project/pull/111332#issuecomment-2416462512
2024-10-15[Coverage][WebAssembly] Add initial support for WebAssembly/WASI (#111332)Yuta Saito1-15/+72
Currently, WebAssembly/WASI target does not provide direct support for code coverage. This patch set fixes several issues to unlock the feature. The main changes are: 1. Port `compiler-rt/lib/profile` to WebAssembly/WASI. 2. Adjust profile metadata sections for Wasm object file format. - [CodeGen] Emit `__llvm_covmap` and `__llvm_covfun` as custom sections instead of data segments. - [lld] Align the interval space of custom sections at link time. - [llvm-cov] Copy misaligned custom section data if the start address is not aligned. - [llvm-cov] Read `__llvm_prf_names` from data segments 3. [clang] Link with profile runtime libraries if requested See each commit message for more details and rationale. This is part of the effort to add code coverage support in Wasm target of Swift toolchain.
2024-09-13[Coverage] Skip empty profile name section (#108480)gulfemsavrun1-1/+3
llvm-cov reads __llvm_prf_names section in an object file to find the profile names, and it instead reads __llvm_covnames section in binary profile correlation mode when __llvm_prf_names section is omitted. This patch ensures that it still reads __llvm_covnames section when there is an empty __llvm_prf_names section.
2024-03-27[nfc]Make InstrProfSymtab non-copyable and non-movable (#86882)Mingming Liu1-16/+19
- The direct use case (in [1]) is to add `llvm::IntervalMap` [2] and the allocator required by IntervalMap ctor [3] to class `InstrProfSymtab` as owned members. The allocator class doesn't have a move-assignment operator; and it's going to take much effort to implement move-assignment operator for the allocator class such that the enclosing class is movable. - There is only one use of compiler-generated move-assignment operator in the repo, which is in CoverageMappingReader.cpp. Luckily it's possible to use std::unique_ptr<InstrProfSymtab> instead, so did the change. [1] https://github.com/llvm/llvm-project/pull/66825 [2] https://github.com/llvm/llvm-project/blob/4c2f68840e984b0f111779c46845ac00e3a7547d/llvm/include/llvm/ADT/IntervalMap.h#L936 [3] https://github.com/llvm/llvm-project/blob/4c2f68840e984b0f111779c46845ac00e3a7547d/llvm/include/llvm/ADT/IntervalMap.h#L1041
2024-02-15[MC/DC] Refactor: Let MCDCConditionID int16_t with zero-origin (#81257)NAKAMURA Takumi1-9/+12
Also, Let `NumConditions` `uint16_t`. It is smarter to handle the ID as signed. Narrowing to `int16_t` will reduce costs of handling byvalue. (See also #81221 and #81227) External behavior doesn't change. They below handle values as internal values plus 1. * `-dump-coverage-mapping` * `CoverageMappingReader.cpp` * `CoverageMappingWriter.cpp`
2024-02-14[MC/DC] Refactor: Introduce `ConditionIDs` as `std::array<2>` (#81221)NAKAMURA Takumi1-3/+3
Its 0th element corresponds to `FalseID` and 1st to `TrueID`. CoverageMappingGen.cpp: `DecisionIDPair` is replaced with `ConditionIDs`
2024-02-13[MC/DC] Refactor: Make `MCDCParams` as `std::variant` (#81227)NAKAMURA Takumi1-7/+9
Introduce `mcdc::DecisionParameters` and `mcdc::BranchParameters` and make sure them not initialized as zero. FIXME: Could we make `CoverageMappingRegion` as a smart tagged union?
2024-02-13CoverageMappingReader/Writer: MCDCConditionID shouldn't be zeroNAKAMURA Takumi1-0/+4
2024-02-13[MC/DC] Refactor: Introduce `MCDCTypes.h` for `coverage::mcdc` (#81459)NAKAMURA Takumi1-4/+3
They can be also used in `clang`. Introduce the lightweight header instead of `CoverageMapping.h`. This includes for now: * `mcdc::ConditionID` * `mcdc::Parameters`
2023-12-14[Profile] Add binary profile correlation for code coverage. (#69493)Zequan Wu1-26/+39
## Motivation Since we don't need the metadata sections at runtime, we can somehow offload them from memory at runtime. Initially, I explored [debug info correlation](https://discourse.llvm.org/t/instrprofiling-lightweight-instrumentation/59113), which is used for PGO with value profiling disabled. However, it currently only works with DWARF and it's be hard to add such artificial debug info for every function in to CodeView which is used on Windows. So, offloading profile metadata sections at runtime seems to be a platform independent option. ## Design The idea is to use new section names for profile name and data sections and mark them as metadata sections. Under this mode, the new sections are non-SHF_ALLOC in ELF. So, they are not loaded into memory at runtime and can be stripped away as a post-linking step. After the process exits, the generated raw profiles will contains only headers + counters. llvm-profdata can be used correlate raw profiles with the unstripped binary to generate indexed profile. ## Data For chromium base_unittests with code coverage on linux, the binary size overhead due to instrumentation reduced from 64M to 38.8M (39.4%) and the raw profile files size reduce from 128M to 68M (46.9%) ``` $ bloaty out/cov/base_unittests.stripped -- out/no-cov/base_unittests.stripped FILE SIZE VM SIZE -------------- -------------- +121% +30.4Mi +121% +30.4Mi .text [NEW] +14.6Mi [NEW] +14.6Mi __llvm_prf_data [NEW] +10.6Mi [NEW] +10.6Mi __llvm_prf_names [NEW] +5.86Mi [NEW] +5.86Mi __llvm_prf_cnts +95% +1.75Mi +95% +1.75Mi .eh_frame +108% +400Ki +108% +400Ki .eh_frame_hdr +9.5% +211Ki +9.5% +211Ki .rela.dyn +9.2% +95.0Ki +9.2% +95.0Ki .data.rel.ro +5.0% +87.3Ki +5.0% +87.3Ki .rodata [ = ] 0 +13% +47.0Ki .bss +40% +1.78Ki +40% +1.78Ki .got +12% +1.49Ki +12% +1.49Ki .gcc_except_table [ = ] 0 +65% +1.23Ki .relro_padding +62% +1.20Ki [ = ] 0 [Unmapped] +13% +448 +19% +448 .init_array +8.8% +192 [ = ] 0 [ELF Section Headers] +0.0% +136 +0.0% +80 [7 Others] +0.1% +96 +0.1% +96 .dynsym +1.2% +96 +1.2% +96 .rela.plt +1.5% +80 +1.2% +64 .plt [ = ] 0 -99.2% -3.68Ki [LOAD #5 [RW]] +195% +64.0Mi +194% +64.0Mi TOTAL $ bloaty out/cov-cor/base_unittests.stripped -- out/no-cov/base_unittests.stripped FILE SIZE VM SIZE -------------- -------------- +121% +30.4Mi +121% +30.4Mi .text [NEW] +5.86Mi [NEW] +5.86Mi __llvm_prf_cnts +95% +1.75Mi +95% +1.75Mi .eh_frame +108% +400Ki +108% +400Ki .eh_frame_hdr +9.5% +211Ki +9.5% +211Ki .rela.dyn +9.2% +95.0Ki +9.2% +95.0Ki .data.rel.ro +5.0% +87.3Ki +5.0% +87.3Ki .rodata [ = ] 0 +13% +47.0Ki .bss +40% +1.78Ki +40% +1.78Ki .got +12% +1.49Ki +12% +1.49Ki .gcc_except_table +13% +448 +19% +448 .init_array +0.1% +96 +0.1% +96 .dynsym +1.2% +96 +1.2% +96 .rela.plt +1.2% +64 +1.2% +64 .plt +2.9% +64 [ = ] 0 [ELF Section Headers] +0.0% +40 +0.0% +40 .data +1.2% +32 +1.2% +32 .got.plt +0.0% +24 +0.0% +8 [5 Others] [ = ] 0 -22.9% -872 [LOAD #5 [RW]] -74.5% -1.44Ki [ = ] 0 [Unmapped] [ = ] 0 -76.5% -1.45Ki .relro_padding +118% +38.8Mi +117% +38.8Mi TOTAL ``` A few things to note: 1. llvm-profdata doesn't support filter raw profiles by binary id yet, so when a raw profile doesn't belongs to the binary being digested by llvm-profdata, merging will fail. Once this is implemented, llvm-profdata should be able to only merge raw profiles with the same binary id as the binary and discard the rest (with mismatched/missing binary id). The workflow I have in mind is to have scripts invoke llvm-profdata to get all binary ids for all raw profiles, and selectively choose the raw pnrofiles with matching binary id and the binary to llvm-profdata for merging. 2. Note: In COFF, currently they are still loaded into memory but not used. I didn't do it in this patch because I noticed that `.lcovmap` and `.lcovfunc` are loaded into memory. A separate patch will address it. 3. This should works with PGO when value profiling is disabled as debug info correlation currently doing, though I haven't tested this yet.
2023-12-13Reland "[Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code ↵Alan Phipps1-3/+30
Coverage (2/3)" Part 2 of 3. This includes the Visualization and Evaluation components. Differential Revision: https://reviews.llvm.org/D138847
2023-10-30Reland "[InstrProf][compiler-rt] Enable MC/DC Support in LLVM Source-based ↵Alan Phipps1-0/+4
Code Coverage (1/3)" Part 1 of 3. This includes the LLVM back-end processing and profile reading/writing components. compiler-rt changes are included. Differential Revision: https://reviews.llvm.org/D138846
2023-10-10Use llvm::endianness (NFC)Kazu Hirata1-7/+7
Now that llvm::support::endianness has been renamed to llvm::endianness, we can use the shorter form. This patch replaces support::endianness with llvm::endianness.
2023-10-10[llvm] Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata1-22/+19
Now that llvm::support::endianness has been renamed to llvm::endianness, we can use the shorter form. This patch replaces support::endianness::{big,little,native} with llvm::endianness::{big,little,native}.
2023-09-26Revert "[Coverage] Allow Clang coverage to be used with debug info correlation."Zequan Wu1-47/+20
This reverts commit 32db121b29f78e4c41116b2a8f1c730f9522b202 and subsequent commits. This causes time regression on llvm-cov even with debug info correlation off.
2023-09-21Revert "[InstrProf][compiler-rt] Enable MC/DC Support in LLVM Source-based ↵Hans Wennborg1-4/+0
Code Coverage (1/3)" This seems to cause Clang to crash, see comments on the code review. Reverting until the problem can be investigated. > Part 1 of 3. This includes the LLVM back-end processing and profile > reading/writing components. compiler-rt changes are included. > > Differential Revision: https://reviews.llvm.org/D138846 This reverts commit a50486fd736ab2fe03fcacaf8b98876db77217a7.
2023-09-20Revert "[Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code ↵Alan Phipps1-30/+3
Coverage (2/3)" This reverts commit 618a22144db5e45da8c95dc22064103e1b5e5b71. Buildbots failing on windows and one other issue.
2023-09-20[Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code Coverage ↵Alan Phipps1-3/+30
(2/3) Part 2 of 3. This includes the Visualization and Evaluation components. Differential Revision: https://reviews.llvm.org/D138847
2023-09-19[InstrProf][compiler-rt] Enable MC/DC Support in LLVM Source-based Code ↵Alan Phipps1-0/+4
Coverage (1/3) Part 1 of 3. This includes the LLVM back-end processing and profile reading/writing components. compiler-rt changes are included. Differential Revision: https://reviews.llvm.org/D138846
2023-09-18[Profile] Pass InstrProfSymtab by reference.Zequan Wu1-2/+2
2023-09-18[Profile] Pass InstrProfSymtab instead of IndexedInstrProfReader when ↵Zequan Wu1-11/+16
creating BinaryCoverageReader Only InstrProfSymtab is needed to retrieve function names when debug info corrletaion is enabled.
2023-09-15[Coverage] Allow Clang coverage to be used with debug info correlation.Zequan Wu1-20/+42
Debug info correlation is an option in InstrProfiling pass, which is used by both IR instrumentation and front-end instrumentation. So, Clang coverage can also benefits the binary size saving from it. Reviewed By: ellis Differential Revision: https://reviews.llvm.org/D157913
2023-09-06[llvm-cov] - Output better error message when the error kind is ↵MaggieYingYi1-31/+76
`coveragemap_error::malforme`. (#65264) The current llvm-cov error message for kind `coveragemap_error::malforme`, just gives the issue kind without any reason for what caused the issue. This patch is aimed at improving the llvm-cov error message to help identify what caused the issue. Reviewed By: MaskRay Close: https://github.com/llvm/llvm-project/pull/65264
2023-08-18Reland "[llvm-cov] Support multi-source object files for convert-for-testing"Yuhao Gu1-30/+63
`llvm-cov convert-for-testing` only functions properly when the input binary contains a single source file. When the binary has multiple source files, a `Malformed coverage data` error will occur when the generated .covmapping is read back. This is because the testing format lacks support for indicating the size of its file records, and current implementation just assumes there's only one record in it. This patch fixes this problem by introducing a new testing format version. Changes to the code: - Add a new format version. The version number is stored in the the last 8 bytes of the orignial magic number field to be backward-compatible. - Output a LEB128 number before the file records section to indicate its size in the new version. - Change the format parsing code correspondingly. - Update the document to formalize the testing format. - Additionally, fix the bug when converting COFF binaries. Reviewed By: phosek, gulfem Differential Revision: https://reviews.llvm.org/D156611
2023-08-15Revert "[llvm-cov] Fix a bug about using `convert-for-testing` on ↵Gulfem Savrun Yeniceri1-27/+22
multi-source object files" This reverts commit f8ad86c23405168a8cd189590184fdcc296627e0 because it broke some downsteam tests reported in https://reviews.llvm.org/D156611.
2023-08-15[llvm-cov] Fix a bug about using `convert-for-testing` on multi-source ↵Yuhao Gu1-22/+27
object files `llvm-cov convert-for-testing` is used to build the .covmapping files used in its regression tests. However the current implementation only works when there's only one source file in the mapping information data. If there are more than 1 source files, `llvm-cov convert-for-testing` can still produce a .covmapping file, but when read it back, `llvm-cov` will report: ``` error: Failed to load coverage: 'main.covmapping': Malformed coverage data ``` This is because the output .covmapping file doesn't have any mark to indicate the boundary between file records and function records, and current implementation jsut assume there's only one file record in the .covmapping file. Changes to the code: - Make `llvm-cov convert-for-testing` output a LEB128 number before file records to indicate its size. - Change the testing format parsing code correspondingly. - Update existing .covmapping files. Reviewed By: gulfem Differential Revision: https://reviews.llvm.org/D156611
2023-04-05[Object] Refactor build ID parsing into Object lib.Daniel Thornburgh1-4/+4
This makes parsing for build IDs in the markup filter slightly more permissive, in line with fromHex. It also removes the distinction between missing build ID and empty build ID; empty build IDs aren't a useful concept, since their purpose is to uniquely identify a binary. This removes a layer of indirection wherever build IDs are obtained. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D147485
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-01-26Reland: [llvm-cov] Look up object files using debuginfodDaniel Thornburgh1-5/+14
Reviewed By: gulfem Differential Revision: https://reviews.llvm.org/D136702
2023-01-25Revert "[llvm-cov] Look up object files using debuginfod"Douglas Yung1-14/+5
This reverts commit efbc8bb18eda63007216ad0cb5a8de04963eddd5. This change is causing failures when detecting curl on several build bots: - https://lab.llvm.org/buildbot/#/builders/247/builds/884 - https://lab.llvm.org/buildbot/#/builders/231/builds/7688 - https://lab.llvm.org/buildbot/#/builders/121/builds/27389 - https://lab.llvm.org/buildbot/#/builders/230/builds/8464 - https://lab.llvm.org/buildbot/#/builders/57/builds/24209 - https://lab.llvm.org/buildbot/#/builders/127/builds/42722
2023-01-25[llvm-cov] Look up object files using debuginfodDaniel Thornburgh1-5/+14
Reviewed By: gulfem Differential Revision: https://reviews.llvm.org/D136702
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-1/+1
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-12-12[ProfileData] llvm::Optional => std::optionalFangrui Song1-7/+7
2022-12-02[llvm] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
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-09-17[Support] Rename llvm::compression::{zlib,zstd}::uncompress to more ↵Fangrui Song1-1/+1
appropriate decompress This improves consistency with other places (e.g. llvm::compression::decompress, llvm::object::Decompressor::decompress, llvm-objcopy). Note: when zstd::uncompress was added, we noticed that the API `ZSTD_decompress` is fine while the zlib API `uncompress` is a misnomer.
2022-07-13[Support] Change compression::zlib::{compress,uncompress} to use uint8_t *Fangrui Song1-5/+5
It's more natural to use uint8_t * (std::byte needs C++17 and llvm has too much uint8_t *) and most callers use uint8_t * instead of char *. The functions are recently moved into `llvm::compression::zlib::`, so downstream projects need to make adaption anyway.
2022-07-08[NFC] Refactor llvm::zlib namespaceCole Kissane1-3/+3
* Refactor compression namespaces across the project, making way for a possible introduction of alternatives to zlib compression. Changes are as follows: * Relocate the `llvm::zlib` namespace to `llvm::compression::zlib`. Reviewed By: MaskRay, leonardchan, phosek Differential Revision: https://reviews.llvm.org/D128953
2022-06-28[CoverageMapping] Remove dots from paths inside the profilePetr Hosek1-1/+2
We already remove dots from collected paths and path mappings. This makes it difficult to match paths inside the profile which contain dots. For example, we would never match /path/to/../file.c because the collected path is always be normalized to /path/file.c. This change enables dot removal for paths inside the profile to address the issue. Differential Revision: https://reviews.llvm.org/D123164
2022-06-27Revert "[CoverageMapping] Remove dots from paths inside the profile"Petr Hosek1-2/+1
This reverts commit d1b098fc825176242afee12b8f9dc14adf5eec51 since it is failing on Windows builders.
2022-06-27[CoverageMapping] Remove dots from paths inside the profilePetr Hosek1-1/+2
We already remove dots from collected paths and path mappings. This makes it difficult to match paths inside the profile which contain dots. For example, we would never match /path/to/../file.c because the collected path is always be normalized to /path/file.c. This change enables dot removal for paths inside the profile to address the issue. Differential Revision: https://reviews.llvm.org/D122750
2022-02-10Cleanup LLVMObject headersserge-sans-paille1-0/+1
Most notably, llvm/Object/Binary.h no longer includes llvm/Support/MemoryBuffer.h llvm/Object/MachOUniversal*.h no longer include llvm/Object/Archive.h llvm/Object/TapiUniversal.h no longer includes llvm/Object/TapiFile.h llvm-project preprocessed size: before: 1068185081 after: 1068324320 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119457
2021-11-24[LLVM][NFC]Inclusive language: remove occurances of sanity check/test from llvmZarko Todorovski1-1/+0
Part of work to use more inclusive language in clang/llvm. Rewording some comments and change function and variable names.
2021-11-09[compiler-rt] Add more diagnostic to InstrProfErrorGulfem Savrun Yeniceri1-1/+2
If profile data is malformed for any kind of reason, we generate an error that only reports "malformed instrumentation profile data" without any further information. This patch extends InstrProfError class to receive an optional error message argument, so that we can do better error reporting. Differential Revision: https://reviews.llvm.org/D108942
2021-06-25[llvm-cov] Enforce alignment of function recordsserge-sans-paille1-12/+42
Function Records are required to be aligned on 8 bytes. This is enforced for each records except the first, when one relies on the default alignment within an std::string. There's no such guarantee, and indeed on 32 bits for some implementation of std::string this is not enforced. Provide a portable implementation based on llvm's MemoryBuffer. Differential Revision: https://reviews.llvm.org/D104745
2021-05-11[Coverage] Support overriding compilation directoryPetr Hosek1-30/+42
When making compilation relocatable, for example in distributed compilation scenarios, we want to set compilation dir to a relative value like `.` but this presents a problem when generating reports because if the file path is relative as well, for example `..`, you may end up writing files outside of the output directory. This change introduces a flag that allows overriding the compilation directory that's stored inside the profile with a different value that is absolute. Differential Revision: https://reviews.llvm.org/D100232
2021-05-11[llvm-cov] Support for v4 format in convert-for-testingPetr Hosek1-7/+34
v4 moves function records to a dedicated section so we need to write and read it separately. https://reviews.llvm.org/D100535