7 Commits

Author SHA1 Message Date
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