From patchwork Tue Jun 30 20:58:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 489814 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 850031402B1 for ; Wed, 1 Jul 2015 06:58:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=AhT6aGDP; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=K2dCgg2ry47XfyrS BSBnHDCiS66bbWVQRAyY6pKozzLM2glSScOxyUfcYjHnpW7mPQtYqPADWpEqXC5o zBDogTEeJz5W+NjYYBdraAt1V+TtZ7suVXx9/+IAAVn0LlkUSUr+pTRUkmZcolN3 gKjL4P2BNn6+p12OYF+SuAb2eKg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=wVu/FGLV7lcZWOX7HHspwi 06F68=; b=AhT6aGDPcPXrM8NUHT5uui1s/sfzKzNvtSEJ4rWE5d7yhzkR6dwob+ jjMt6xjQuv5YB93s+YB/N3vE3zRel8iAv7z/YSKsHtq6Rsj6zN1h0r8cZRIuAmAu cbCi6DceuOY88LfBEe7g9UFVj2z95pl+L8XlSVFEfh9BWzKKu5AZo= Received: (qmail 79118 invoked by alias); 30 Jun 2015 20:58:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 79105 invoked by uid 89); 30 Jun 2015 20:58:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.2 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=no version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 30 Jun 2015 20:58:42 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-6-QKxRFCaJSauenQfqznHgfA-1 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 30 Jun 2015 21:58:37 +0100 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: RFA: Use target-insns.def for casesi and tablejump Date: Tue, 30 Jun 2015 21:58:37 +0100 Message-ID: <87lhf0oqv6.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: QKxRFCaJSauenQfqznHgfA-1 This patch uses target-insns.def to define casesi and tablejump. It's the first point in the series at which we need access to the instruction code, so the patch adds that to targetm as well. Bootstrapped & regression-tested on x86_64-linux-gnu and aarch64-linux-gnu. Also tested via config-list.mk. OK to install? Thanks, Richard gcc/ * target.def: Add code_for_* hooks. * gentarget-def.c (def_target_insn): Add TARGET_CODE_FOR_* macros. * defaults.h (HAVE_tablejump, gen_tablejump): Delete. * target-insns.def (casesi, tablejump): New targetm instruction patterns. * expr.c (try_casesi): Use them instead of HAVE_*/gen_* interface. (do_tablejump): Likewise. * stmt.c (expand_switch_as_decision_tree_p): Likewise. (expand_sjlj_dispatch_table): Likewise. * targhooks.c (default_case_values_threshold): Likewise. Index: gcc/target.def =================================================================== --- gcc/target.def 2015-06-30 21:57:42.678281095 +0100 +++ gcc/target.def 2015-06-30 21:57:42.674281140 +0100 @@ -5877,6 +5877,11 @@ HOOK_VECTOR_END (mode_switching) #include "target-insns.def" #undef DEF_TARGET_INSN +#define DEF_TARGET_INSN(NAME, PROTO) \ + DEFHOOKPOD (code_for_##NAME, "*", enum insn_code, CODE_FOR_nothing) +#include "target-insns.def" +#undef DEF_TARGET_INSN + /* Close the 'struct gcc_target' definition. */ HOOK_VECTOR_END (C90_EMPTY_HACK) Index: gcc/gentarget-def.c =================================================================== --- gcc/gentarget-def.c 2015-06-30 21:57:42.678281095 +0100 +++ gcc/gentarget-def.c 2015-06-30 21:57:42.674281140 +0100 @@ -189,6 +189,13 @@ def_target_insn (const char *name, const printf ("invalid_%s\n", suffix); else printf ("target_gen_%s\n", name); + + printf ("#undef TARGET_CODE_FOR_%s\n", upper_name); + printf ("#define TARGET_CODE_FOR_%s ", upper_name); + if (truth == 0) + printf ("CODE_FOR_nothing\n"); + else + printf ("CODE_FOR_%s\n", name); } int Index: gcc/defaults.h =================================================================== --- gcc/defaults.h 2015-06-30 21:57:42.678281095 +0100 +++ gcc/defaults.h 2015-06-30 21:57:42.670281186 +0100 @@ -1426,16 +1426,6 @@ #define STACK_CHECK_MAX_VAR_SIZE (STACK_ #define TARGET_VTABLE_USES_DESCRIPTORS 0 #endif -#ifndef HAVE_tablejump -#define HAVE_tablejump 0 -static inline rtx -gen_tablejump (rtx, rtx) -{ - gcc_unreachable (); - return NULL; -} -#endif - #endif /* GCC_INSN_FLAGS_H */ #endif /* ! GCC_DEFAULTS_H */ Index: gcc/target-insns.def =================================================================== --- gcc/target-insns.def 2015-06-30 21:57:42.678281095 +0100 +++ gcc/target-insns.def 2015-06-30 21:57:42.674281140 +0100 @@ -31,6 +31,7 @@ Instructions should be documented in md.texi rather than here. */ DEF_TARGET_INSN (canonicalize_funcptr_for_compare, (rtx x0, rtx x1)) +DEF_TARGET_INSN (casesi, (rtx x0, rtx x1, rtx x2, rtx x3, rtx x4)) DEF_TARGET_INSN (epilogue, (void)) DEF_TARGET_INSN (jump, (rtx x0)) DEF_TARGET_INSN (load_multiple, (rtx x0, rtx x1, rtx x2)) @@ -42,3 +43,4 @@ DEF_TARGET_INSN (return, (void)) DEF_TARGET_INSN (sibcall_epilogue, (void)) DEF_TARGET_INSN (simple_return, (void)) DEF_TARGET_INSN (store_multiple, (rtx x0, rtx x1, rtx x2)) +DEF_TARGET_INSN (tablejump, (rtx x0, rtx x1)) Index: gcc/expr.c =================================================================== --- gcc/expr.c 2015-06-30 21:57:42.678281095 +0100 +++ gcc/expr.c 2015-06-30 21:57:42.670281186 +0100 @@ -11058,14 +11058,6 @@ do_store_flag (sepops ops, rtx target, m && !TYPE_UNSIGNED (ops->type)) ? -1 : 1); } - -/* Stubs in case we haven't got a casesi insn. */ -#ifndef HAVE_casesi -# define HAVE_casesi 0 -# define gen_casesi(a, b, c, d, e) (0) -# define CODE_FOR_casesi CODE_FOR_nothing -#endif - /* Attempt to generate a casesi instruction. Returns 1 if successful, 0 otherwise (i.e. if there is no casesi instruction). @@ -11080,7 +11072,7 @@ try_casesi (tree index_type, tree index_ machine_mode index_mode = SImode; rtx op1, op2, index; - if (! HAVE_casesi) + if (! targetm.have_casesi ()) return 0; /* Convert the index to SImode. */ @@ -11124,7 +11116,7 @@ try_casesi (tree index_type, tree index_ create_fixed_operand (&ops[4], (default_label ? default_label : fallback_label)); - expand_jump_insn (CODE_FOR_casesi, 5, ops); + expand_jump_insn (targetm.code_for_casesi, 5, ops); return 1; } @@ -11197,7 +11189,7 @@ do_tablejump (rtx index, machine_mode mo vector = gen_const_mem (CASE_VECTOR_MODE, index); convert_move (temp, vector, 0); - emit_jump_insn (gen_tablejump (temp, table_label)); + emit_jump_insn (targetm.gen_tablejump (temp, table_label)); /* If we are generating PIC code or if the table is PC-relative, the table and JUMP_INSN must be adjacent, so don't output a BARRIER. */ @@ -11211,7 +11203,7 @@ try_tablejump (tree index_type, tree ind { rtx index; - if (! HAVE_tablejump) + if (! targetm.have_tablejump ()) return 0; index_expr = fold_build2 (MINUS_EXPR, index_type, Index: gcc/stmt.c =================================================================== --- gcc/stmt.c 2015-06-30 21:57:42.678281095 +0100 +++ gcc/stmt.c 2015-06-30 21:57:42.670281186 +0100 @@ -780,10 +780,6 @@ dump_case_nodes (FILE *f, struct case_no dump_case_nodes (f, root->right, indent_step, indent_level); } -#ifndef HAVE_casesi -#define HAVE_casesi 0 -#endif - /* Return the smallest number of different values for which it is best to use a jump-table instead of a tree of conditional branches. */ @@ -812,7 +808,7 @@ expand_switch_as_decision_tree_p (tree r /* If neither casesi or tablejump is available, or flag_jump_tables over-ruled us, we really have no choice. */ - if (!HAVE_casesi && !HAVE_tablejump) + if (!targetm.have_casesi () && !targetm.have_tablejump ()) return true; if (!flag_jump_tables) return true; @@ -1291,7 +1287,7 @@ expand_sjlj_dispatch_table (rtx dispatch of expanding as a decision tree or dispatch table vs. the "new way" with decrement chain or dispatch table. */ if (dispatch_table.length () <= 5 - || (!HAVE_casesi && !HAVE_tablejump) + || (!targetm.have_casesi () && !targetm.have_tablejump ()) || !flag_jump_tables) { /* Expand the dispatch as a decrement chain: Index: gcc/targhooks.c =================================================================== --- gcc/targhooks.c 2015-06-30 21:57:42.678281095 +0100 +++ gcc/targhooks.c 2015-06-30 21:57:42.674281140 +0100 @@ -1339,10 +1339,6 @@ default_target_can_inline_p (tree caller return ret; } -#ifndef HAVE_casesi -# define HAVE_casesi 0 -#endif - /* If the machine does not have a case insn that compares the bounds, this means extra overhead for dispatch tables, which raises the threshold for using them. */ @@ -1350,7 +1346,7 @@ default_target_can_inline_p (tree caller unsigned int default_case_values_threshold (void) { - return (HAVE_casesi ? 4 : 5); + return (targetm.have_casesi () ? 4 : 5); } bool