From patchwork Thu Jun 5 21:30:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 356597 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 7083F140087 for ; Fri, 6 Jun 2014 07:31:12 +1000 (EST) 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:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=jSMruUB+NXhqXRv8dV8TR2TywUY61 3YL9g0y+dDHjdKIZoxdzYFHmDpymHl++XtTVcmodHRNG0OhSCJrjTaeCzzxxkdvW jwkW2CF3YSqFoDRw09hRLYTRlyLW7BjNd129odnCmZYPmx3Djvt4bffMR2oQQwtr jPtYxyWgEc+wVs= 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:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=NAgLwiCGXhaYxwqk4MmH/1EMtYc=; b=wwL xUGgVpbzMyKZ4JIOGdCD/jBHI5wWtkiv0qPdpywCCMnSTTZU6E2luT8dpIzFrRib RxHKsQPrmFFQQUxYgl1PKdqo6RWHt3FKgt7maBIbkgDSnzgAZE19MpYsCo5+WcYb 22Uyvw3LmESegniI3BryDdIrqqNHrQKlhPIm+cEg= Received: (qmail 27943 invoked by alias); 5 Jun 2014 21:31:06 -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 27931 invoked by uid 89); 5 Jun 2014 21:31:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f52.google.com Received: from mail-wg0-f52.google.com (HELO mail-wg0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 05 Jun 2014 21:31:02 +0000 Received: by mail-wg0-f52.google.com with SMTP id l18so1864257wgh.35 for ; Thu, 05 Jun 2014 14:30:59 -0700 (PDT) X-Received: by 10.180.36.241 with SMTP id t17mr1977504wij.38.1402003859927; Thu, 05 Jun 2014 14:30:59 -0700 (PDT) Received: from localhost ([2.26.169.52]) by mx.google.com with ESMTPSA id p18sm56260630wik.3.2014.06.05.14.30.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jun 2014 14:30:59 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: [PATCH 3/8] Speed up constraint_satisfied_p References: <87sinj9hhy.fsf@talisman.default> Date: Thu, 05 Jun 2014 22:30:58 +0100 In-Reply-To: <87sinj9hhy.fsf@talisman.default> (Richard Sandiford's message of "Thu, 05 Jun 2014 22:24:57 +0100") Message-ID: <87fvjj9h7x.fsf@talisman.default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 After the earlier changes, the only important function that switches on constraint_num is constraint_satisfied_p (now constraint_satisfied_p_1). Since constraint_num is a dense enum, it seems faster to use a jump table instead. In many cases this allows the handling function to be a simple sibcall to something like a predicate. Richard gcc/ * genpreds.c (write_constraint_satisfied_p_1): Replace with... (write_constraint_satisfied_p_array): ...this new function. (write_tm_preds_h): Replace write_constraint_satisfied_p_1 with an array. (write_insn_preds_c): Update accordingly. Index: gcc/genpreds.c =================================================================== --- gcc/genpreds.c 2014-06-05 21:05:45.972964371 +0100 +++ gcc/genpreds.c 2014-06-05 21:05:49.372993717 +0100 @@ -1166,29 +1166,19 @@ #define GCC_TM_CONSTRS_H\n"); a CONSTRAINT_xxx constant to one of the predicate functions generated above. */ static void -write_constraint_satisfied_p_1 (void) +write_constraint_satisfied_p_array (void) { - struct constraint_data *c; - if (satisfied_start == num_constraints) return; - puts ("bool\n" - "constraint_satisfied_p_1 (rtx op, enum constraint_num c)\n" - "{\n" - " switch (c)\n" - " {"); - - FOR_ALL_CONSTRAINTS (c) - if (!c->is_register) - printf (" case CONSTRAINT_%s: " - "return satisfies_constraint_%s (op);\n", - c->c_name, c->c_name); - - puts (" default: break;\n" - " }\n" - " return false;\n" - "}\n"); + printf ("bool (*constraint_satisfied_p_array[]) (rtx) = {\n "); + for (unsigned int i = satisfied_start; i < num_constraints; ++i) + { + if (i != satisfied_start) + printf (",\n "); + printf ("satisfies_constraint_%s", enum_order[i]->c_name); + } + printf ("\n};\n\n"); } /* Write out the function which computes whether a given value matches @@ -1293,16 +1283,15 @@ #define GCC_TM_PREDS_H\n\ " return false;\n" "}\n"); else - printf ("extern bool constraint_satisfied_p_1 (rtx," - " enum constraint_num);\n" + printf ("extern bool (*constraint_satisfied_p_array[]) (rtx);\n" "\n" "/* Return true if X satisfies constraint C. */\n" "\n" "static inline bool\n" "constraint_satisfied_p (rtx x, enum constraint_num c)\n" "{\n" - " return c >= CONSTRAINT_%s" - " && constraint_satisfied_p_1 (x, c);\n" + " int i = (int) c - (int) CONSTRAINT_%s;\n" + " return i >= 0 && constraint_satisfied_p_array[i] (x);\n" "}\n" "\n", enum_order[satisfied_start]->name); @@ -1425,7 +1414,7 @@ write_insn_preds_c (void) write_lookup_constraint_array (); if (have_register_constraints) write_reg_class_for_constraint_1 (); - write_constraint_satisfied_p_1 (); + write_constraint_satisfied_p_array (); if (have_const_int_constraints) write_insn_const_int_ok_for_constraint ();