Does IR lightweight instrumentation work on source code coverage?

I’m looking for ways to reduce the binary size overhead from source code coverage instrumentation. I found there was a IR lightweight instrumentation when doing IR level instrumentation. From the overview, it looks like it should also help reduce the binary size with front end level instrumentation because it removes the __llvm_prf_names and __llvm_prf_data sections from the binary and then later retrieve those information from debug info.

So I followed these commands (using -fprofile-instr-generate -fcoverage-mapping instead) in https://discourse.llvm.org/t/instrprofiling-lightweight-instrumentation/59113/14:

$ clang++ -fprofile-instr-generate -fcoverage-mapping -mllvm -enable-name-compression=false  -mllvm -debug-info-correlate -mllvm --disable-vp=true -g a.cpp -o a-light-cov.out
$ ./a-light-cov.out
$ llvm-profdata merge -o default.profile --debug-info=a-light-cov.out default.profraw
warning: default.profraw: debug info for correlation is not necessary
error: no profile can be merged

Did I miss something here? Or is the lightweight instrumentation meant to be only useful for IRPGO?
@ellishg

Lightweight instrumentation does not support clang instrumentation (-fprofile-instr-generate). It only supports LLVM’s instrumentation (IRPGO) using -fprofile-generate.

It is theoretically possible to construct source coverage from IRPGO using debug info, but it would require a bit more work. For now, you can use llvm-profdata show --covered <file.profdata> to view the source files that have been executed.

Lightweight instrumentation does not support clang instrumentation (-fprofile-instr-generate ). It only supports LLVM’s instrumentation (IRPGO) using -fprofile-generate .

Are there features of lightweight PGO that we could incorporate into coverage? Obviously, we are not going to get source-accurate coverage info if we instrument the LLVM IR after optimization, and that is a correctness requirement for coverage.

I believe boolean counters were added as part of the lightweight PGO work, if I’m not mistaken, and that would help reduce overhead.

Are there features of lightweight PGO that we could incorporate into coverage? Obviously, we are not going to get source-accurate coverage info if we instrument the LLVM IR after optimization, and that is a correctness requirement for coverage.

I don’t think we can incorporate that into coverage, because the instrumentation happens after some optimizations. Coverage instrumentation needs to be done on clang AST level. So, we could borrow idea of debug info correlation to coverage and implement that to reduce the binary size overhead.

I believe boolean counters were added as part of the lightweight PGO work, if I’m not mistaken, and that would help reduce overhead.

gulfem’s patch implements boolean counters for coverage. Not sure if it’s close to complete or not.