YaFeng  Luo
YaFeng Luo

Reputation: 101

Identify whether a function is inlined in the LLVM IR

We are instrumenting the source code at compile-time, based on the LLVM IR. In this procedure, we want to skip the functions that are already inlined (e.g., due to compile-time optimization).

How can we determine whether a function has been inlined in our LLVM pass?

Upvotes: 1

Views: 633

Answers (2)

YaFeng  Luo
YaFeng Luo

Reputation: 101

Well, we gradually noticed that the "inline" operation is in terms of the specific call site rather than the callee function. Thus, one function may not have an attribute of "inline". For each function, it may be inlined at some call points but called normally at other call points, so we shouldn't skip them in our instrument pass.

Upvotes: 0

arnt
arnt

Reputation: 9685

This seems rather vague and open to many interpretations...

One way to see whether foo() is inlined into bar() is to loop over the instructions in bar() and see whether any of them are call %foo or similar. If that is the case, then at least one call wasn't inlined, even if other calls may have been.

Another way is to look at the debug info. Suppose that foo() originates in foo.c lines 10 to 20. You can look at the debug info for all instructions in bar() and check whether any refer to lines 10-20 of foo.c. If any do, then at least one call was inlined, even if others were not.

I can think of at least two more ways, too, and I'm sure there are more. (Edit: I can think of three, including one quite nice way: Attach some unique metadata to the instructions in foo() early in the compilation and see where that metadata is found just before native codegen.)

Upvotes: 1

Related Questions