This is an archive of the discontinued LLVM Phabricator instance.

[IROutliner] Adding support to properly handle musttail, swifttailcc and tailcc
Needs ReviewPublic

Authored by AndrewLitteken on Mar 2 2022, 10:04 PM.

Details

Summary

musttail functions and those with swifttailcc and tailcc calling conventions have to be handled specially when being outlined. This adds support of musttail function in the cases of these two calling conventions in particular.

Diff Detail

Event Timeline

AndrewLitteken created this revision.Mar 2 2022, 10:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 10:04 PM
AndrewLitteken requested review of this revision.Mar 2 2022, 10:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 10:04 PM

Do you think you could add a statistic which counts the number of tail calls emitted? And maybe some debug output that says that something will be handled as a tail call?

I'm not sure how often musttail/tailcc appears in the LLVM test suite, but this didn't introduce any asserts there, and all of the tests pass.

@aschwaighofer Can you think of any (open source) Swift programs we can test this on? :)

I'm not sure how often musttail/tailcc appears in the LLVM test suite, but this didn't introduce any asserts there, and all of the tests pass.

@aschwaighofer Can you think of any (open source) Swift programs we can test this on? :)

Is there a clang attribute?

ormris removed a subscriber: ormris.Mar 7 2022, 9:55 AM

Yeah, it looks like there's a clang attribute, but it isn't used anywhere in the LLVM test suite.

https://clang.llvm.org/docs/AttributeReference.html#musttail

llvm/lib/Transforms/IPO/IROutliner.cpp
2438
2729

Nit: You could just return this rather than explicitly returning true/false

2738
  • Can you add a comment explaining why we need to check the caller's CC as well?
  • Would it be faster to check this first, and then do the any_of?
  • What if every candidate except for the first is in a function with swifttailcc or tailcc? What happens then? Can you add a testcase for that?
2744

Could pull CandidateVec[0] out into a variable?

2749

Nit

2809

I think this needs a testcase?