Timmmm
Timmmm

Reputation: 96625

Clang --coverage and -fprofile options

Clang has a few options related to coverage-style profiling. The command line reference doesn't really say what any of them do:

--coverage
-fprofile-arcs
-fprofile-instr-generate
-ftest-coverage
-fcoverage-mapping

According to the llvm-cov docs --coverage enables -fprofile-arcs and -ftest-coverage and maybe more.

Both -fprofile-.. flags add instrumentation in some way to record execution counts, but do they do exactly the same thing? If so why have both?

The llvm-cov docs say to use -fprofile-arcs with llvm-cov gcov but -fprofile-instr-generate with llvm-cov show. Why? What is going on here?

And what do -fcoverage-mapping and -ftest-coverage do exactly?

Upvotes: 11

Views: 4196

Answers (1)

Timmmm
Timmmm

Reputation: 96625

I started reading the code, and as far as I can tell:

--coverage enables -ftest-coverage, -fprofile-arcs, and also adds -u__llvm_runtime_variable on Linux, or something like that.

-fprofile-arcs and -fprofile-instr-generate are different. The former adds -femit-coverage-data and the latter adds -fprofile-instrument=clang (other options are "none" or "llvm").

-ftest-coverage adds -femit-coverage-notes

-fcoverage-mapping adds -fcoverage-mapping

Then the options have the following effect:

ProfileNone,       // Profile instrumentation is turned off.
ProfileClangInstr, // Clang instrumentation to generate execution counts
                   // to use with PGO.
ProfileIRInstr,    // IR level PGO instrumentation in LLVM.

So that answers some questions, but there does indeed seem to be two totally different profiling systems and I'm not sure of the difference.

Upvotes: 11

Related Questions