inline callsites whose function definitions are in different file?

LLVM (2.7 release version) provides 2 implementations for inlining function callsites:

- InlineSimple.cpp (-inline): inline simple callsites according to its cost analysis
- InlineAlways.cpp (-always-inline): inline all callsites that are marked with "always_inline" attribute.

They are both subclasses of Inline.cpp that assumes the function's definition (body) is in the same Module (file) as its callsites (that will be inlined).

I am now having a situation that the functions are defined in file1.c (Module1) but all callsites are spread in file2, file3, ...fileN. Would LLVM be able to inline such callsites at compile time?

I think the right approach is to conduct inlining at link time (via the LTO), but still wonder if it is possible to do it at compile time without heavy hacking.

Thank you

Chuck

1 Like

At compiler time while compiling file2.c, how would compile know about
function definition in file1.c ?

I don't, and the compiler doesn't neither, that is the problem, unless I do hacking at compile time.
E.g.:
- put all such function's definitions into file1.c
- force to compile file1.c 1st.
- when compiling file2.c:
   . read file1.bc
   . attach to file2's module
   - do inline analysis + inlining
   - detach the attached file1.bc functions
- repeat for other files.
...

But I don't think this is a good/elegant approach, thus asking the LLVM-Dev group.

Thank you

Chuck

This is what LTO does.

One difference is, usually LTO stitches all modules together before
inlining instead of individually attaching/detaching .bc files. This
is because what if file2.c uses a function from file9.c ?

Ya, I agree with you. The answer is, do such types of inlining at link time.

Thanks Devang

Chuck