<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Billy,<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 23, 2019, at 4:46 PM, William Moses via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-family: Arial, sans-serif; font-size: 11pt;" class="">Hello all,</span><br class=""></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Arial, sans-serif;" class=""><br class=""></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Arial, sans-serif;" class="">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;" class=""> </span></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Arial, sans-serif;" class="">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 class=""></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 class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><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;" class=""> </span></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Arial, sans-serif;" class="">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;" class=""> </span></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Consolas;" class="">$ ./clang foobar.c -g
-Rannotations -O3</span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Consolas;" class=""> 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;" class=""><span style="font-size: 11pt; font-family: Consolas;" class=""> 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;" class=""> </span></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Consolas;" class="">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;" class=""> </span></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Consolas;" class="">double f(double* a) {</span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Consolas;" class=""> return a[0];</span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Consolas;" class="">}</span></div></div></div></blockquote><div><br class=""></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 class=""></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 class=""></div><div>Cheers,</div><div><br class=""></div><div>— </div><div>Francis</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><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;" class=""> </span></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Arial, sans-serif;" class="">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)" class="">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;" class=""> </span></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Arial, sans-serif;" class="">Cheers,</span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt; font-family: Arial, sans-serif;" class="">Billy Moses</span></div></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>