Force a function to be inline in Clang/LLVM

后端 未结 5 1632
醉话见心
醉话见心 2021-02-05 11:39

Is there a way to force an inline function in Clang/LLVM?

AFAIK, the following is just a hint to the compiler but it can ignore the request.

__attribute_         


        
5条回答
  •  无人共我
    2021-02-05 12:20

    Just a few remarks that might be useful too.

    For the OP's comments:

    1. Multiple static inline definitions is a caveat because it can cause, upon changing one of them, multiple different functions that can cause lots of head-scratching, especially if inlining kicks in and the actual calls evaporate to different sequences of statements.
    2. This can have similar effects as 1.
    3. Inlining is an optimization and you can look into your compiler's manual to see when it kicks in (e.g. gcc doc page). Usually, it is in the first level. See also this answer.

    A useful discussion and recommendation can be found here. The advice for C99 is summed up as follows:

    1. In a header file define the following and include it wherever it's required:

      inline void foo() { /*...*/ }

    2. In a single source file declare it using extern to generate the external symbol:

      extern inline foo();

    As for the LLVM IR method proposed, it works but then you are passed the source language domain and subject to a different set of rules (highly dependent on the tool). A brief indicative discussion can be found here.

提交回复
热议问题