<div dir="ltr">Hi Francis,<div><br></div><div>I'm wondering if it makes more sense to have a single pass to emit attributes rather than making sure that this is emitted in all passes that could modify arguments. If memory serves there's more than just FunctionAttrs.</div><div><br></div><div>Cheers,</div><div>Billy</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 24, 2019 at 5:32 PM Francis Visoiu Mistrih <<a href="mailto:francisvm@yahoo.com">francisvm@yahoo.com</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;">Hi Billy,<br><div><br><blockquote type="cite"><div>On Jul 23, 2019, at 4:46 PM, William Moses via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="gmail-m_6726862875496400616Apple-interchange-newline"><div><div dir="ltr"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-family:Arial,sans-serif;font-size:11pt">Hello all,</span><br></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif"><br></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif">During the compilation
process, LLVM automatically derives various attributes about functions and
values (for example that a pointer is nonnull, a function is constant, etc)
that are used within a translation unit.</span></div><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif"> </span></p><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif">I propose adding a pass
to LLVM that allows front-ends to output derived attributes. Such a pass would
be useful both for developers and end users to debug programs, either learning
that an expected attribute was learned, or an unexpected attribute was learned
(for example a pointer never being written to).</span></div></div></div></blockquote><div><br></div><div>This sounds like a good idea! Would adding new optimization remarks to passes that modify the attributes work? For example, we could emit an “analysis” remark in FunctionAttrs::setDoesNotRecurse.</div><br><blockquote type="cite"><div><div dir="ltr"><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif"> </span></p><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif">Evidently the following
might not be the final interface, but one could imagine something like the
following:</span></div><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif"> </span></p><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Consolas">$ ./clang foobar.c -g
-Rannotations -O3</span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Consolas"> foobar.c:2:1: remark: derived following
attributes for function f: fn_attr("norecurse")
fn_attr("nounwind") fn_attr("readonly") arg_attr(0,
"nocapture") arg_attr(0, "readonly") [-Rannotations]</span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Consolas"> double f(double* a) {</span></div><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif"> </span></p><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Consolas">foobar.c:</span></div><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Consolas"> </span></p><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Consolas">double f(double* a) {</span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Consolas"> return a[0];</span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Consolas">}</span></div></div></div></blockquote><div><br></div><div>If this is emitted as an analysis remark as suggested above, clang -Rpass-analysis=functionattrs could display the remarks in a similar way.</div><div><br></div><div>This has also the advantage that it can be serialized to a file using -fsave-optimization-record without any extra work involved.</div><div><br></div><div>Cheers,</div><div><br></div><div>— </div><div>Francis</div><br><blockquote type="cite"><div><div dir="ltr"><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif"> </span></p><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif">A work in progress patch
implementing such an optimization remark is available here: <a href="https://reviews.llvm.org/D65169" style="color:rgb(5,99,193)" target="_blank">https://reviews.llvm.org/D65169</a></span></div><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif"> </span></p><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif">Cheers,</span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Arial,sans-serif">Billy Moses</span></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" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></div></blockquote></div><br></div></blockquote></div>