[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
GCCJIT and proper tail calls
- To: jit@gcc.gnu.org
- Subject: GCCJIT and proper tail calls
- From: Marc Nieper-WiÃkirchen <marc@nieper-wisskirchen.de>
- Date: Wed, 11 May 2016 09:38:12 +0200
- Authentication-results: sourceware.org; auth=none
- Delivered-to: listarch-jit@gcc.gnu.org
- Delivered-to: mailing list jit@gcc.gnu.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=q7IVPZC2+raZYetuyhUq/R+HSn/HyOPgN/F767JAZ98=; b=HTL51PTvQIkSSR4ekE62U3LBnxAZFRD2w/g0BZUEkITnmvoIVMtPDQZlVW4pdI3P3x r3cfoNuRpb3fzFtdxLiibtaZHjKas/Ciul/bCZEgnpC27Mp1pfrjf2Fd4jnxUrrKvovd YM647BQy3NTb40Bi+TJpOKhn2yP7dBMopmkRNx1hUvXGjNIVmeMDNGR+TTQDX5RhDo93 twmAfjqzxoNJubb7AC4RayxxXEX4uk7E6/F7BBM2/d5RV80YuEwo/UE5HBkyoZF9IM0g wh2Lyjp3JpNnEGgaiv92ByBWEWsTZNvF17HT0Ht+2LuSbwD1EeSk+liA3y6B6Q/tFgbb Dn4g==
- List-help: <mailto:jit-help@gcc.gnu.org>
- List-post: <mailto:jit@gcc.gnu.org>
- List-subscribe: <mailto:jit-subscribe@gcc.gnu.org>
- Mailing-list: contact jit-help@gcc.gnu.org; run by ezmlm
- Sender: jit-owner@gcc.gnu.org
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2
Last year there was a discussion on the gccjit mailing list whether it
is possible to guarantee the elimination of proper tail calls.
Compiling Scheme code with gccjit was given as an example because the
language demands proper tail call elimination (for example, loops are
usually implemented by recursive function calls).
The point I would like to make that proper tail call elimination on
gccjit's side remains crucial even if Scheme didn't ask for proper tail
call elimination: Scheme allows programs to get hold of the current
continuation of the program. One way to implement this is to globally
rewrite the program into continuation-passing style. In other words,
every call (outside of calling library functions) would become a proper
tail call. If gccjit chose not to eliminate the calls in favour of
jumps, the stack usage of the transformed program would be proportional
to its running time.
LLVM has the `musttail' marker
http://llvm.org/docs/LangRef.html#call-instruction
<http://llvm.org/docs/LangRef.html#call-instruction> to guarantee proper
tail call elimination independent of any optimization pass (or to signal
an error in case the requirements for the elimination are not met).
Such a thing should be possible for gccjit as well (so that the
aforementioned program in continuation-passing style would still work
even without an optimization pass eliminating non-marked proper tail calls).
--
Marc