Compiling Multiple Files

Clangers,

What’s the best way to compile multiple files in one LLVM IR file? It doesn’t appear that clang supports the gcc -combine feature.

Hi Ryan,

I would just compile to multiple IR files then link them together with llvm-link.

Would that work for you?

Cheers,

James

I believe it might actually. Do you know if it’s possible to inline functions without an external node? It doesn’t appear to be so.

Hi Ryan,

Do you know if it's possible to inline functions without an external node?

Sorry, I don't know to what you're referring here. Could you please rephrase? what do you mean be "external node"?

Cheers,

James

James,

Sure. I want to inline functions in a C program that has no external node, or “main”. So the “top” function is not main and there does not exist a main in the file.

Thanks.

Hi Ryan,

I see. Well, that shouldn't be an issue. If you link the bitcode files together with llvm-link you can then do several things:

(1) Run clang on it as you normally would with -O3 for maximum inlining
(2) Run 'llc' manually with -O3 and LTO, which will do the maximum link time optimisations.
(3) Run 'opt' manually with -O3, LTO which will produce another bitcode file, which you can then again give to Clang to codegen.

Cheers,

James

James,

Thanks. It wouldn’t take the LTO option; however, I can get it to inline using -cppgen=inline.

However, when I run clang the second time it gives me an error, stating that it expects a top level entity. I think I’ve run into this issue before. Any ideas?

Hi Ryan,

Well, when linking, it'll need a top level entity. Else what is it going to link to? (unless you're building a shared library?)