[cfe-dev] LLVM- AST contents display and dependency analysis

Reid Kleckner rnk at google.com
Thu May 14 10:24:52 PDT 2015


On Wed, May 13, 2015 at 12:28 PM, Renato Golin <renato.golin at linaro.org>
wrote:

> On 13 May 2015 at 17:53, Reid Kleckner <rnk at google.com> wrote:
> > If you want the AST, you want to use libTooling or libclang to
> > programmatically examine the AST. The -ast-dump flag will print the AST
> for
> > debugging purposes, but it cannot be deserialized.
>
> Hi Reid,
>
> Apologies for the lack of context. I sent him here. :)
>

No problem. :)


> Basically, he wants something similar to OpenMP (parallel loops,
> separate threads, multi-core CPUs) but without having to specify
> pragmas and command line options.
>
> My assumption is that, doing it at the IR level, it's already too
> late, because there's a lot of OpenMP that is Clang-based. So, if he
> could add a pass (possibly out-of-tree), that could identify loops and
> mark them with OpenMP pragmas (as they are, when the pragmas exist in
> the source), then he could benefit from OpenMP without requiring the
> users to add the pragmas to their sources or add command-line options
> to their Makefiles.
>
> In theory, if the toolchain he distributes has lib*omp in the right
> place, it should be completely transparent.
>
> Are my assumptions in the right track?
>

I think you are on the right track, but this is going to be really hard due
to the current design of OpenMP in Clang. A lot of OpenMP processing
happens in Sema right now, like formation of CapturedStmts. There also
isn't any alias analysis at the AST level, so separating dependent
computations will be hard.

Is this tool intended to run automatically, or as a programmer aide to
insert pragmas based on a potentially optimistic analysis? If it's a
programmer aide, I wonder if you could use the Clang CFG to the dependency
analysis.

If you want it to be just as semantics preserving as a regular optimizer
pass, then you probably want to analyze the loop in IR, figure out where
the loop header came from in the source code, grovel around in the AST for
that source location (maybe metadata can help?), and do some kind of
rewrite and recompile.

Another thing you might be able to do is have Clang parse all loop bodies
as CapturedStmts (this will outline all loop bodies for easy
parallelization), and then parallelize loops later. You'll need a way of
re-inlining the loops you decide not to parallelize. OpenMP currently has
some logic for this in Clang IRGen, but this is probably too early for your
purposes.

You might *also* be able to do the outlining completely in LLVM IR time
with LoopExtractor, but I assume there's a reason that OpenMP isn't using
that code.

Hope that helps.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150514/46ff3d72/attachment.html>


More information about the cfe-dev mailing list