<div dir="ltr"><div>Hey Wilhelm,</div><div><br></div><div>Raising a bug on <a href="http://bugs.llvm.org" target="_blank">bugs.llvm.org</a> sounds good to me.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Is there anything I can do about it?</div></blockquote><div><br></div><div>If you look at the AVR backend and figure out why the unnecessary instructions are emitted, it shouldn't be too hard to skip them. I suspect the code that generates this lives in 'llvm/lib/Target/AVR/AVRFrameLowering.cpp'. Look specifically for the 'emitPrologue' and 'emitEpilogue' functions.</div><div><br></div><div>If you can identify some subset of instructions which can be skipped for ISRs, add the appropriate conditionals and pop a review on <a href="http://reviews.llvm.org" target="_blank">reviews.llvm.org</a>.</div><div><br></div><div>Most of the backend work thus far has been focused on correctness rather than efficiency, and so there is a lot of low hanging fruit laying there.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>BTW: gcc is loosing the AVR backend, so I would assume, there will be a<br>
greater interest to this in llvm compared to the past.</div></blockquote><div><br></div><div>The GCC backend died of bitrot so perhaps not, although there does seem to be a bit more activity here. Historically almost all users of the AVR backend were using frontends other than clang, so I suspect it Clang+AVR will get a good stress testing now.<br></div><div><br></div><div>Regards,</div><div>Dylan<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 9, 2020 at 7:46 AM Wilhelm Meier <<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Is there anything I can do about it?<br>
<br>
BTW: gcc is loosing the AVR backend, so I would assume, there will be a<br>
greater interest to this in llvm compared to the past.<br>
<br>
Thanks,<br>
 Wilhelm<br>
<br>
Am 03.04.20 um 15:09 schrieb Wilhelm Meier via llvm-dev:<br>
> Should I create an issue in bugzilla for this? Just to be reminded ...<br>
> <br>
> Am 31.03.20 um 09:34 schrieb Wilhelm Meier via llvm-dev:<br>
>> Hi Dylan,<br>
>><br>
>> looks ok now.<br>
>><br>
>> One thing:<br>
>><br>
>> the ISR is now:<br>
>><br>
>> __vector_21:                            ; @__vector_21<br>
>> __vector_21$local:<br>
>> sei<br>
>> push    r0<br>
>> push    r1<br>
>> in      r0, 63<br>
>> push    r0<br>
>> clr     r0<br>
>> push    r24<br>
>> lds     r24, v1<br>
>> sts     v2, r24<br>
>> pop     r24<br>
>> pop     r0<br>
>> out     63, r0<br>
>> pop     r1<br>
>> pop     r0<br>
>> reti<br>
>><br>
>> There are unneccessary push/pops of r1 and r0 too, since the clr is<br>
>> useless ... GCC had the same problem but they made improvements.<br>
>><br>
>> Thanks.<br>
>><br>
>><br>
>> Am 31.03.20 um 08:09 schrieb Wilhelm Meier via llvm-dev:<br>
>>> Hi Dylan,<br>
>>><br>
>>> thank you. I'll be back with a test ...<br>
>>><br>
>>> Wilhelm<br>
>>><br>
>>> Am 31.03.20 um 08:06 schrieb Dylan McKay:<br>
>>>> Hey Wilhelm,<br>
>>>><br>
>>>> That's a bug, the "interrupt" attribute is not being recognized by the<br>
>>>> backend.<br>
>>>><br>
>>>> I have fixed it in<br>
>>>> <a href="https://github.com/llvm/llvm-project/commit/339b34266c1b54a9b5ff2f83cfb1da9cd8c9d90a" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/339b34266c1b54a9b5ff2f83cfb1da9cd8c9d90a</a><br>
>>>><br>
>>>> Pull the latest LLVM and it should be fixed.<br>
>>>><br>
>>>><br>
>>>> On Tue, Mar 31, 2020 at 8:00 AM Wilhelm Meier <<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a><br>
>>>> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>>> wrote:<br>
>>>><br>
>>>>     Hi Dylan,<br>
>>>><br>
>>>>     I used the following commandline:<br>
>>>><br>
>>>>     clang++ -Os -DF_OSC=20000000 -DF_CPU=20000000 --target=avr  -I.<br>
>>>>     -I../include0 -I../../include0 -I../../../include0 -I../../include0/std<br>
>>>>     -I../include0/std -I../../../include0/std -I../../3rdparty/boost<br>
>>>>     -I/usr/avr/include -mmcu=atmega328p<br>
>>>>     /home/lmeier/Projekte/wmucpp/clang/bm00/bm00.cc -S -emit-llvm --output<br>
>>>>     <a href="http://bm00.ir" rel="noreferrer" target="_blank">bm00.ir</a> <<a href="http://bm00.ir" rel="noreferrer" target="_blank">http://bm00.ir</a>><br>
>>>><br>
>>>>     Please find the IR attached in the file <a href="http://bm00.ir" rel="noreferrer" target="_blank">bm00.ir</a> <<a href="http://bm00.ir" rel="noreferrer" target="_blank">http://bm00.ir</a>><br>
>>>><br>
>>>>     Thanks,<br>
>>>>      Wilhelm<br>
>>>><br>
>>>><br>
>>>>     Am 30.03.20 um 13:44 schrieb Dylan McKay:<br>
>>>>     > Hey Wilhelm,<br>
>>>>     ><br>
>>>>     > Could you post the LLVM IR generated from your C++ file?<br>
>>>>     ><br>
>>>>     > This can be achieved with 'clang -S -emit-llvm'<br>
>>>>     ><br>
>>>>     > Cheers<br>
>>>>     ><br>
>>>>     > On Sat, Mar 28, 2020 at 6:36 PM Wilhelm Meier<br>
>>>>     <<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>><br>
>>>>     > <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>>>><br>
>>>>     wrote:<br>
>>>>     ><br>
>>>>     >     Answering partly to myself there was a extern "C" missing.<br>
>>>>     ><br>
>>>>     >     But the register pushes ans reti are still missing.<br>
>>>>     ><br>
>>>>     >     Whats wrong?<br>
>>>>     ><br>
>>>>     >     Am 28.03.20 um 06:26 schrieb Wilhelm Meier via llvm-dev:<br>
>>>>     >     > Hi Dylan,<br>
>>>>     >     ><br>
>>>>     >     > the following code<br>
>>>>     >     ><br>
>>>>     >     > volatile uint8_t v1;<br>
>>>>     >     > volatile uint8_t v2;<br>
>>>>     >     ><br>
>>>>     >     > __attribute__((interrupt)) void __vector_21(void)  {<br>
>>>>     >     >     v2 = v1;<br>
>>>>     >     > }<br>
>>>>     >     ><br>
>>>>     >     > produces in C mode:<br>
>>>>     >     ><br>
>>>>     >     > 00000092 <__vector_21>:<br>
>>>>     >     > 92:   80 91 61 00     lds     r24, 0x0061     ; 0x800061 <v1><br>
>>>>     >     > 96:   80 93 60 00     sts     0x0060, r24     ; 0x800060<br>
>>>>     <__data_end><br>
>>>>     >     > 9a:   08 95           ret<br>
>>>>     >     ><br>
>>>>     >     > and in C++ mode:<br>
>>>>     >     ><br>
>>>>     >     > 00000074 <_Z11__vector_21v>:<br>
>>>>     >     > 74:   80 91 60 00     lds     r24, 0x0060     ; 0x800060<br>
>>>>     <__data_end><br>
>>>>     >     > 78:   80 93 61 00     sts     0x0061, r24     ; 0x800061 <v2><br>
>>>>     >     > 7c:   08 95           ret<br>
>>>>     >     ><br>
>>>>     >     > So, in C++ mode it is not recognized as ISR due to name<br>
>>>>     mangling.<br>
>>>>     >     ><br>
>>>>     >     > Furthermore there are no register push/pos and no reti.<br>
>>>>     >     ><br>
>>>>     >     > Whats wrong?<br>
>>>>     >     ><br>
>>>>     >     > Thanks.<br>
>>>>     >     ><br>
>>>>     >     ><br>
>>>>     >     > Am 11.03.20 um 08:13 schrieb Dylan McKay:<br>
>>>>     >     >> Here you go Wilhelm,<br>
>>>>     >     >><br>
>>>>     >     >> <a href="https://github.com/dylanmckay/clang-avr-libc-interrupt-example" rel="noreferrer" target="_blank">https://github.com/dylanmckay/clang-avr-libc-interrupt-example</a><br>
>>>>     >     >><br>
>>>>     >     >><br>
>>>>     >     >><br>
>>>>     >     >> On Thu, Mar 5, 2020 at 4:05 AM Wilhelm Meier<br>
>>>>     >     <<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>><br>
>>>>     <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>>><br>
>>>>     >     >> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a><br>
>>>>     <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a><br>
>>>>     <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>>>>><br>
>>>>     >     wrote:<br>
>>>>     >     >><br>
>>>>     >     >>     Am 04.03.20 um 13:28 schrieb Dylan McKay:<br>
>>>>     >     >><br>
>>>>     >     >>     ><br>
>>>>     >     >>     >   * *The C/C++ function needs to be declared with either<br>
>>>>     >     the calling<br>
>>>>     >     >>     >     convention avr-interrupt or<br>
>>>>     >     avr-non-blocking-interrupt.* Skipping<br>
>>>>     >     >>     >     this step will cause regular ret instructions to be<br>
>>>>     >     emitted for<br>
>>>>     >     >>     >     return-from-subroutine, instead of the required reti<br>
>>>>     >     for interrupt<br>
>>>>     >     >>     >     handlers. ISRs also have stricter requirements on<br>
>>>>     which<br>
>>>>     >     registers<br>
>>>>     >     >>     >     must not be clobbered after execution, which the<br>
>>>>     >     backend will<br>
>>>>     >     >>     handle<br>
>>>>     >     >>     >     properly by restoring all clobbered registers in the<br>
>>>>     >     interrupt<br>
>>>>     >     >>     >     handler epilogue<br>
>>>>     >     >>     >   * *The symbol names of the ISR function handlers must<br>
>>>>     >     match those<br>
>>>>     >     >>     >     referred to in avr-libc/avr-libgcc/crt*. This is<br>
>>>>     >     because the ISR<br>
>>>>     >     >>     >     table is specified in assembly inside the GCC AVR<br>
>>>>     CRT.<br>
>>>>     >     The way it<br>
>>>>     >     >>     >     works is that the external symbol references in<br>
>>>>     the CRT<br>
>>>>     >     object<br>
>>>>     >     >>     files<br>
>>>>     >     >>     >     are declared with an exotic linkage type that causes<br>
>>>>     >     the linker to<br>
>>>>     >     >>     >     skip linking of the symbols if they are undefined<br>
>>>>     >     references.<br>
>>>>     >     >>     If you<br>
>>>>     >     >>     >     chose a custom ISR table in a custom CRT or runtime<br>
>>>>     >     library, you<br>
>>>>     >     >>     >     would be free to choose ISR names as you pleased.<br>
>>>>     >     >>     ><br>
>>>>     >     >>     Thank you for your explanation. But I suspect I didn't<br>
>>>>     get it<br>
>>>>     >     right. Can<br>
>>>>     >     >>     you please provide an example?<br>
>>>>     >     >><br>
>>>>     >     >>     Thanks<br>
>>>>     >     >><br>
>>>>     >     > _______________________________________________<br>
>>>>     >     > LLVM Developers mailing list<br>
>>>>     >     > <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
>>>>     <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>><br>
>>>>     >     > <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>>>>     >     ><br>
>>>>     ><br>
>>>><br>
>>> _______________________________________________<br>
>>> LLVM Developers mailing list<br>
>>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
>>> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>>><br>
>> _______________________________________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
>> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
> <br>
<br>
</blockquote></div>