<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>There are no existing attributes for this in upstream, but you
can hook isAllocLikeFunction to get the effect you're looking for.</p>
<p>Philip<br>
</p>
<br>
<div class="moz-cite-prefix">On 11/17/2017 05:17 AM, Siddharth Bhat
via llvm-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAPipc=15CoE0eCsSbH6zT_=eabXb9sReAB=QSZ9JqqCF91ATFQ@mail.gmail.com">
<div dir="ltr">
<div>Hello all,</div>
<div>I have a custom allocator, and would like to teach LLVM
about its semantics. In particular, I would like LLVM to kill
allocations that are "dead", similar to dead <span
style="font-family:monospace">new in</span> C++.<br>
</div>
<div><br>
</div>
<div>Consider this example:</div>
<div><br>
</div>
<div><span style="font-family:monospace">; ModuleID =
'<stdin>'<br>
source_filename = "Module"<br>
<br>
; Function Attrs: inaccessiblememonly noinline norecurse
nounwind<br>
declare i8* @alloc(i64) local_unnamed_addr #0<br>
<br>
; Function Attrs: inaccessiblememonly noinline norecurse
nounwind<br>
declare void @useClosure(i8*) local_unnamed_addr #1<br>
<br>
; Function Attrs: alwaysinline norecurse nounwind<br>
define void @main() #1 {<br>
entry:<br>
%closure.raw = tail call noalias i8* @alloc(i64 8)<br>
%fn_slot = bitcast i8* %closure.raw to void ()**<br>
store void ()* @"case_ackerman(atom-3 atom-10)_alts", void
()** %fn_slot, align 8, !invariant.group !0<br>
tail call void @useClosure(i8* %closure.raw)<br>
;========<br>
; dead<br>
%closure.raw.i = tail call noalias i8* @alloc(i64 24)<br>
%fn_slot.i = bitcast i8* %closure.raw.i to void ()**<br>
store void ()* @"case_aint()_alts", void ()** %fn_slot.i,
align 8, !invariant.group !0<br>
;========<br>
ret void<br>
}<br>
<br>
; Function Attrs: alwaysinline<br>
declare void @"case_aint()_alts"() #2<br>
<br>
; Function Attrs: alwaysinline<br>
declare void @"case_ackerman(atom-3 atom-10)_alts"() #2<br>
<br>
attributes #0 = { inaccessiblememonly noinline norecurse
nounwind writeonly }<br>
attributes #1 = { alwaysinline norecurse nounwind }<br>
attributes #2 = { alwaysinline }<br>
<br>
!0 = distinct !{!0, !"closure_invariant_group"}</span><br>
-----</div>
<div><br>
</div>
<div>In my view, <span style="font-family:monospace">%closure.raw.i
</span>is a dead allocation<span style="font-family:monospace"><font
face="sans-serif">, because the memory returned by it is
not used anywhere. How do I communicate this fact to LLVM?</font></span></div>
<div><span style="font-family:monospace"><font face="sans-serif"><br>
</font></span></div>
<div><span style="font-family:monospace"><font face="sans-serif">I
tried seeing how clang does it, but I'm not sure - it
doesn't seem to have any attribute that would help, except
perhaps </font>builtin<font face="sans-serif">. Does LLVM
know about the special semantics of new?<br>
</font></span></div>
<div><span style="font-family:monospace"><font face="sans-serif"><br>
</font></span></div>
<div><span style="font-family:monospace"><font face="sans-serif">Cheers,</font></span></div>
<div><span style="font-family:monospace"><font face="sans-serif">~Siddharth.</font><br>
</span></div>
</div>
<div dir="ltr">-- <br>
</div>
<div class="gmail_signature" data-smartmail="gmail_signature">
<div dir="ltr">Sending this from my phone, please excuse any
typos!</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>