From 66af1399963a1872e520d1dbd1c94fd43e65082d Mon Sep 17 00:00:00 2001 From: Cheng Shao Date: Mon, 12 Sep 2022 13:55:05 +0000 Subject: CmmToC: emit explicit tail calls when the C compiler supports it Clang 13+ supports annotating a return statement using the musttail attribute, which guarantees that it lowers to a tail call if compilation succeeds. This patch takes advantage of that feature for the unregisterised code generator. The configure script tests availability of the musttail attribute, if it's available, the Cmm tail calls will become C tail calls that avoids the mini interpreter trampoline overhead. Nothing is affected if the musttail attribute is not supported. Clang documentation: https://clang.llvm.org/docs/AttributeReference.html#musttail --- m4/fp_musttail.m4 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 m4/fp_musttail.m4 (limited to 'm4') diff --git a/m4/fp_musttail.m4 b/m4/fp_musttail.m4 new file mode 100644 index 0000000000..e309f44c7b --- /dev/null +++ b/m4/fp_musttail.m4 @@ -0,0 +1,16 @@ +# FP_MUSTTAIL +# ---------------------------------- +# Is the musttail attribute supported? +AC_DEFUN([FP_MUSTTAIL], +[ + AC_MSG_CHECKING([whether __attribute__((musttail)) is supported]) + echo 'extern int foo(void); int bar(void) { __attribute__((musttail)) return foo(); }' > conftest.c + if $CC -c conftest.c -o conftest.o + then + AC_MSG_RESULT([yes]) + AC_DEFINE(HAS_MUSTTAIL, 1, [Has musttail]) + else + AC_MSG_RESULT([no]) + fi + rm -f conftest.c conftest.o +]) -- cgit v1.2.1