[PATCH] D103275: Update musttail verification to check all swiftasync->swiftasync tail calls.
Varun Gandhi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 27 16:47:58 PDT 2021
varungandhi-apple updated this revision to Diff 348417.
varungandhi-apple added a comment.
Removed stray `tee` command used for debugging.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103275/new/
https://reviews.llvm.org/D103275
Files:
llvm/docs/LangRef.rst
llvm/lib/IR/Verifier.cpp
llvm/test/Verifier/musttail-missing.ll
Index: llvm/test/Verifier/musttail-missing.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/musttail-missing.ll
@@ -0,0 +1,9 @@
+; REQUIRES: asserts
+; RUN: not llvm-as %s -enable-swifttailcc-musttail-check -o /dev/null 2>&1 | FileCheck %s
+
+declare swifttailcc void @swift_callee()
+define swifttailcc void @swift_caller() {
+; CHECK: tail call from swifttail->swifttail should be marked musttail
+ call swifttailcc void @swift_callee()
+ ret void
+}
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -3419,7 +3419,28 @@
return Copy;
}
+// FIXME: This flag should eventually be removed and the check should be on by
+// default.
+static cl::opt<bool> EnableSwiftTailCCMustTailCheck(
+ "enable-swifttailcc-musttail-check", cl::init(false),
+ cl::desc("Check that tail calls from swifttailcc functions to"
+ " swifttailcc functions are marked musttail."));
+
void Verifier::verifyMustTailCall(CallInst &CI) {
+ if (!CI.isMustTailCall()) {
+#ifndef NDEBUG
+ if (EnableSwiftTailCCMustTailCheck &&
+ CI.getCallingConv() == CallingConv::SwiftTail &&
+ CI.getCaller()->getCallingConv() == CallingConv::SwiftTail &&
+ isa_and_nonnull<ReturnInst>(CI.getNextNode())) {
+ Assert(false,
+ "tail call from swifttail->swifttail should be marked musttail",
+ &CI);
+ }
+#endif
+ return;
+ }
+
Assert(!CI.isInlineAsm(), "cannot use musttail call with inline asm", &CI);
// - The caller and callee prototypes must match. Pointer types of
@@ -3485,9 +3506,7 @@
void Verifier::visitCallInst(CallInst &CI) {
visitCallBase(CI);
-
- if (CI.isMustTailCall())
- verifyMustTailCall(CI);
+ verifyMustTailCall(CI);
}
void Verifier::visitInvokeInst(InvokeInst &II) {
Index: llvm/docs/LangRef.rst
===================================================================
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -11320,11 +11320,13 @@
This instruction requires several arguments:
-#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
- should perform tail call optimization. The ``tail`` marker is a hint that
- `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
- means that the call must be tail call optimized in order for the program to
- be correct. The ``musttail`` marker provides these guarantees:
+#. The optional ``tail`` and ``musttail`` markers (with one exception for
+ mandatory ``musttail`` when using ``swifttailcc``, see below) indicate that
+ the optimizers should perform tail call optimization. The ``tail`` marker is
+ a hint that `can be ignored <CodeGenerator.html#sibcallopt>`_. The
+ ``musttail`` marker means that the call must be tail call optimized in
+ order for the program to be correct. The ``musttail`` marker provides
+ these guarantees:
#. The call will not cause unbounded stack growth if it is part of a
recursive cycle in the call graph.
@@ -11354,6 +11356,8 @@
- The callee must be varargs iff the caller is varargs. Bitcasting a
non-varargs function to the appropriate varargs type is legal so
long as the non-varargs prefixes obey the other rules.
+ - ``musttail`` is mandatory for tail calls where both the caller and
+ the callee use the ``swifttailcc`` convention.
Tail call optimization for calls marked ``tail`` is guaranteed to occur if
the following conditions are met:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103275.348417.patch
Type: text/x-patch
Size: 3601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210527/19a46209/attachment.bin>
More information about the llvm-commits
mailing list