Always inline with O0

When the function is attributed with always_inline , and the code is compiled with -O0 , the compiler still decides to inline it. Where can I find this behavior implemented in the LLVM source code? I looked in InlineCost.cpp, AlwaysInliner.cpp, and Inliner.cpp passes but couldn’t find an answer to my question.
Any recommendations?

always_inline means always inline; that’s why it’s done at -O0.

Clang’s optimization pipelines are constructed in clang/lib/CodeGen/BackendUtil.cpp; the always-inliner is deliberately included in the O0 pipeline to maintain semantic correctness.

3 Likes