Dear LLVMers, I am trying to use your inline pass, and I would like to know if it is possible to remove a function from the bitcode file once it is inlined. Basically, I try: $> opt -inline file2.bc > file2.in.bc and I see that all the functions have been inlined into the main procedure, inside file2.in.bc. However, the inlined function is still in the bitcode, even though it is unreachable from main. Is there a way to remove this unreachable function from the bitcode file? thank you very much, Gabriel -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111020/def23d05/attachment.html>
Hi Gabriel,> I am trying to use your inline pass, and I would like to know if it is > possible to remove a function from the bitcode file once it is inlined. > Basically, I try: > > $> opt -inline file2.bc > file2.in.bc > > and I see that all the functions have been inlined into the main procedure, > inside file2.in.bc. However, the inlined function is still in the bitcode, even > though it is unreachable from main. Is there a way to remove this unreachable > function from the bitcode file?probably your functions have external linkage (the default). This means that they may be called from outside your module. That is why it would be wrong to throw them away. However if you know that they aren't referenced from outside the module then you can give them internal linkage (see the LangRef for more linkage types). This is done automatically by tools like llvm-ld or the gold plugin that know that they are building the final program, and can compute which functions are really used externally and which are not (link time optimization). Ciao, Duncan.
On Thu, Oct 20, 2011 at 12:48 PM, Gabriel Quadros <gquadrossilva at gmail.com> wrote:> Dear LLVMers, > > I am trying to use your inline pass, and I would like to know if it is > possible to remove a function from the bitcode file once it is inlined. > Basically, I try: > > $> opt -inline file2.bc > file2.in.bc > > and I see that all the functions have been inlined into the main > procedure, inside file2.in.bc. However, the inlined function is still in the > bitcode, even though it is unreachable from main. Is there a way to remove > this unreachable function from the bitcode file? > > thank you very much, > > Gabriel >Try "-inline -internalize -globaldce", should do the trick. The -globaldce by itself is the pass that does what you want (remove unreachable functions among other things), but the -internalize marks all functions as internal (otherwise they're reachable via their exported symbols, and so globaldce cannot remove them). Hope this helps, ~Will
Will Dietz wrote:> On Thu, Oct 20, 2011 at 12:48 PM, Gabriel Quadros > <gquadrossilva at gmail.com> wrote: >> Dear LLVMers, >> >> I am trying to use your inline pass, and I would like to know if it is >> possible to remove a function from the bitcode file once it is inlined. >> Basically, I try: >> >> $> opt -inline file2.bc> file2.in.bc >> >> and I see that all the functions have been inlined into the main >> procedure, inside file2.in.bc. However, the inlined function is still in the >> bitcode, even though it is unreachable from main. Is there a way to remove >> this unreachable function from the bitcode file? >> >> thank you very much, >> >> Gabriel >> > > Try "-inline -internalize -globaldce", should do the trick. > > The -globaldce by itself is the pass that does what you want (remove > unreachable functions among other things), but the -internalize marks > all functions as internal (otherwise they're reachable via their > exported symbols, and so globaldce cannot remove them).Just "opt -internalize -inline" should suffice; the inliner will delete an internal function if it inlines all callers away. Nick