TailCallKind

public enum TailCallKind

Optimization markers for tail call elimination.

  • No optimization tail call marker is present. The optimizer is free to infer one of the other tail call markers.

    Declaration

    Swift

    case none
  • Suggests that tail call optimization should be performed on this function. Note that this is not a guarantee.

    tail calls may not access caller-provided allocas, and may not access varargs.

    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.
    • The call is in tail position (ret immediately follows call and ret uses value of call or is void).
    • Tail call elimination is enabled in the target machine’s TargetOptions or is globally enabled in LLVM.
    • Platform-specific constraints are met.

    Declaration

    Swift

    case tail
  • Requires the tail call optimization be performed in order for this call to proceed correctly.

    Tail calls guarantee the following invariants:

    • The call will not cause unbounded stack growth if it is part of a recursive cycle in the call graph.
    • Arguments with the inalloca attribute are forwarded in place.
    • If the musttail call appears in a function with the thunk attribute and the caller and callee both have varargs, than any unprototyped arguments in register or memory are forwarded to the callee. Similarly, the return value of the callee is returned the the caller’s caller, even if a void return type is in use.

    mustTail calls may not access caller-provided allocas, and may not access varargs. Unlike tails, they are also subject to the following restrictions:

    • The call must immediately precede a ret instruction, or a pointer bitcast followed by a ret instruction.
    • The ret instruction must return the (possibly bitcasted) value produced by the call, or return void.
    • The caller and callee prototypes must match. Pointer types of parameters or return types may differ in pointee type, but not in address space.
    • The calling conventions of the caller and callee must match.
    • All ABI-impacting function attributes, such as sret, byval, inreg, returned, and inalloca, must match.
    • 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.

    Declaration

    Swift

    case mustTail
  • Prevents tail call optimizations from being performed or inferred.

    Declaration

    Swift

    case noTail
  • Retrieves the corresponding LLVMTailCallKind.

    Declaration

    Swift

    public var llvm: LLVMTailCallKind { get }