[PATCH] D70366: Add new 'flatten' LLVM attribute to fix clang's 'flatten' function attribute

Johannes Doerfert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 8 14:41:12 PDT 2020


jdoerfert added a comment.

In D70366#1970299 <https://reviews.llvm.org/D70366#1970299>, @LevitatingLion wrote:

> While adding tests to clang I realized the attribute is not working as intended when using an optimization level of zero, because clang adds the noinline attribute to all functions. In this case the optimizer cannot distinguish between functions originally marked noinline (where recursive always-inlining should stop) and those where clang added the attribute (where recursive always-inlining should continue).
>
> Is this acceptable? I think we should fix this, and recursively inline at optimization level zero. GCC's documentation on the flatten attribute states that "every call inside this function is inlined, if possible", clang's that calls are "inlined unless it is impossible to do so".
>
> Maybe we can add an additional string attribute when adding the noinline attribute to functions which are not marked noinline in the source code, something like "noinline-added-by-clang". I don't know if that's a legitimate use case for a string attribute, but it wouldn't be very invasive. What do you think?


TBH, I would issue a warning if we see `flatten` in O0 that says this will not work and be done with it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70366/new/

https://reviews.llvm.org/D70366





More information about the cfe-commits mailing list