<br><br><div class="gmail_quote">On Tue, Mar 8, 2011 at 4:07 PM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Mar 7, 2011, at 9:55 PM, 邓尧 wrote:<br>
> When the generated instructions of two functions "f()" & "g()" are the same(when templates are used it isn't unusual), could clang remove the function "f()" in the object file and translate "f()" calls to "g()" calls?<br>

<br>
</div>C and C++ require that almost all objects, including function objects, have different addresses. </blockquote><div>This isn't a big problem, just pad some nop/jmp instructions.<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
 In principle, we can detect cases where a program doesn't rely on the address of a function;  in other cases we can just emit one function as a tail call to the other.  There's actually already an LLVM optimization that does something like this, although I believe it's not enabled by default because detecting the equivalence of functions is very difficult to do quickly.<br>
</blockquote><div> </div><div>I know only a little about compilation theories, so the following possibly are just nonsense.<br>Detect equivalence of functions may be done at two different levels, one is at the IR level, the other is at the C++ function template level. The second one is useful because different instances of the same template should be the largest source of equivalence. To detect at the IR level: 1. get hash  of a functions (can we??? I have no idea on this).  2. sort the hash 3. search & compare. To detect at the C++ function template level is much more complicated, I currently don't know what situations should be considered. <br>
</div></div><br>