[compiler-rt][pgo] Add profile instrumentation test for coroutines (#213801)
This PR adds a compiler-rt test (`instrprof-coroutine-profile.cpp`) to
verify PGO profile counter generation and ingestion for C++20
coroutines.
During investigating the iFDO profile ingested for coroutine pass, we
found that the profile data contains entry counts for the original
coroutine function (`foo`), but lacks the entry counters for the split
`foo.resume` function.
After inspecting
[PassBuilderPipelines.cpp](https://github.com/llvm/llvm-project/blob/f7b7ec8d5542dcede1ae607aa74dfe36d7a3c530/llvm/lib/Passes/PassBuilderPipelines.cpp#L1273)
confirms that `PGOInstrumentationGen` runs before `CoroSplitPass`.
Therefore,
- 1) the iFDO profile correctly ingests and associates profile counters
with coroutine function `foo`.
- 2) Separate function entry counters for `foo.resume` are not expected
in the iFDO profile.
Added `compiler-rt/test/profile/instrprof-coroutine-profile.cpp` and use
`llvm-profdata show` verify coroutine profile data. The IR dump after
`PGOInstrumentationGen` confirms that the function entry count is
tracking by counter[6] in the 8-element counter for `foo`.
```llvm
coro.alloc: ; preds = %entry
call void @llvm.instrprof.increment(ptr @__profn__Z3fooi, i64 650973721613012168, i32 8, i32 6)
%2 = call i64 @llvm.coro.size.i64()
%call = call noalias noundef nonnull ptr @_Znwm(i64 noundef %2) #14
br label %coro.init
coro.init: ; preds = %coro.alloc, %entry
```
Co-authored-by: Jin Huang <jingold@google.com>
GitOrigin-RevId: 2f4043eb92f789541b483dec8c794ecd67d167c1
1 file changed