<div dir="ltr"><span class="gmail-im" style="color:rgb(80,0,80)"><div dir="ltr">On Thu, Nov 19, 2020 at 1:04 AM John McCall <<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>> wrote:<br></div></span><div class="gmail_quote"><span class="gmail-im" style="color:rgb(80,0,80)"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The main problem for this sort of optimization is that it is difficult<br>to do on an IR like LLVM’s, where the semantic relationships between<br>values that exist in the program have been lowered into a sequence of<br>primitive operations with no remaining structural relationship.</blockquote><div><br></div></span><div>I understand. I think one possible advantage though would be to optimize C++ shared_ptr as well when calling into C++ code (assuming that everything is done with a modified version of clang++), or to provide a C library with macros that will emit the ARC-intrinsics so that C-FFI can benefit from the same optimizations...</div><span class="gmail-im" style="color:rgb(80,0,80)"><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">Dealing with unrelated operations and retroactively attempting to infer<br>relationships, as LLVM IR must, turns it into a fundamentally difficult<br>analysis that often relies on semantic knowledge that isn’t expressed<br>in the IR, so that you’re actually reasoning about what happens under<br>a “well-behaved” frontend.<br></blockquote><div><br></div></span><div>Yes, so basically, if one chooses to do this within the LLVM IR then it might be difficult to share the ARC optimizations with other front ends.  I don't  intend to give direct access to the acquire/release or the ref-count value, so I think I can assume that the front end provides "well behaved" IR. I only plan on providing tests for refcount==1 (I guess weak_ptr requires tests for refcount==0 internally as well)</div><div><br></div><div>What I worry about with a custom IR is that generic programming can emit a lot of conditionals that should be resolved to true/false statically before doing the ARC passes. So if I write my own IR then I would have to implement much of what LLVM has.</div><div><br></div><div>But I guess what you are saying is that it will be a significant job either way...</div><div><br></div><div>(Also thanks to Florian for the OBJ-C pointers.)</div><font color="#888888"><div><br></div><div>Ola.</div><div><br></div></font></div></div>