option similar to -finstrument-functions but for code blocks

Hi,

I'd like to track not just at the function level, but also at the code
block level. For example, for a if-else statement, I want to know when
the if-branch or else-branch is enter/exit.

Is there a clang option similar to -finstrument-functions for code blocks?

Alternatively, I could manually insert the code to the IR .ll file.

I see the generated .ll use the following function when
-finstrument-functions is enabled. Is there an equivalent function for
code blocks?

%1 = call i8* @llvm.returnaddress(i32 0), !dbg !10

You’re probably looking for the “coverage” builds of clang which add instrumentation in the IR:

https://clang.llvm.org/docs/SourceBasedCodeCoverage.html

(Details of the data you can get is at https://llvm.org/docs/CoverageMappingFormat.html).

I’m not sure there’s something built into LLVM that makes that happen, but I suggest looking into what the coverage-instrumented .ll files look like when clang does it.

Cheers

-- Dean

Peng Yu via llvm-dev <llvm-dev@lists.llvm.org> writes:

I'd like to track not just at the function level, but also at the code
block level. For example, for a if-else statement, I want to know when
the if-branch or else-branch is enter/exit.

Is there a clang option similar to -finstrument-functions for code blocks?

Are you looking for code coverage or profile information (block
execution counts)? Dean already replied with the code coverage
information. LLVM has a profile instrumentation pass which is run with
opt -profile-generate. This is gprof-style profiling. I don't know
offhand which (if any) clang option is hooked up to -profile-generate.

                           -David

Peng Yu via llvm-dev <llvm-dev@lists.llvm.org> writes:

> I'd like to track not just at the function level, but also at the code
> block level. For example, for a if-else statement, I want to know when
> the if-branch or else-branch is enter/exit.
>
> Is there a clang option similar to -finstrument-functions for code blocks?

Are you looking for code coverage or profile information (block
execution counts)? Dean already replied with the code coverage
information.

Not really. I don't care really the number of times an instruction is
called. I care about the control flow and I'd like to visualize it as
a graph. cfg is static. I'd like something dynamic which only shows
what is run.

Of course, having the additional information about the count should be
fine. But it is secondary.

Peng Yu via llvm-dev <llvm-dev@lists.llvm.org> writes:

I'd like to track not just at the function level, but also at the code
block level. For example, for a if-else statement, I want to know when
the if-branch or else-branch is enter/exit.

Is there a clang option similar to -finstrument-functions for code blocks?

Are you looking for code coverage or profile information (block
execution counts)? Dean already replied with the code coverage
information.

Not really. I don't care really the number of times an instruction is
called. I care about the control flow and I'd like to visualize it as
a graph. cfg is static. I'd like something dynamic which only shows
what is run.

Of course, having the additional information about the count should be
fine. But it is secondary.

As far as I can tell, what you want is a subset of the data that the coverage tooling provides.

Is there something else you’re looking for? Do you need temporal information as well, to see when a particular basic block is run? I don’t know if the coverage infrastructure gives that information, but I’m positive you can hook something up through the gcov infrastructure which David mentioned to install your own runtime handler when functions (and code blocks?) get executed.

LLVM has a profile instrumentation pass which is run with
opt -profile-generate. This is gprof-style profiling. I don't know
offhand which (if any) clang option is hooked up to -profile-generate.

                          -David

--
Regards,
Peng
_______________________________________________
LLVM Developers mailing list
llvm-dev@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-- Dean