Page MenuHomePhabricator

Add new 'flatten' LLVM attribute to fix clang's 'flatten' function attribute
Needs ReviewPublic

Authored by LevitatingLion on Sun, Nov 17, 4:05 PM.



This adds a new 'flatten' attribute, which works like 'always_inline' but applies recursively to inlined call sites. The addition was briefly discussed on the mailing list:

This patch also contains changes to clang, so that it uses the new LLVM attribute on functions marked with the clang attribute 'flatten'. Previously, clang marked all calls in such functions with 'always_inline'; in effect, only the first level of calls was inlined.

Currently this patch fails the '/llvm/test/Bitcode/highLevelStructure.3.2.ll' test. llvm-dis seems to be unable to correctly decode attributes stored in the bitcode when the new attribute is added, although other attributes don't seem to have required any handling of this problem, see or I speculated that's because this is the 65th attribute, so a bitmask indicating all attributes doesn't fit in 64 bit anymore.

Diff Detail

Event Timeline

LevitatingLion created this revision.Sun, Nov 17, 4:05 PM
arsenm added inline comments.Sun, Nov 17, 8:56 PM

It's not obvious to me what the flatten name means. flatteninline? recursive_alwaysinline? Something else?

Thank you for working on this!

LevitatingLion added inline comments.Mon, Nov 18, 7:34 AM

I agree. What about always_inline_recurse or always_inline_recursively?

We need more tests here.

For one, the flatten attribute is not necessary to pass the test.
Second, we need to check the corner cases, e.g. reduction with different cycle lengths.


I'd prefer always_inline_recursively or recursive_alwaysinline so far. Though something shorter would be fine too.
always_inline_rec maybe?