Page MenuHomePhabricator

[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

Unit TestsFailed

TimeTest
70 msx64 debian > LLVM.DebugInfo/AArch64::ir-outliner.ll
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/opt -verify -iroutliner -ir-outlining-no-cost < /var/lib/buildkite-agent/builds/llvm-project/llvm/test/DebugInfo/AArch64/ir-outliner.ll | /var/lib/buildkite-agent/builds/llvm-project/build/bin/llc -filetype=obj -mtriple=aarch64-- | /var/lib/buildkite-agent/builds/llvm-project/build/bin/llvm-dwarfdump - | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/llvm/test/DebugInfo/AArch64/ir-outliner.ll
60,070 msx64 debian > MLIR.Examples/standalone::test.toy
Script: -- : 'RUN: at line 1'; /usr/bin/cmake /var/lib/buildkite-agent/builds/llvm-project/mlir/examples/standalone -G "Ninja" -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DLLVM_ENABLE_LIBCXX=OFF -DMLIR_DIR=/var/lib/buildkite-agent/builds/llvm-project/build/lib/cmake/mlir ; /usr/bin/cmake --build . --target check-standalone | tee /var/lib/buildkite-agent/builds/llvm-project/build/tools/mlir/test/Examples/standalone/Output/test.toy.tmp | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/mlir/test/Examples/standalone/test.toy
60,050 msx64 debian > libFuzzer.libFuzzer::large.test
Script: -- : 'RUN: at line 3'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/var/lib/buildkite-agent/builds/llvm-project/compiler-rt/lib/fuzzer -m64 /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/fuzzer/LargeTest.cpp -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/fuzzer/X86_64DefaultLinuxConfig/Output/large.test.tmp-LargeTest

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?