1101 Commits

Author SHA1 Message Date
Teresa Johnson
749d595de9
[MemProf][NFC] Correct comment about stripping of suffixes in profile (#73840)
The comment about the stripping of suffixes when creating the indexed
MemProf profile was partially incorrect, as we do not strip ".__uniq."
suffixes by default (by design). Update the comment accordingly.
2023-11-29 10:34:21 -08:00
Zequan Wu
b9951b3fe6
[llvm-profdata] Fix binary ids with multiple raw profiles in a single… (#72740)
Save binary ids when iterating through `RawInstrProfReader`.

Fixes #72699.
2023-11-20 14:25:24 -05:00
Ellis Hoag
b0154c36d6
[InstrProf] Add pgo use block coverage test (#72443)
Back in https://reviews.llvm.org/D124490 we added a block coverage mode
that instruments a subset of basic blocks using single byte counters to
get coverage for the whole function.

This commit adds a test to make sure that we correctly assign branch
weights based on the coverage profile.

I noticed this test was missing after seeing that we had no coverage on
`PGOUseFunc::populateCoverage()`

https://lab.llvm.org/coverage/coverage-reports/coverage/Users/buildslave/jenkins/workspace/coverage/llvm-project/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp.html#L1383
2023-11-20 09:25:33 -06:00
Kazu Hirata
0d55ea25a6 [llvm] Stop including llvm/ADT/DenseMapInfo.h (NFC)
Identified with clangd.
2023-11-11 00:13:29 -08:00
William Junda Huang
683f2df6e5
[SampleProfile] Fix bug where remapper returns empty string and crashing Sample Profile loader (#71479)
Normally SampleContext does not allow using an empty StirngRef to
construct an object, this is to prevent bugs reading the profile.
However empty names may be emitted by a function which its name is
intentionally set to empty, or a bug in the remapper that returns an
empty string. Regardless, converting it to FunctionId first will prevent
the assert, and that assert check is unnecessary, which will be
addressed in another patch
2023-11-10 21:38:13 +00:00
Mingming Liu
bb642f8b94
[NFC][InstrProf]Refactor readPGOFuncNameStrings (#71566)
Refactor this function to take a callback for each decoded string, rename it and change it to a static function in cpp. Move its (sole) caller definition from header to cpp.
- This is a split of patch https://github.com/llvm/llvm-project/pull/66825; to minimize the diff created in a big PR.
2023-11-09 10:47:44 -08:00
Zequan Wu
56e205a89c [Profile] Fix debug info correlation test failure on mac. 2023-11-02 11:30:26 -04:00
Zequan Wu
3c97c8b6fc
[Profile] Refactor profile correlation. (#70856)
Refactor some code from https://github.com/llvm/llvm-project/pull/69493.

#70712 was reverted due to linking failures. So, `-debug-info-correlate` remains unchanged and no new flag added.
2023-11-01 14:16:43 -04:00
Zequan Wu
89a2e70159
[llvm-profdata] Emit warning when counter value is greater than 2^56. (#69513)
Fixes #65416
2023-10-31 16:40:51 -04:00
Zequan Wu
db7a1ed9a2 Revert "[Profile] Refactor profile correlation. (#70712)"
This reverts commit 4b383d0af93136b80841fc140da0823dfc441dd4.
2023-10-31 10:53:45 -04:00
Zequan Wu
4b383d0af9
[Profile] Refactor profile correlation. (#70712)
Refactor some code from https://github.com/llvm/llvm-project/pull/69493.

Rebase of https://github.com/llvm/llvm-project/pull/69656 on top of main
as it was messed up.
2023-10-31 10:41:01 -04:00
Alan Phipps
f95b2f1acf Reland "[InstrProf][compiler-rt] Enable MC/DC Support in LLVM Source-based 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-30 11:15:02 -05:00
Mingming Liu
a1e9777b76
[NFC] In InstrProf, generalize helper functions to take 'GlobalObject'. They currently take 'Functions' as function parameters or have 'Func' in the name. (#70287)
- For instance, `collectPGOFuncNameStrings` is reused a lot in https://github.com/llvm/llvm-project/pull/66825 to get the compressed vtable names; and in some added callsites it's just confusing to see 'func' since context clearly shows it's not. This function currently just takes a list of strings as input so name it to `collectGlobalObjectNameStrings`
- Do the rename in a standalone patch since the method is used in non-llvm codebase. It's easier to rollback this NFC in case rename in that codebase takes longer.
2023-10-26 14:48:36 -07:00
Kazu Hirata
3b7bfeb483 [llvm] Stop including llvm/ADT/SmallString.h (NFC)
Identified with misc-include-cleaner.
2023-10-22 10:42:15 -07:00
William Junda Huang
ef0e0adccd
[llvm-profdata] Do not create numerical strings for MD5 function names read from a Sample Profile. (#66164)
This is phase 2 of the MD5 refactoring on Sample Profile following
https://reviews.llvm.org/D147740
    
In previous implementation, when a MD5 Sample Profile is read, the
reader first converts the MD5 values to strings, and then create a
StringRef as if the numerical strings are regular function names, and
later on IPO transformation passes perform string comparison over these
numerical strings for profile matching. This is inefficient since it
causes many small heap allocations.
In this patch I created a class `ProfileFuncRef` that is similar to
`StringRef` but it can represent a hash value directly without any
conversion, and it will be more efficient (I will attach some benchmark
results later) when being used in associative containers.

ProfileFuncRef guarantees the same function name in string form or in
MD5 form has the same hash value, which also fix a few issue in IPO
passes where function matching/lookup only check for function name
string, while returns a no-match if the profile is MD5.

When testing on an internal large profile (> 1 GB, with more than 10
million functions), the full profile load time is reduced from 28 sec to
25 sec in average, and reading function offset table from 0.78s to 0.7s
2023-10-17 21:09:39 +00:00
Kazu Hirata
02f67c097d Use llvm::endianness::{big,little,native} (NFC)
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class. This patch replaces
{big,little,native} with llvm::endianness::{big,little,native}.

This patch completes the migration to llvm::endianness and
llvm::endianness::{big,little,native}.  I'll post a separate patch to
remove the migration helpers in llvm/Support/Endian.h:

  using endianness = llvm::endianness;
  constexpr llvm::endianness big = llvm::endianness::big;
  constexpr llvm::endianness little = llvm::endianness::little;
  constexpr llvm::endianness native = llvm::endianness::native;
2023-10-13 23:16:25 -07:00
Kazu Hirata
4a0ccfa865 Use llvm::endianness::{big,little,native} (NFC)
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an
enum. This patch replaces support::{big,little,native} with
llvm::endianness::{big,little,native}.
2023-10-12 21:21:45 -07:00
Fangrui Song
776e456dd8 [llvm-cov gcov] Make recursive propagateCounts iterative. NFC
propagateCounts computes unmeasured arc counts (see
commit b9d086693b5baebc477793af0d86a447bae01b6f).

In a x86-64 build using -O3 -fno-omit-frame-pointer, propagateCounts uses 80
bytes per stack frame. If a function contains 1e5 basic blocks on a tree path
(Kirchoff's circuit law optimization), the used stack space will be 8MB (default
ulimit -s in many configurations). (In a -O0 build, a stack frame costs 224
bytes.) 1e5 is ample for most configurations. However, for library users using
threads (e.g. in RPC handlers), a remaining thread stack of 64KiB allows just
819 stack frames, which is too limited.

Switch to an iterative form to avoid stack overflow issues. Iterative forms
match other iterative form functions in this file
(https://reviews.llvm.org/D93073).

Alternative to #68455
2023-10-11 11:22:13 -07:00
Kazu Hirata
b8885926f8 Use llvm::endianness::{big,little,native} (NFC)
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an enum.
This patch replaces llvm::support::{big,little,native} with
llvm::endianness::{big,little,native}.
2023-10-10 22:54:51 -07:00
Kazu Hirata
a9d5056862 Use llvm::endianness (NFC)
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 21:54:15 -07:00
Kazu Hirata
b05dbc4d5f [llvm] Use llvm::endianness::{big,little,native} (NFC)
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-10-10 20:14:20 -07:00
Kazu Hirata
b3ec0595d3 [llvm] Drop unaligned from calls to llvm::support::endian::{read,write} (NFC)
The last template parameter of llvm::support::endian::{read,write}
defaults to unaligned, so we can drop that at call sites.
2023-10-10 18:57:14 -07:00
Kazu Hirata
d7b18d5083 Use llvm::endianness{,::little,::native} (NFC)
Now that llvm::support::endianness has been renamed to
llvm::endianness, we can use the shorter form.  This patch replaces
llvm::support::endianness with llvm::endianness.
2023-10-09 00:54:47 -07:00
Kazu Hirata
a06e94cf3b [ProfileData] Remove getHostEndianness (NFC)
With the recent redefinition of llvm::endianness::native, it is equal
to either llvm::endianness::big or llvm::endianness::little depending
on the host endianness.  Since getHostEndianness just returns
llvm::endianness::native, this patch removes the function and
"constant propagates" llvm::endianness:native.
2023-10-05 21:30:48 -07:00
Mingming Liu
1c2634e316
[NFC]Rename InstrProf::getFuncName{,orExternalSymbol} to getFuncOrValName{,IfDefined} (#68240)
- This function looks up MD5ToNameMap to return a name for a given MD5.
https://github.com/llvm/llvm-project/pull/66825 adds MD5 of global
variable names into this map. So rename methods and update comments
2023-10-04 11:56:28 -07:00
Zequan Wu
3c34245c47
[Profile] Use upper 32 bits of profile version for profile variants. (#67695)
Currently all upper 8 bits are reserved for different profile variants.
We need more bits for new mods in the future.
Context:
https://discourse.llvm.org/t/how-to-add-a-new-mode-to-llvm-raw-profile-version/73688
2023-10-03 10:15:22 -04:00
shen3qing1
3f417a7096
[NFC] [Coverage] Do not use recursion for getMaxCounterID (#67870)
This causes stack overflows for real-world coverage reports.

Tested with build/bin/llvm-lit -a llvm/test/tools/llvm-cov

Co-authored-by: Qing Shen <qingshen@google.com>
2023-10-02 13:40:43 -07:00
Zequan Wu
4d5d9a5390 Revert "[Coverage] Allow Clang coverage to be used with debug info correlation."
This reverts commit 32db121b29f78e4c41116b2a8f1c730f9522b202 and subsequent commits.

This causes time regression on llvm-cov even with debug info correlation off.
2023-09-26 20:57:09 -04:00
Kazushi Marukawa
418e441936
[InstrProf] Correct buffer size for encodeULEB128 (#67011)
This function uses 16 bytes buffer to encode two 64 bits data. However,
the encoding method requires 10 bytes to encode one 64 bits data, so
encoded data actually requiress 20 bytes total.
2023-09-26 10:16:01 +09:00
William Junda Huang
3a807b5ac6
[llvm-profdata] Move error handling logic out of normal input's code path (#67177)
Based on disassembly and profiling results, it looks like the cost of
std::error_code and llvm::ErrorOr<> are non-trivial, as it involves
virtual function calls that are not optimized in -O3.

This patch moves error handling logic into the conditional branch in
error checking, only generates std::error_code on actual error instead
of the default case to generate sampleprof_error::success.

In the next patch I am looking to change the API to uses a plain old
enum for error checking instead, because based on profiling results
error handling related code accounts for 7-8% of the profile loading
time even if there's no error at all.
2023-09-25 16:08:27 +00:00
Fangrui Song
dd8902ab3b [llvm-cov] Properly fix -Wcovered-switch-default in CoverageMapping.cpp
And revert commit 1f3fa96e516fda26244afb8877e6cee619c21205.
2023-09-24 12:06:15 -07:00
Kazu Hirata
7df88212d4 [ProfileData] Use llvm::byteswap instead of sys::getSwappedBytes (NFC) 2023-09-23 13:00:47 -07:00
Kazu Hirata
9c5b38b49f [Coverage] Fix a warning
This patch fixes:

  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp:219:5: error:
  default label in switch which covers all enumeration values
  [-Werror,-Wcovered-switch-default]
2023-09-22 09:50:11 -07:00
shen3qing1
487c784ef2
[NFC]Do not use recursion for CounterMappingContext::evaluate (#66961)
This causes stack overflows for real-world coverage reports.

Ran $ build/bin/llvm-lit -a llvm/test/tools/llvm-cov locally and passed.

Co-authored-by: Qing Shen <qingshen@google.com>
2023-09-22 09:04:49 -07:00
Kazu Hirata
4c14638b55 [llvm] Use range-based for loops (NFC) 2023-09-22 00:41:37 -07:00
Hans Wennborg
53a2923bf6 Revert "[InstrProf][compiler-rt] Enable MC/DC Support in LLVM Source-based 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-21 12:20:24 +02:00
Alan Phipps
ab3cd075b3 Revert "[Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code Coverage (2/3)"
This reverts commit 618a22144db5e45da8c95dc22064103e1b5e5b71.

Buildbots failing on windows and one other issue.
2023-09-20 16:32:34 -05:00
Alan Phipps
618a22144d [Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code Coverage (2/3)
Part 2 of 3. This includes the Visualization and Evaluation components.

Differential Revision: https://reviews.llvm.org/D138847
2023-09-20 15:30:47 -05:00
Alan Phipps
a50486fd73 [InstrProf][compiler-rt] Enable MC/DC Support in LLVM Source-based 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-09-19 17:07:23 -05:00
Zequan Wu
1609a87a83 [Profile] Pass InstrProfSymtab by reference. 2023-09-18 14:20:10 -04:00
Zequan Wu
cb9f66de8b [Profile] Pass InstrProfSymtab instead of IndexedInstrProfReader when creating BinaryCoverageReader
Only InstrProfSymtab is needed to retrieve function names when debug info corrletaion is enabled.
2023-09-18 12:44:26 -04:00
Zequan Wu
37402c3491 [NFC][Coverage] Rename coverage function attribute name from "Cov Function Name" to "Coverage Function Name" 2023-09-15 15:23:17 -04:00
Zequan Wu
32db121b29 [Coverage] Allow Clang coverage to be used with debug info correlation.
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-15 13:47:23 -04:00
Jie Fu
1f3fa96e51 [llvm-cov] Fix -Wcovered-switch-default in CoverageMapping.cpp (NFC)
/Users/jiefu/llvm-project/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp:959:3: error: default label in switch which covers all enumeration values [-Werror,-Wcovered-switch-default]
  default:
  ^
1 error generated.
2023-09-06 22:30:36 +08:00
MaggieYingYi
cd8fe1dbcb
[llvm-cov] - Output better error message when the error kind is 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-09-06 15:02:31 +01:00
Snehasish Kumar
37fd3c96b9 [memprof] Add a MemProfReader base class.
Add a MemProfReader base class which can be used directly where
symbolization and processing a raw profile is unnecessary.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D159141
2023-08-30 20:20:55 +00:00
Snehasish Kumar
0edc32fda5 [memprof] Canonicalize the function name prior to hashing.
Canonicalize the function name (strip suffixes etc) to ensure that
function name suffixes added by late stage passes do not cause
mismatches when memprof profile data is consumed.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D159132
2023-08-29 20:45:39 +00:00
Kazu Hirata
25ac7a0d11 [llvm] Use SmallDenseMap::contains (NFC) 2023-08-27 00:18:16 -07:00
Arthur Eubanks
a6f33ad447 [NFC][Profile] Rename Counters/DataSize to NumCounters/Data
Fixes some FIXMEs.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D158466
2023-08-22 09:03:59 -07:00
Yuhao Gu
57cb2f6ffe Reland "[llvm-cov] Support multi-source object files for convert-for-testing"
`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-18 16:43:45 +00:00