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

Adam Nemet via clangd-dev clangd-dev at lists.llvm.org
Thu Sep 20 07:41:04 PDT 2018


Why do you want to use clangd for this rather than clang itself?  You will need to effectively perform full compiles for this which is clang’s job.  (The remarks are emitted by the various optimization passes *as* LLVM runs them.)

Adam


> On Sep 20, 2018, at 2:16 AM, Laurin Brandner <mail at laurinbrandner.ch> wrote:
> 
> Hi Jan,
> 
> Essentially, I want to create a vs code extension that annotates the code to display various optimization remarks. So for example, I would like to highlight a loop which clang wasn’t able to vectorize. Thus, I’m now trying to make clangd invoke the backend as well. 
> 
> Could you maybe share some hints that I can look into to make this work? Thank you very much in any case :)
> 
> Cheers,
> Laurin
>> On 19 Sep 2018, 17:43 +0200, Jan Korous <jkorous at apple.com>, wrote:
>> +backend guys
>> 
>> Hi Laurin,
>> 
>> Would you mind sharing more details about your project? What is your goal here?
>> 
>> Cheers,
>> 
>> Jan
>> 
>>> On 18 Sep 2018, at 15:13, Laurin Brandner via clangd-dev <clangd-dev at lists.llvm.org> wrote:
>>> 
>>> Hi Sam,
>>> 
>>> Thank you very much for your help. I will prototype this and see where it goes :)
>>> 
>>> Cheers,
>>> Laurin
>>>> 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
>>> _______________________________________________
>>> 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/20180920/67d4a960/attachment-0001.html>


More information about the clangd-dev mailing list