aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-profdata/llvm-profdata.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-10-07[InstrProf][llvm-profdata] Dump profile correlation data as YAMLEllis Hoag1-2/+5
Change the behavior of the `llvm-profdata show --debug-info=` command to dump a YAML file when using debug info correlation since it provides more information in a parseable format. Reviewed By: yozhu, phosek Differential Revision: https://reviews.llvm.org/D134770
2022-10-07[llvm-profdata] Add --output-format optionEllis Hoag1-15/+39
Add `--output-format` option for the `llvm-profdata show` command to select the type of output. The existing `--text` flag is used to emit text encoded profiles. To avoid confusion, `--output-format=text-encoding` indicates that the output will be profiles encoded in the text format, and `--output-format=text` indicates the default text output that doesn't necessarily represent a profile. `--output-format=json` is an alias for `--json` and `--output-format=yaml` will be used in D134770. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D135127
2022-10-06[InstrProf] Add version into llvm-profdataGulfem Savrun Yeniceri1-3/+6
This patch adds support of printing profile version into llvm-profdata which was proposed in: https://discourse.llvm.org/t/llvm-profdata-failure-guarantees-for-code-coverage/64924 Differential Revision: https://reviews.llvm.org/D135317
2022-10-06[llvm-driver] Add various tools to the llvm-driverAlex Brachet1-1/+2
The llvm-driver, enabled with LLVM_TOOL_LLVM_DRIVER_BUILD combines many llvm executables into one to save overall toolchain size. This patch adds a few more llvm tools to the llvm-driver. Differential Revision: https://reviews.llvm.org/D135281
2022-09-28[iwyu] Move <cmath> out of llvm/Support/MathExtras.hserge-sans-paille1-0/+1
Interestingly, MathExtras.h doesn't use <cmath> declaration, so move it out of that header and include it when needed. No functional change intended, but there's no longer a transitive include fromMathExtras.h to cmath.
2022-08-29[llvm-profdata] Improve profile supplementationRong Xu1-17/+57
Current implementation promotes a non-cold function in the SampleFDO profile into a hot function in the FDO profile. This is too aggressive. This patch promotes a hot functions in the SampleFDO profile into a hot function, and a warm function in SampleFDO into a warm function in FDO. Differential Revision: https://reviews.llvm.org/D132601
2022-08-29[llvm-profdata] Handle internal linkage functions in profile supplementationRong Xu1-9/+94
This patch has the following changes: (1) Handling of internal linkage functions (static functions) Static functions in FDO have a prefix of source file name, while they do not have one in SampleFDO. Current implementation does not handle this and we are not updating the profile for static functions. This patch fixes this. (2) Handling of -funique-internal-linakge-symbols Again this is for the internal linkage functions. Option -funique-internal-linakge-symbols can now be applied to both FDO and SampleFDO compilation. When it is used, it demangles internal linkage function names and adds a hash value as the postfix. When both SampleFDO and FDO profiles use this option, or both not use this option, changes in (1) should handle this. Here we also handle when the SampleFDO profile using this option while FDO profile not using this option, or vice versa. There is one case where this patch won't work: If one of the profiles used mangled name and the other does not. For example, if the SampleFDO profile uses clang c-compiler and without -funique-internal-linakge-symbols, while the FDO profile uses -funique-internal-linakge-symbols. The SampleFDO profile contains unmangled names while the FDO profile contains mangled names. If both profiles use c++ compiler, this won't happen. We think this use case is rare and does not justify the effort to fix. Differential Revision: https://reviews.llvm.org/D132600
2022-08-29[llvm-profdata] Adjust profile supplementation heuristicsRong Xu1-2/+4
1) We now use the count size in FDO as the main factor to deal with pre-inliner. Currently we use the number of sample records in the SampleFDO profile. But that only counts the top-level body sample records (not including the nested call-sites). We are seeing some big functions not being updated because of this. I think using the count size in FDO profile is more reasonable to judge if the function is likely to be inlined to the callers in pre-inliner. (2) We use getMaxCount in SampleFDO rather the HeadSample to determine if if the function is hot in SampleFDO. This is in-sync with the logic in the compiler (also HeadSample can be 0). Differential Revision: https://reviews.llvm.org/D132602
2022-08-09[llvm-profdata] Support JSON as as an output-only formatKazu Hirata1-8/+20
This patch teaches llvm-profdata to output the sample profile in the JSON format. The new option is intended to be used for research and development purposes. For example, one can write a Python script to take a JSON file and analyze how similar different inline instances of a given function are to each other. I've chosen JSON because Python can parse it reasonably fast, and it just takes a couple of lines to read the whole data: import json with open ('profile.json') as f: profile = json.load(f) Differential Revision: https://reviews.llvm.org/D130944
2022-07-24Use any_of (NFC)Kazu Hirata1-2/+1
2022-07-22[NFC] FunctionSamples::getEntrySamples -> getHeadSamplesEstimateMircea Trofin1-3/+4
The name `getEntrySamples` was misleading for 2 reasons. One, it's close in name to `Function::getEntryCount`, but the equivalent here is `getHeadSamples`; second, as opposed to the other get* APIs in `FunctionSamples`, it performs an estimate/heuristic rather than just retrieving raw data (or a non-heuristic derivate off that data, like `getMaxCountInside`) The new name should more clearly communicate its intent; and, being close (in name) to `getHeadSamples`, it should allow the reader discover the relation between them. Also updated the doc comments for both `getHeadSamples[Estimate]` so a reader may better understand the relation between them. Differential Revision: https://reviews.llvm.org/D130281
2022-06-25[llvm] Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata1-2/+2
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
2022-06-03[llvm] Remove unneeded cl::ZeroOrMore for cl::opt options. NFCFangrui Song1-1/+1
Some cl::ZeroOrMore were added to avoid the `may only occur zero or one times!` error. More were added due to cargo cult. Since the error has been removed, cl::ZeroOrMore is unneeded. Also remove cl::init(false) while touching the lines.
2022-05-25[memprof] Keep and display symbol names in the RawMemProfReader.Snehasish Kumar1-2/+2
Extend the Frame struct to hold the symbol name if requested when a RawMemProfReader object is constructed. This change updates the tests and removes the need to pass --debug to obtain the mapping from GUID to symbol names. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D126344
2022-05-05Fix "the the" typo in documentation and user facing stringsBrian Tracy1-1/+1
There are many more instances of this pattern, but I chose to limit this change to .rst files (docs), anything in libcxx/include, and string literals. These have the highest chance of being seen by end users. Reviewed By: #libc, Mordante, martong, ldionne Differential Revision: https://reviews.llvm.org/D124708
2022-05-04[ThreadPool] add ability to group tasks into separate groupsLuboš Luňák1-0/+1
This is needed for parallelizing of loading modules symbols in LLDB (D122975). Currently LLDB can parallelize indexing symbols when loading a module, but modules are loaded sequentially. If LLDB index cache is enabled, this means that the cache loading is not parallelized, even though it could. However doing that creates a threadpool-within-threadpool situation, so the number of threads would not be properly limited. This change adds ThreadPoolTaskGroup as a simple type that can be used with ThreadPool calls to put tasks into groups that can be independently waited for (even recursively from within a task) but still run in the same thread pool. Differential Revision: https://reviews.llvm.org/D123225
2022-04-29[CSSPGO] Rename ProfileIsCSNested and ProfileIsCSFlatHongtao Yu1-8/+7
To be more clear and definitive, I'm renaming `ProfileIsCSFlat` back to `ProfileIsCS` which stands for full context-sensitive flat profiles. `ProfileIsCSNested` is now renamed to `ProfileIsPreInlined` and is extended to be applicable for CS flat profiles too. More specifically, `ProfileIsPreInlined` is for any kind of profiles (flat or nested) that contain 'ShouldBeInlined' contexts. The flag is encoded in the profile summary section for extbinary profiles and is computed on-the-fly for text profiles. Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D122602
2022-04-08[memprof] Deduplicate and outline frame storage in the memprof profile.Snehasish Kumar1-6/+19
The current implementation of memprof information in the indexed profile format stores the representation of each calling context fram inline. This patch uses an interned representation where the frame contents are stored in a separate on-disk hash table. The table is indexed via a hash of the contents of the frame. With this patch, the compressed size of a large memprof profile reduces by ~22%. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D123094
2022-03-23[llvm-profdata] Unify default cutoffs for detailed summary printingWenlei He1-1/+1
Use `ProfileSummaryBuilder::DefaultCutoffs` for llvm-profdata detailed summary printing for Instr profile. Differential Revision: https://reviews.llvm.org/D122210
2022-03-22Reland "[memprof] Store callsite metadata with memprof records."Snehasish Kumar1-2/+2
This reverts commit f4b794427e8037a4e952cacdfe7201e961f31a6f. Reland with underlying msan issue fixed in D122260.
2022-03-21Revert "[memprof] Store callsite metadata with memprof records."Mitch Phillips1-2/+2
This reverts commit 0d362c90d335509c57c0fbd01ae1829e2b9c3765. Reason: Causes the MSan buildbot to fail (see comments on https://reviews.llvm.org/D121179 for more information
2022-03-21[memprof] Store callsite metadata with memprof records.Snehasish Kumar1-2/+2
To ease profile annotation, each of the callsites in a function can be annotated with profile data - "IR metadata format for MemProf" [1]. This patch extends the on-disk serialized record format to store the debug information for allocation callsites incl inline frames. This change is incompatible with the existing format i.e. indexed profiles must be regenerated, raw profiles are unaffected. [1] https://groups.google.com/g/llvm-dev/c/aWHsdMxKAfE/m/WtEmRqyhAgAJ Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D121179
2022-02-17Reland "[memprof] Extend the index prof format to include memory profiles."Snehasish Kumar1-7/+41
This patch adds support for optional memory profile information to be included with and indexed profile. The indexed profile header adds a new field which points to the offset of the memory profile section (if present) in the indexed profile. For users who do not utilize this feature the only overhead is a 64-bit offset in the header. The memory profile section contains (1) profile metadata describing the information recorded for each entry (2) an on-disk hashtable containing the profile records indexed via llvm::md5(function_name). We chose to introduce a separate hash table instead of the existing one since the indexing for the instrumented fdo hash table is based on a CFG hash which itself is perturbed by memprof instrumentation. This commit also includes the changes reviewed separately in D120093. Differential Revision: https://reviews.llvm.org/D120103
2022-02-17Revert "Reland "[memprof] Extend the index prof format to include memory ↵Snehasish Kumar1-41/+7
profiles."" This reverts commit 807ba7aace188ada83ddb4477265728e97346af1.
2022-02-17Reland "[memprof] Extend the index prof format to include memory profiles."Snehasish Kumar1-7/+41
This reverts commit 85355a560a33897453df2ef959e255ee725eebce. This patch adds support for optional memory profile information to be included with and indexed profile. The indexed profile header adds a new field which points to the offset of the memory profile section (if present) in the indexed profile. For users who do not utilize this feature the only overhead is a 64-bit offset in the header. The memory profile section contains (1) profile metadata describing the information recorded for each entry (2) an on-disk hashtable containing the profile records indexed via llvm::md5(function_name). We chose to introduce a separate hash table instead of the existing one since the indexing for the instrumented fdo hash table is based on a CFG hash which itself is perturbed by memprof instrumentation. Differential Revision: https://reviews.llvm.org/D118653
2022-02-14Revert "Reland "[memprof] Extend the index prof format to include memory ↵Snehasish Kumar1-41/+7
profiles."" This reverts commit de54e4ab78ef09b60f870e8df6f8a87e56d6bd94 [1/4]
2022-02-14Reland "[memprof] Extend the index prof format to include memory profiles."Snehasish Kumar1-7/+41
This reverts commit 0f73fb18ca333e38cdb9ffa701a8db026c56041d. Use llvm/Profile/MIBEntryDef.inc instead of relative path. Generated the raw profile data with `-mllvm -enable-name-compression=false` so that builbots where the reader is built without zlib do not fail. Also updated the test build instructions.
2022-02-14[llvm-profdata] Fix use-after-moveFangrui Song1-0/+1
2022-02-14Revert "[memprof] Extend the index prof format to include memory profiles."Snehasish Kumar1-41/+7
This reverts commit 43c2348c5b926df6bdbc5b70efaa35ecdefe12d5. Buildbots are failing with an error on reading memprof testdata. "Inputs/basic.profraw: profile uses zlib compression but the profile reader was built without zlib support" https://lab.llvm.org/buildbot/#/builders/16/builds/24490
2022-02-14[memprof] Extend the index prof format to include memory profiles.Snehasish Kumar1-7/+41
This patch adds support for optional memory profile information to be included with and indexed profile. The indexed profile header adds a new field which points to the offset of the memory profile section (if present) in the indexed profile. For users who do not utilize this feature the only overhead is a 64-bit offset in the header. The memory profile section contains (1) profile metadata describing the information recorded for each entry (2) an on-disk hashtable containing the profile records indexed via llvm::md5(function_name). We chose to introduce a separate hash table instead of the existing one since the indexing for the instrumented fdo hash table is based on a CFG hash which itself is perturbed by memprof instrumentation. Differential Revision: https://reviews.llvm.org/D118653
2022-02-08Revert "Revert "[ProfileData] Read and symbolize raw memprof profiles.""Snehasish Kumar1-4/+14
This reverts commit dbf47d227d080e4eb7239b589660f51d7b08afa9. Reapply https://reviews.llvm.org/D116784 now that https://reviews.llvm.org/D118413 has landed with a couple of fixes: * fix raw profile reader unaligned access identified by ubsan * fix windows build by using MOCK_CONST_METHOD3 instead of MOCK_METHOD.
2022-02-03Revert "[ProfileData] Read and symbolize raw memprof profiles."Snehasish Kumar1-14/+4
This reverts commit 26f978d4c5ad0d2217940ef7625b0c3c0d576988. This patch added a transitive dependency on libcurl via symbolize. See discussion https://reviews.llvm.org/D116784#inline-1137928 https://reviews.llvm.org/D113717#3295350
2022-02-03[ProfileData] Read and symbolize raw memprof profiles.Snehasish Kumar1-4/+14
This change extends the RawMemProfReader to read all the sections of the raw profile and symbolize the virtual addresses recorded as part of the callstack for each allocation. For now the symbolization is used to display the contents of the profile with llvm-profdata. Differential Revision: https://reviews.llvm.org/D116784
2022-02-03[memprof] Print out the summary in YAML format.Snehasish Kumar1-1/+2
Print out the profile summary in YAML format to make it easier to for tools and tests to read in the contents of the raw profile. Differential Revision: https://reviews.llvm.org/D116783
2022-01-27[InstrProf] Add single byte coverage modeEllis Hoag1-3/+14
Use the llvm flag `-pgo-function-entry-coverage` to create single byte "counters" to track functions coverage. This mode has significantly less size overhead in both code and data because * We mark a function as "covered" with a store instead of an increment which generally requires fewer assembly instructions * We use a single byte per function rather than 8 bytes per block The trade off of course is that this mode only tells you if a function has been covered. This is useful, for example, to detect dead code. When combined with debug info correlation [0] we are able to create an instrumented Clang binary that is only 150M (the vanilla Clang binary is 143M). That is an overhead of 7M (4.9%) compared to the default instrumentation (without value profiling) which has an overhead of 31M (21.7%). [0] https://groups.google.com/g/llvm-dev/c/r03Z6JoN7d4 Reviewed By: kyulee Differential Revision: https://reviews.llvm.org/D116180
2022-01-27[InstrProf][NFC] Refactor Profile kind into a bitset enum.Snehasish Kumar1-4/+1
This change refactors the ProfileKind enum into a bitset enum to represent the different attributes a profile can have. This change simplifies the logic in the instrprof writer when multiple profiles are merged together. In the future we plan on introducing a new memory profile section which will extend the enum by one additional entry. Without this change when accounting for memory profiles will have to be maintained separately and will make the logic more complex. Differential Revision: https://reviews.llvm.org/D115393
2022-01-27[InstrProf][Correlate] Verify debug info with llvm-profdata showEllis Hoag1-2/+41
Use the `llvm-profdata show` command to verify debug info for profile correlation using the `--debug-info` option. Reviewed By: kyulee Differential Revision: https://reviews.llvm.org/D118181
2022-01-18Handle whitespace in symbol listChris Bieneman1-2/+2
Trimming whitespace or carriage returns from symbols allows this code to work on Windows and makes it match other places symbol lists are handled. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D117570
2022-01-08[llvm] Remove redundant member initialization (NFC)Kazu Hirata1-4/+3
Identified with readability-redundant-member-init.
2022-01-03Revert "[llvm] Remove redundant member initialization (NFC)"Kazu Hirata1-3/+4
This reverts commit fd4808887ee47f3ec8a030e9211169ef4fb094c3. This patch causes gcc to issue a lot of warnings like: warning: base class ‘class llvm::MCParsedAsmOperand’ should be explicitly initialized in the copy constructor [-Wextra]
2022-01-01[llvm] Remove redundant member initialization (NFC)Kazu Hirata1-4/+3
Identified with readability-redundant-member-init.
2021-12-28[llvm-profdata] Make -debug-info visibleKyungwoo Lee1-1/+1
Add the option comment in .rst. Reviewed By: ellis Differential Revision: https://reviews.llvm.org/D116348
2021-12-17[Try2][InstrProf] Add Correlator class to read debug infoEllis Hoag1-7/+26
Extend `llvm-profdata` to read in a `.proflite` file and also a debug info file to generate a normal `.profdata` profile. This reduces the binary size by 8.4% when building an instrumented Clang binary without value profiling (164 MB vs 179 MB). This work is part of the "lightweight instrumentation" RFC: https://groups.google.com/g/llvm-dev/c/r03Z6JoN7d4 This was first landed in https://reviews.llvm.org/D114566 but had to be reverted due to build errors. Reviewed By: kyulee Differential Revision: https://reviews.llvm.org/D115915
2021-12-16Revert "[InstrProf] Add Correlator class to read debug info"Ellis Hoag1-26/+7
Also reverts an attempt to fix the build errors https://reviews.llvm.org/D115911 The original diff https://reviews.llvm.org/D114566 causes some build errors that I need to investigate. https://lab.llvm.org/buildbot/#/builders/118/builds/7037 This reverts commit 95946d2f8589b5450d8f9a9e9b4f7adf44386f8b. Reviewed By: kyulee Differential Revision: https://reviews.llvm.org/D115913
2021-12-16[InstrProf] Add Correlator class to read debug infoEllis Hoag1-7/+26
Extend `llvm-profdata` to read in a `.proflite` file and also a debug info file to generate a normal `.profdata` profile. This reduces the binary size by 8.4% when building an instrumented Clang binary without value profiling (164 MB vs 179 MB). This work is part of the "lightweight instrumentation" RFC: https://groups.google.com/g/llvm-dev/c/r03Z6JoN7d4 Reviewed By: kyulee Differential Revision: https://reviews.llvm.org/D114566
2021-12-14[CSSPGO] Use nested context-sensitive profile.Hongtao Yu1-11/+20
CSSPGO currently employs a flat profile format for context-sensitive profiles. Such a flat profile allows for precisely manipulating contexts that is either inlined or not inlined. This is a benefit over the nested profile format used by non-CS AutoFDO. A downside of this is the longer build time due to parsing the indexing the full CS contexts. For a CS flat profile, though only the context profiles relevant to a module are loaded when that module is compiled, the cost to figure out what profiles are relevant is noticeably high when there're many contexts, since the sample reader will need to scan all context strings anyway. On the contrary, a nested function profile has its related inline subcontexts isolated from other unrelated contexts. Therefore when compiling a set of functions, unrelated contexts will never need to be scanned. In this change we are exploring using nested profile format for CSSPGO. This is expected to work based on an assumption that with a preinliner-computed profile all contexts are precomputed and expected to be inlined by the compiler. Contexts not expected to be inlined will be cut off and returned to corresponding base profiles (for top-level outlined functions). This naturally forms a nested profile where all nested contexts are expected to be inlined. The compiler will less likely optimize on derived contexts that are not precomputed. A CS-nested profile will look exactly the same with regular nested profile except that each nested profile can come with an attributes. With pseudo probes, a nested profile shown as below can also have a CFG checksum. ``` main:1968679:12 2: 24 3: 28 _Z5funcAi:18 3.1: 28 _Z5funcBi:30 3: _Z5funcAi:1467398 0: 10 1: 10 _Z8funcLeafi:11 3: 24 1: _Z8funcLeafi:1467299 0: 6 1: 6 3: 287884 4: 287864 _Z3fibi:315608 15: 23 !CFGChecksum: 138828622701 !Attributes: 2 !CFGChecksum: 281479271677951 !Attributes: 2 ``` Specific work included in this change: - A recursive profile converter to convert CS flat profile to nested profile. - Extend function checksum and attribute metadata to be stored in nested way for text profile and extbinary profile. - Unifiy sample loader inliner path for CS and preinlined nested profile. - Changes in the sample loader to support probe-based nested profile. I've seen promising results regarding build time. A nested profile can result in a 20% shorter build time than a CS flat profile while keep an on-par performance. This is with -duplicate-contexts-into-base=1. Test Plan: Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D115205
2021-11-30[memprof] Extend llvm-profdata to display MemProf profile summaries.Snehasish Kumar1-5/+19
This commit adds initial support to llvm-profdata to read and print summaries of raw memprof profiles. Summary of changes: * Refactor shared defs to MemProfData.inc * Extend show_main to display memprof profile summaries. * Add a simple raw memprof profile reader. * Add a couple of tests to tools/llvm-profdata. Differential Revision: https://reviews.llvm.org/D114286
2021-10-27[CSSPGO] Trim cold base profiles for the CS preinliner.Hongtao Yu1-1/+1
Adding support to the CS preinliner to trim cold base profiles. This makes trimming consistent with the inline decision made by the preinliner. Also disable the existing profile merger when preinliner is on unless explicitly specified. Reviewed By: wenlei, wlei Differential Revision: https://reviews.llvm.org/D112489