<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Dear Cristianno,<br>
<br>
Have you verified that some other pass is not adding the function
declarations back in after your pass is executed (e.g., by using
the -debug-pass=Executions argument to see what passes run after
your pass)?<br>
<br>
Also, does your doFinalization() method make other changes that
are persistent?<br>
<br>
Regards,<br>
<br>
John Criswell<br>
<br>
On 5/5/15 8:19 PM, Cristianno Martins wrote:<br>
</div>
<blockquote
cite="mid:CAPjL5Aciac-HtbY8UFDTW5PGXSD_3jp+t_6-GdG82Xe9Y3X2SQ@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
<div dir="ltr">Hello there,
<div><br>
</div>
<div>I'm writing some LLVM passes, and just ran into an
interesting situation: now, I don't know if I misunderstood
the way doFinalization is supposed to work, but I hope someone
could help =)</div>
<div><br>
</div>
<div>One of the transformations I wrote needed to replace some
instructions within the code, so I needed to clean up the code
after the process was completed. The pass basically swapped
some function calls (from the standard C library) with my own
implementation of those functions. Changing the code in this
way, though, creates some dead code (like those dead
prototypes that are not being used anymore).</div>
<div><br>
</div>
<div>I, then, implemented the "clean up" strategy overriding
doFinalization. Unfortunately, any modifications done to the
module in this method appears to be ignored by LLVM. I even
dumped the module directly from within the method, and could
see that the modifications were applied to that reference of
the module, but the .bc file opt wrote into does not retain
these changes.</div>
<div><br>
</div>
<div>Now, bear with me here: I know that other passes like DCE
could be used to clean the bytecode, but some of the code I
implemented in doFinalization actually needed to run only
once, and necessarily after the pass has finished: this is
where I check to see if there is some extra situation I need
to address, optimize some of the replaced instructions, and
verify if any of the functions that I want to remove had their
addresses taken by any instruction.</div>
<div><br>
</div>
<div>Also, doFinalization has a bool return type, but it doesn't
appear to have any different behavior if I return either value
=/ (I assumed the general idea would be "return true if the
module was modified in any way", like runOnFunction, but I
couldn't find anything to support that anywhere).</div>
<div><br>
</div>
<div>Thus, am I wrong about how to use doFinalization? If so, is
there any way to guarantee running some code only once and
only when a pass already finished its job?</div>
<div><br>
</div>
<div>Thanks in advance,</div>
<div><br>
</div>
<div>Oh, and before I forget, this is the version of the opt I'm
running:</div>
<div><br>
</div>
<div>
<div>LLVM (<a moz-do-not-send="true" href="http://llvm.org/">http://llvm.org/</a>):</div>
<div> LLVM version 3.7.0svn</div>
<div> DEBUG build with assertions.</div>
<div> Built May 4 2015 (00:18:21).</div>
<div> Default target: x86_64-apple-darwin14.3.0</div>
<div> Host CPU: sandybridge</div>
<div>
<div class="gmail_signature"><br>
--<br>
Cristianno Martins<br>
PhD Student of Computer Science<br>
University of Campinas<br>
<a moz-do-not-send="true"
href="mailto:cmartins@ic.unicamp.br" target="_blank">cmartins@ic.unicamp.br</a><br>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
</body>
</html>