<div dir="ltr">My experience with LLVM is limited, but I am trying to figure out how to add optimizations for automatic reference counting. The GC documentation mentions that patch-points could be useful, but it does not state how they would be useful. If this is a FAQ, please let me know...<div><br></div><div>So this is my idea at this point:</div><div><br></div><div>The context is a C++ like language with an aggregate type that is always reference counted. The typesystem differentiate between pointers to objects that is shared between threads and those that does not. I also want a pass that turn shared_ptr to nonshared_ptr if it can be proven.</div><div><br></div><div>So what I want to do is to wrap up all the "events" that are relevant as intrinsics and run some simplification passes, then use the pointer capture/escape analysis that LLVM has to turn shared_ptrs to nonshared_ptrs and to elide nonatomic/atomic acquire/release. So basically, the intrinsics will be the type-annotation also.</div><div><br></div><div>The compilation will then follow this pattern:</div><div>1. generate LLVM IR</div><div>2. simplification passes</div><div>3. pass for turning shared_ptr to nonshared_ptr</div><div>4. pass for eliding acquire/release</div><div>5, pass that substitute the custom intrinsics to function call</div><div>6. full optimization passes</div><div><br></div><div>I think about having the following intrinsics:</div><div><br></div><div>ptr = cast_untyped_to_nonshared(ptr) // e.g. used after allocation</div><div>ptr = cast_to_shared_irreversible(ptr)  // basically a gateway to other threads</div><div>nonhared_acquire(ptr)</div><div>nonshared_release(ptr)</div><div>shared_acquire(ptr)</div><div>shared_release(ptr)</div><div><br></div><div>I also want weak_ptr at  a later stage, but leave it out for now to keep the complexity manageble.</div><div><br></div><div>Is this idea completely unreasonable?</div><div><br></div><div>Ola.<br></div><div><br></div></div>