From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122660 invoked by alias); 22 Jun 2015 22:02:22 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 122647 invoked by uid 89); 22 Jun 2015 22:02:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.98.7 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: ovh.starynkevitch.net Message-ID: <558885E4.20706@starynkevitch.net> Date: Thu, 01 Jan 2015 00:00:00 -0000 From: Basile Starynkevitch User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: David Malcolm CC: jit@gcc.gnu.org Subject: Re: switches in GCC JIT? References: <558880D7.7080503@starynkevitch.net> <1435009326.13727.16.camel@surprise> In-Reply-To: <1435009326.13727.16.camel@surprise> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2015-q2/txt/msg00097.txt.bz2 On 06/22/2015 11:42 PM, David Malcolm wrote: > On Mon, 2015-06-22 at 23:40 +0200, Basile Starynkevitch wrote: >> Hello David & all >> >> I'm guessing that GCCJIT is able to emit switch like statements, e.g. >> using GIMPLE_SWITCH statements >> internally. > No, it doesn't. > >> But I don't understand how is it possible. It looks like >> gimple_build_switch does not occur in gcc/jit/ > Currently gcc/jit builds functions at the tree level and hands them off > to the gimplifier, so you wouldn't see that in any case. (in theory it > could be ported to directly generate gimple). > >> Are switch statements omitted from GCCJIT? > Yes. > >> If yes, why??? > I intentionally didn't implement them, to keep the API simpler. > > I've never run into a need for them when implementing jit-compilation, > and in theory they could be implemented using conditionals (albeit > without the nice optimizations that we have for lowering GIMPLE_SWITCH). > > There was some discussion about this here: > https://gcc.gnu.org/ml/jit/2014-q4/msg00116.html > >> David, do you intend to improve that? > Do you have a use-case for them? We can add them if we need them. Any language (MELT, Ocaml, Haskell, ....) having some pattern matching would use a lot of switches. Or most efficient implementations of Rete algorithm, or similar stuff when compiling Prolog-like or CLIPS-like rules. Also, translation of most finite state automatons is done by a switch (often a quite big one, with one case per each state). At last, any kind of "byte-code" interpreter uses switches. And many languages have a switch like construct, that would be trivial to translate to a GIMPLE_SWITCH, but painful to translate otherwise. All the bytecodes I know (e.g. JVM & Ocaml) have switch-like constructs, and it would be easy to translate them to a GIMPLE_SWITCH, and painful otherwise. BTW, if we don't have switches, we should at least have indirect jumps, and the ability to retrieve, as a label, the starting address of any basic block. (i.e. the equivalent of goto *ptr; and of &&label in C). If that is possible today, we need more documentation about that (at least saying that switch statements could be translated that way) And of course, leveraging on all the important optimizations done by GCC on GIMPLE_SWITCH is essential... Actually, I'm surprised you are asking what is the use case for switches. I feel they are obvious and numerous... I would be annoyed, e.g. if I could not use switches in my C++ or C code. Replacing a switch with a sequence of if is an annoyance, and is probably a major performance loss (unless GCC optimizations are clever enough to replace them with a switch; which might sometimes be true, but not always). Regards -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mine, sont seulement les miennes} ***