[cfe-dev] Iterating over a CFGBlock excluding subexpressions

Gábor Horváth via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 16 09:44:38 PDT 2020


How did you get the CFG? There is a build option called setAlwaysAdd that
you probably set before the CFG was built.

On Mon, 16 Mar 2020 at 17:13, Stefan Schulze Frielinghaus via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi all,
>
> Is there some way to iterate over a CFGBlock excluding subexpressions?
>
> Currently I iterate over a CFGBlock as e.g.
>
>    const CFGBlock *block;
>    /* ... */
>    for (const auto &I : *block) {
>      if (Optional<CFGStmt> S = I.getAs<CFGStmt>())
>        foo(const_cast<Stmt*>(S->getStmt()));
>    }
>
> where function foo *recursively* descends into statements.  This has the
> drawback that I visit some (sub)expressions twice: one time via the loop
> and
> another time by recursively descending into subexpressions via function
> foo.
> For example, a CFGBlock for a single statement e1=e2 looks as follows:
>
>    <begin>  (e2)  (e1)  (e1=e2)  <end>
>
> Therefore, I would first call foo for e2, then for e1, and in the end for
> e1=e2
> where I would recursively call foo for e1 and e2 again. Although they have
> been
> visited previously.
>
> Maybe this is not the supposed way to iterate over a CFGBlock?
>
> Cheers,
> Stefan
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200316/1708e8ba/attachment.html>


More information about the cfe-dev mailing list