[X86] Add new calling convention that guarantees tail call optimization
When the target option GuaranteedTailCallOpt is specified, calls with
the fastcc calling convention will be transformed into tail calls if
they are in tail position. This diff adds a new calling convention,
tailcc, currently supported only on X86, which behaves the same way as
fastcc, except that the GuaranteedTailCallOpt flag does not need to
enabled in order to enable tail call optimization.
Patch by Dwight Guth <dwight.guth@runtimeverification.com>!
Reviewed By: lebedev.ri, paquette, rnk
Differential Revision: https://reviews.llvm.org/D67855
llvm-svn: 373976
diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst
index 4e653ae..dce8462 100644
--- a/llvm/docs/BitCodeFormat.rst
+++ b/llvm/docs/BitCodeFormat.rst
@@ -794,6 +794,7 @@
* ``preserve_allcc``: code 15
* ``swiftcc`` : code 16
* ``cxx_fast_tlscc``: code 17
+ * ``tailcc`` : code 18
* ``x86_stdcallcc``: code 64
* ``x86_fastcallcc``: code 65
* ``arm_apcscc``: code 66
diff --git a/llvm/docs/CodeGenerator.rst b/llvm/docs/CodeGenerator.rst
index 343b987..75330a5 100644
--- a/llvm/docs/CodeGenerator.rst
+++ b/llvm/docs/CodeGenerator.rst
@@ -2068,12 +2068,12 @@
and PowerPC if:
* Caller and callee have the calling convention ``fastcc``, ``cc 10`` (GHC
- calling convention) or ``cc 11`` (HiPE calling convention).
+ calling convention), ``cc 11`` (HiPE calling convention), or ``tailcc``.
* The call is a tail call - in tail position (ret immediately follows call and
ret uses value of call or is void).
-* Option ``-tailcallopt`` is enabled.
+* Option ``-tailcallopt`` is enabled or the calling convention is ``tailcc``.
* Platform-specific constraints are met.
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index d9a3890..e797b1f 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -299,7 +299,7 @@
allows the target to use whatever tricks it wants to produce fast
code for the target, without having to conform to an externally
specified ABI (Application Binary Interface). `Tail calls can only
- be optimized when this, the GHC or the HiPE convention is
+ be optimized when this, the tailcc, the GHC or the HiPE convention is
used. <CodeGenerator.html#id80>`_ This calling convention does not
support varargs and requires the prototype of all callees to exactly
match the prototype of the function definition.
@@ -436,6 +436,14 @@
- On X86-64 RCX and R8 are available for additional integer returns, and
XMM2 and XMM3 are available for additional FP/vector returns.
- On iOS platforms, we use AAPCS-VFP calling convention.
+"``tailcc``" - Tail callable calling convention
+ This calling convention ensures that calls in tail position will always be
+ tail call optimized. This calling convention is equivalent to fastcc,
+ except for an additional guarantee that tail calls will be produced
+ whenever possible. `Tail calls can only be optimized when this, the fastcc,
+ the GHC or the HiPE convention is used. <CodeGenerator.html#id80>`_ This
+ calling convention does not support varargs and requires the prototype of
+ all callees to exactly match the prototype of the function definition.
"``cc <n>``" - Numbered convention
Any calling convention may be specified by number, allowing
target-specific calling conventions to be used. Target specific
@@ -10232,11 +10240,12 @@
Tail call optimization for calls marked ``tail`` is guaranteed to occur if
the following conditions are met:
- - Caller and callee both have the calling convention ``fastcc``.
+ - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``.
- The call is in tail position (ret immediately follows call and ret
uses value of call or is void).
- - Option ``-tailcallopt`` is enabled, or
- ``llvm::GuaranteedTailCallOpt`` is ``true``.
+ - Option ``-tailcallopt`` is enabled,
+ ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention
+ is ``tailcc``
- `Platform-specific constraints are
met. <CodeGenerator.html#tailcallopt>`_