<div dir="ltr">Try add the internalize pass before populateFunctionPassManager. See inlined. <br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 19, 2015 at 7:15 PM, Russell Wallace via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">I'm working on a whole program optimizer that uses LLVM as a library, and one of the things I want to do is eliminate dead global functions and variables even when they are not local to a module. (This understandably doesn't happen by default because the optimizer has to assume it could be compiling a library rather than a program.)<br><br>I've actually written a function to do this, but then I came across InternalizePass which seems like it could allow my code to be discarded because it could flag globals as internal (in the presence of a main function, according to the documentation) which would allow the existing dead global elimination optimization pass to do the job.<br><br>It seems that InternalizePass is, again understandably, not enabled by default even when you select optimization level 3. How do you turn it on? I tried setting PrepareForLTO but that doesn't seem to do anything. Here's what I have so far:<br><br> legacy::FunctionPassManager FPM(&M);<br> legacy::PassManager MPM;<br><br> PassManagerBuilder Builder;<br> Builder.OptLevel = 3;<br> Builder.PrepareForLTO = true;<br> Builder.VerifyInput = true;<br> Builder.VerifyOutput = true;<br></div></blockquote><div><br></div>MPM.add(llvm::createInternalizePass(export_list));<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"> Builder.populateFunctionPassManager(FPM);<br> Builder.populateModulePassManager(MPM);<br><br> FPM.doInitialization();<br> for (Function &F : M)<br> FPM.run(F);<br> FPM.doFinalization();<br> MPM.run(M);<br><br></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>