10 Commits

Author SHA1 Message Date
Mircea Trofin
b15845c005
[ctxprof] dump profiles using yaml (for testing) (#123108)
This is a follow-up from PR #122545, which enabled converting yaml to contextual profiles.

This change uses the lower level yaml APIs because:
- the mapping APIs `llvm::yaml` offers don't work with `const` values, because they (the APIs) want to enable both serialization and deserialization
- building a helper data structure would be an alternative, but it'd be either memory-consuming or overly-complex design, given the recursive nature of the contextual profiles.
2025-01-15 16:49:59 -08:00
Mircea Trofin
6329355860
[ctxprof] Move test serialization to yaml (#122545)
We have a textual representation of contextual profiles for test scenarios, mainly. This patch moves that to YAML instead of JSON. YAML is more succinct and readable (some of the .ll tests should be illustrative). In addition, JSON is parse-able by the YAML reader.

A subsequent patch will address deserialization.

(thanks, @kazutakahirata, for showing me how to use the llvm YAML reader/writer APIs, which I incorrectly thought to be more low-level than the JSON ones!)
2025-01-10 18:04:25 -08:00
Kazu Hirata
e4e3ff5adc
[llvm] Use std::optional::value_or (NFC) (#109568) 2024-09-22 01:00:24 -07:00
Mircea Trofin
1022323c9b
[ctx_prof] Move the "from json" logic more centrally to reuse it from test. (#106129)
Making the synthesis of a contextual profile file from a JSON descriptor more reusable, for unittest authoring purposes.

The functionality round-trips through the binary format - no reason, currently, to support other ways of loading contextual profiles.
2024-08-27 15:43:05 -07:00
Mircea Trofin
cc7308a156
[ctx_prof] Make the profile output analyzable by llvm-bcanalyzer (#99563)
This requires output-ing a "Magic" 4-byte header. We also emit a block info block, to describe our blocks and records. The output of `llvm-bcanalyzer` would look like:

```
<BLOCKINFO_BLOCK/>
<Metadata NumWords=17 BlockCodeSize=2>
  <Version op0=1/>
  <Context NumWords=13 BlockCodeSize=2>
    <GUID op0=2/>
    <Counters op0=1 op1=2 op2=3/>
```

Instead of having `Unknown` for block and record IDs.
2024-07-23 08:59:07 -04:00
Mircea Trofin
fc8775e214 "Reapply "[ctx_profile] Profile reader and writer" (#92199)"
This reverts commit 2c54bf497f7d7aecd24f4b849ee08e37a3519611.

Fixed gcc-7 issue.
2024-05-15 12:47:00 -07:00
Mehdi Amini
2c54bf497f Revert "Reapply "[ctx_profile] Profile reader and writer" (#92199)"
This reverts commit c19f2c773b0e23fd623502888894add822079f63.

Broke the gcc-7 bot.
2024-05-15 11:44:50 -07:00
Mircea Trofin
c19f2c773b Reapply "[ctx_profile] Profile reader and writer" (#92199)
This reverts commit 03c7458a3603396d2d0e1dee43399d3d1664a264.

One of the problems was addressed in #92208

The other problem: needed to add `BitstreamReader` to the list of
link deps of `LLVMProfileData`
2024-05-15 10:59:35 -07:00
Mircea Trofin
03c7458a36
Revert "[ctx_profile] Profile reader and writer" (#92199)
Reverts llvm/llvm-project#91859

Buildbot failures.
2024-05-14 18:07:58 -07:00
Mircea Trofin
dfdc3dcbe7
[ctx_profile] Profile reader and writer (#91859)
Utility converting a profile coming from `compiler_rt` to bitstream, and
a reader.

`PGOCtxProfileWriter::write` would be used as the `Writer` parameter for
`__llvm_ctx_profile_fetch` API. This is expected to happen in user code,
for example in the RPC hanler tasked with collecting a profile, and
would look like this:

```
// set up an output stream "Out", which could contain other stuff
{
  // constructing the Writer will start the section, in Out, containing
  // the collected contextual profiles.
  PGOCtxProfWriter Writer(Out);
  __llvm_ctx_profile_fetch(&Writer, +[](void* W, const ContextNode &N) {
    reinterpret_cast<PGOCtxProfWriter*>(W)->write(N);
  });
  // Writer going out of scope will finish up the section.
}
```

The reader produces a data structure suitable for maintenance during IPO
transformations.
2024-05-14 18:01:23 -07:00