[clangd-dev] Using clangd to retrieve backend optimization remarks

Laurin Brandner via clangd-dev clangd-dev at lists.llvm.org
Tue Sep 18 07:13:56 PDT 2018

Hi Sam,

Thank you very much for your help. I will prototype this and see where it goes :)

On 17 Sep 2018, 16:43 +0200, Sam McCall <sammccall at google.com>, wrote:
> Hi Laurin,
> I'm not really familiar with clang/LLVM backends, but here's a guess.
> The simplest idea is to change the existing code that parses the file and generates diagnostics.
> At least to prototype, I think you might want to change clangd::ClangdFrontendAction (in ClangdUnit.cpp) to subclass clang::EmitCodeGenOnlyAction (or one of the other CodeGenActions) instead of clang::SyntaxOnlyAction. And then add the relevant flags.
> However I'm not sure that's going to work well:
>  - with the backend enabled, everything is going to get a lot slower
>  - we have optimizations (like not parsing function bodies in the preamble) that probably aren't compatible with codegen
>  - doing codegen is probably going to force clang to deserialize all of the preamble, which is also slow
>  - obviously it means linking in the backend, which is quite a big thing for a release build if this is a niche feature
> For performance, I'm not sure how feasible it is to run codegen for code directly referenced by the main file only (again, not a backend person!), this would be the analogue to how we keep frontend diagnostics fast.
> We have a vague wish to support some more-expensive diagnostics (template expansions, clang-tidy analysis) that can't be computed every loop, but haven't come up with a good design yet.
> Cheers, Sam
> > On Mon, Sep 17, 2018 at 2:24 PM Laurin Brandner via clangd-dev <clangd-dev at lists.llvm.org> wrote:
> > > Hi,
> > >
> > > I’m fairly new to this community so I hope I’m not asking a very trivial question.
> > > Anyways, I’m looking into the possibility of returning optimization remarks like the option -Rpass=loop-vectorize would do. By looking at clangd’s source code I realized that clangd only preprocesses the project but does not really invoke the backend.
> > > Thus, I would like to implement an action that enables the output of optimization remarks. Could I maybe get some guidance on to what I need to do to achieve this? I saw that I most likely need to subclass Action but I’m not quite sure what subclass I should have a closer look at.
> > >
> > > Thanks a lot for any kind of help.
> > >
> > > Cheers,
> > > Laurin
> > > _______________________________________________
> > > clangd-dev mailing list
> > > clangd-dev at lists.llvm.org
> > > http://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/clangd-dev/attachments/20180918/f7dc4997/attachment.html>

More information about the clangd-dev mailing list