[llvm-dev] Finding label of basic block where a conditional branch merges

David Greene via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 29 14:38:33 PST 2019

Sebastian Roland via llvm-dev <llvm-dev at lists.llvm.org> writes:

> Joshua, David
> much appreciate your quick help!
> What I am actually doing is statically tracing values. If one of the
> traced values is part of a condition (e.g. in an if statement) all
> instructions in the then and else part are also traced. The automatic
> tracing of instructions however needs to stop when I hit the first
> instruction after the if statement (same for switch).
> Dominators seem to be a good starting point!

It sounds like you're looking for a control dependence analysis (which
Instructions/BasicBlocks are dependent on the outcome of some branch and
thus on the value input into the branch).  That can be computed from the
"post-dominance frontier" of the graph
(https://en.wikipedia.org/wiki/Data_dependency#Control_Dependency).  I
don't think LLVM has a post-dominance frontier built-in, but it has a
regular ol' DominanceFrontier.  It should be possible to adapt that to
do what you want.

Good luck!


More information about the llvm-dev mailing list