<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 27, 2018 at 6:47 AM, Marianne Mailhot-Sarrasin via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_4929807762507386768WordSection1">
<p class="MsoNormal"><span lang="EN-CA">Hi,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA">I am looking at the Type Based Alias Analysis and I am trying to understand why, from what I see,
<i>pointsToConstantMemory()</i> never returns true. <u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA">It seems that this information should come from the TBAA metadata, in which the Access Tag has an optional 4th field to specify this information.
<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-CA">“Access tags are represented as MDNode s with either 3 or 4 operands. The first operand is an MDNode pointing to the node representing the base type. The second operand is an MDNode pointing
 to the node representing the access type. The third operand is a ConstantInt that states the offset of the access.
<u>If a fourth field is present, it must be a ConstantInt valued at 0 or 1. If it is 1 then the access tag states that the location being accessed is “constant” (<wbr>meaningpointsToConstantMemory <wbr>should return true; see <a href="https://llvm.org/docs/AliasAnalysis.html#OtherItfs" target="_blank"><span style="color:windowtext">other
 useful AliasAnalysis methods</span></a>). </u>The TBAA root of the access type and the base type of an access tag must be the same, and that is the TBAA root of the access tag.” (<a href="https://llvm.org/docs/LangRef.html#tbaa-metadata" target="_blank">https://llvm.org/docs/<wbr>LangRef.html#tbaa-metadata</a>)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA">But, from what I see, the CodeGenTBAA pass never sets this field.
</span><span style="font-size:9.5pt;font-family:Consolas;color:black">CodeGenTBAA</span><span lang="EN-CA">::</span><span style="font-size:9.5pt;font-family:Consolas;color:black">getAccessTagInfo(<wbr>)</span><span lang="EN-CA"> calls
</span><span style="font-size:9.5pt;font-family:Consolas;color:black">createTBAAStructTagNode()
</span><span lang="EN-CA">to create the access tag, but it does not pass the IsConstant parameter.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black"> 
</span><span style="font-size:9.5pt;font-family:Consolas;color:darkgreen">/// \brief Return metadata for a TBAA tag node with the given</span><span style="font-size:9.5pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black"> 
</span><span style="font-size:9.5pt;font-family:Consolas;color:darkgreen">/// base type, access type and offset relative to the base type.</span><span style="font-size:9.5pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black"> 
</span><span style="font-size:9.5pt;font-family:Consolas;color:#2b91af">MDNode</span><span style="font-size:9.5pt;font-family:Consolas;color:black"> *createTBAAStructTagNode(</span><span style="font-size:9.5pt;font-family:Consolas;color:#2b91af">MDNod<wbr>e</span><span style="font-size:9.5pt;font-family:Consolas;color:black">
 *</span><span style="font-size:9.5pt;font-family:Consolas;color:gray">BaseType</span><span style="font-size:9.5pt;font-family:Consolas;color:black">,
</span><span style="font-size:9.5pt;font-family:Consolas;color:#2b91af">MDNode</span><span style="font-size:9.5pt;font-family:Consolas;color:black"> *</span><span style="font-size:9.5pt;font-family:Consolas;color:gray">AccessType</span><span style="font-size:9.5pt;font-family:Consolas;color:black">,<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:9.5pt;font-family:Consolas;color:black">                              <wbr>   
</span><span style="font-size:9.5pt;font-family:Consolas;color:#2b91af">uint64_t</span><span style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span style="font-size:9.5pt;font-family:Consolas;color:gray">Offset</span><span style="font-size:9.5pt;font-family:Consolas;color:black">,
</span><span style="font-size:9.5pt;font-family:Consolas;color:blue">bool</span><span style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span style="font-size:9.5pt;font-family:Consolas;color:gray">IsConstant</span><span style="font-size:9.5pt;font-family:Consolas;color:black"> =
</span><span style="font-size:9.5pt;font-family:Consolas;color:blue">false</span><span style="font-size:9.5pt;font-family:Consolas;color:black">);</span><span lang="EN-CA"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA">So my questions are:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p>
<p class="m_4929807762507386768MsoListParagraph"><u></u><span lang="EN-CA"><span>-<span style="font:7.0pt "Times New Roman"">         
</span></span></span><u></u><span lang="EN-CA"> Is there any reason <i>IsConstant</i> is never set ?
<u></u><u></u></span></p>
<p class="m_4929807762507386768MsoListParagraph"><u></u><span lang="EN-CA"><span></span></span></p></div></div></blockquote><div><br></div><div>It should be set for global constants (but not global Constant objects, i believe).</div><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72"><div class="m_4929807762507386768WordSection1"><p class="m_4929807762507386768MsoListParagraph"><span lang="EN-CA"><span>-<span style="font:7.0pt "Times New Roman"">         
</span></span></span><u></u><span lang="EN-CA"> Would it be valid to set this information according to the const-qualifier of the data accessed, maybe by getting it from
</span><span style="font-size:9.5pt;font-family:Consolas;color:#2b91af">QualType</span><span style="font-size:9.5pt;font-family:Consolas;color:black">::isConstQualified()</span><span lang="EN-CA">so<wbr>mehow ?</span></p></div></div></blockquote><div><br></div><div>No, because even const objects are set once, and pointsToConstantMemory is about completely unchanging memory locations.   It's only true for llvm-level gllobal constants, functions, etc.</div><div>There's a long historical discussion on the llvm mailing list about the best way to mark that kind of thing as unchanging once it is initialized.</div><div>Various methods were proposed, i don't remember the end result.</div><div>But everyone seem to agree that at least *this* is not the way to do that.</div><div><br></div><div><br></div></div></div></div>