How to split module into several ones

Hi all,

Can anyone give me advice about an appropriate way for extracting number of functions from module recursively (starting from entry point). Actually it may be more than one entry point so all dependent functions and global values must be extracted.

I’ve tried llvm-extract tool but it can’t do work recursively. Maybe it would be good to write some Call Graph pass or something. Any thoughts?

Thanks in advance,

Alexey Zasenko

I thought llvm-extract conservatively extracted anything that was relevant to what it was asked to extract. In any event, if you need a call graph analysis, there are two call graph passes available for LLVM. The first is the CallGraph pass that comes in the LLVM source tree. It is very conservative with function pointers, but its results are conservatively correct. The second is the CallGraph analysis within DSA. You should be able to find a copy for LLVM 3.7 or LLVM 3.8 here () and here (). Regards, John Criswell

Hi John,
Thanks for your answer.

The CallGraph pass did the work for me. But since I actually have several modules and my toolchain looked like

llvm-link

opt llc

I’ve found that llvm-lto is great for doing all the work: greedy linkage, optimization and further MC generation.
Here the command line I’m using for that:
llvm-lto -exported-symbol=main -save-merged-module -filetype=asm -o %t2 %t1
(I’ve attached corresponding llvm-lit test.)

Now I’m wondering if there is any possibility to use LTO within the linker like ld (mingw) to build a dynamic library from my IR code?

Best regards,

Alexey Zasenko

src1.ll (1.09 KB)

Hi John,
Thanks for your answer.

The CallGraph pass did the work for me. But since I actually have several
modules and my toolchain looked like

llvm-link
<CallGraph extraction pass>
opt
llc

I've found that llvm-lto is great for doing all the work: greedy linkage,
optimization and further MC generation.
Here the command line I'm using for that:
llvm-lto -exported-symbol=main -save-merged-module -filetype=asm <or obj>
-o %t2 %t1
(I've attached corresponding llvm-lit test.)

Now I'm wondering if there is any possibility to use LTO within the linker
like ld (mingw) to build a dynamic library from my IR code?

What is your ld version? The Gold ld can invoke LLVM's gold-plugin when
given bitcode input files, which will perform LTO. However, while the GNU
ld recently gained the ability to invoke LLVM's gold-plugin to do this for
bitcode, it is not a configuration we test, so I'd recommend Gold ld. Also,
LLVM's lld has support for bitcode inputs and will also invoke LTO. For the
gold plugin, see http://llvm.org/docs/GoldPlugin.html for ensuring it is
configured properly.

Teresa

What is your ld version?

I’ve used ld 2.23.1 from MinGW package for my tests. This is quite old version. As far as I remember the gold-plugin is not supported on Windows for now.

As for linker, I need following features:

-ability to build windows dll

-ability to embed debug info compatible to gdb

-own crt (like MinGW has)

I’m going to try lld with MinGW crt again (my recent attempts failed for some reason)