<div dir="ltr"><div>Hello Łukasz,</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><div>I was wondering if it is possible to implement placing RO variables
within progmem sections. For now it is possible to just use
[[gnu::progmem]] and read variables using assembly<br></div></div></blockquote><div><br></div><div>This is already implemented, via address spaces. At the moment, the IR frontend can control which memory to place global variables in by declaring it with `addrspace(1)`, which will place the variable in read-only program memory. When omitted, LLVM assumes the default address space 0, which corresponds to read/write SRAM data memory.</div><div><br></div><div>The address space is tracked through all uses of the global variable, and the AVR backend will correctly select an 'LPM' instruction to load from program memory when the address space is one, otherwise it will emit an 'LD' instruction to load from data memory. You shouldn't need to implement this boilerplate yourself.</div><div><br></div><div>There are some good points here<br></div><div><ul><li><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Automatic placement of variables in __flash sections.</blockquote><div><ul><li>avr-rust issue: <a href="https://github.com/avr-rust/rust/issues/74">https://github.com/avr-rust/rust/issues/74</a></li><li>I'm a big fan of automatic placement of const/RO variables in flash memory, but there hasn't been very much critical debate of it, which makes me hesitant to build it into LLVM proper. As far as my reasoning has gone, I think we should be able to add a pass to do this safely, but whether it should be on by default needs more debate IMO<br></li></ul></div></li><li><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Take care of reading across 64KB boundary</blockquote><div><ul><li>Good point, we don't currently recognize the RAMP{X,Y,Z} IO registers, which are required for >64kb addressing.<br></li></ul></div></li><li><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">If a variable is const, it can be places automatically in some __flash section</blockquote></li><ul><li>Related to above - should this be on by default? Is there any possible codegen breakage it could cause?</li></ul></ul><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 10, 2019 at 3:16 AM Łukasz Kostka via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</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"><div style="overflow-wrap: break-word;">Hello.<div><br></div><div>I was wondering if it is possible to implement placing RO variables within progmem sections. For now it is possible to just use [[gnu::progmem]] and read variables using assembly. My proposal is to:</div><div><ul><li>Use those variables as any other, without creating assembly.</li><li>While reading them, compiler has all necessary knowledge where the variable is and can generate assembly</li></ul><div><br></div></div><div>Possible future improvements:</div><div><ul><li>Automatic placement of variables in __flash sections.</li><li>Take care of reading across 64KB boundary</li><li>If a variable is const, it can be places automatically in some __flash section</li></ul><div><br></div></div><div>AVR devices are old, but still widely used. This feature could improve code quality even further. </div><div><br></div></div>_______________________________________________<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>
</blockquote></div>