From patchwork Thu Jul 13 08:42:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 107598 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1926932qge; Thu, 13 Jul 2017 01:43:15 -0700 (PDT) X-Received: by 10.98.204.194 with SMTP id j63mr59454693pfk.137.1499935395782; Thu, 13 Jul 2017 01:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499935395; cv=none; d=google.com; s=arc-20160816; b=sl409snK6DcXdeSbZdDw2C1YJpDqAo23/69zxyTyP0ZTE81A522ciKAijsMXNUFwhd mFotFIge2kbhrTGhOyXEI9pwXBzbANHEN6OVW/li9AnejyTDnCfRW3oC/X8HXjtZgPIm dJCaG7udN22VAbOnLUKJe5SI9tJ7M8L1FJP57ohr6pSFPLS1xiZY08amVcgNLCPfnF6y YHBLLZBUa385EnAyuo73czwP589T+gNydh5Wt6M74Qhnks2qmFFIBOchpCfVZPAJ02J4 bPjlm+692T+DTeB4REK3yKkKuHOogBXoP3pYTiFztgp2xxgeMRX8FimukwPn/AUz35M1 +bsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=jCyLiFcBAADywL7i+teezl8j0wSODIHhGbfrImBdGPc=; b=v+kgVDeN0V0UWtjkqTMdQIJLHMdUkkhMnVeB78fbxJ//vgykP42wHUv2hneg0xV8o9 +ZYNLuzjj+1C/Rgrkg7cOfFVUWib7cwQccVGhTR7M+PxEveXFcc9oy7Dv8tD7UU3ycNK Zo5U6WQt3JOc0Mx30auHjNg4KFN5NiuYvrdxg8NvQQpkNPbhPMGQbh/ig4IM3dwMyCNP bEDOIzDZYgQklZ3Qdl/FTtPSaFkwfyVH15i7Qj2nOHA0uWlUjwdoR5rtUet27ufcqlUf UqboN8zjWSm7s4BFBOqRqi6WVjn54GUs8i+roLOMAiC0zZnzUuKF6TMBBxc6hcWCZ+Vl IXLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=GIy8s5KA; spf=pass (google.com: domain of gcc-patches-return-458002-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458002-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v11si3726385pfd.94.2017.07.13.01.43.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 01:43:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458002-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=GIy8s5KA; spf=pass (google.com: domain of gcc-patches-return-458002-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458002-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=TegtCRpsdCH1dVxPfrxPqlRWiI0yh cMhi3H3+2sXVXDzqGs3aHVcxe+fS4aza+7OyKGpCQ6uNxmtqWFBS0F8iv4j2lpAp GCritMw/Argc+cZCbJHX7jyTHNhbJQ4JAK9cf/yld0PK0hInJsJ9Sny/bLX/zEWm cMmz2faHHEJZeg= 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=0FFLJp6Mc2eJXamqtMv0AW2SSoo=; b=GIy 8s5KAlHMeA1J7EgeeAQAhYE8HXQl+OK/04NVP7FKp0deYj0rpLgEulGqfOtkMdix lsxXAuqGCkcmvw9Zvj8jKqIy7F4qbP5q7KuxCZhWswiEtUV8QgFeNh47tRrwXria b4Ju5TBmZ4MuqZpjNYqyVrRNfVkK9XPJpOkUN2O8= Received: (qmail 1580 invoked by alias); 13 Jul 2017 08:42:53 -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 387 invoked by uid 89); 13 Jul 2017 08:42:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f41.google.com Received: from mail-wm0-f41.google.com (HELO mail-wm0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 08:42:50 +0000 Received: by mail-wm0-f41.google.com with SMTP id f67so18042518wmh.1 for ; Thu, 13 Jul 2017 01:42:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=jCyLiFcBAADywL7i+teezl8j0wSODIHhGbfrImBdGPc=; b=mWCOqVg9WjBBrzTNH97sLlFOKZrxP2/8MyrVTIaJniQWvN/iGdaIYTy6FyO02XKFDY IqQaBNkVr4LnAZN5b8By8gfi05Muh2/dFi8vXIfW+Rq7BNJdT6MOpPanO1YxsqpsBSUU uPFrM/DLZ5Ef2fjpVPDjUihOu4c0xbnn5jRFkue+DWQjOv4Y2FbVFhK4iib+5zFdnPhH icUHY4gyvShdtANuTprXaDnVKfzejPJMCYkrVQEUpYiX2qG57xikcwfv+hRQior7dHmC K5LxhYGY5yBpijguZXbP01zSeAFiL9DaUM1/VEtPpGKSmWJOca9wJTDWM/8/4vxQefad B3uA== X-Gm-Message-State: AIVw111j1TzLMcGjCU3njddwjXW69lc/+qpgd3uLXm2l2eZVgIrW+APs oCUIxA/f4CcgTFTaxkUfcg== X-Received: by 10.28.138.13 with SMTP id m13mr1073542wmd.97.1499935368177; Thu, 13 Jul 2017 01:42:48 -0700 (PDT) Received: from localhost (92.40.249.184.threembb.co.uk. [92.40.249.184]) by smtp.gmail.com with ESMTPSA id r200sm4323355wmd.20.2017.07.13.01.42.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 01:42:47 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [12/77] Use opt_scalar_float_mode when iterating over float modes References: <8760ewohsv.fsf@linaro.org> Date: Thu, 13 Jul 2017 09:42:45 +0100 In-Reply-To: <8760ewohsv.fsf@linaro.org> (Richard Sandiford's message of "Thu, 13 Jul 2017 09:35:44 +0100") Message-ID: <87pod4loca.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This means that we know when accessing the modes that the size is a compile-time constant, even for SVE. It also enables stricter type safety in later patches. 2017-07-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * machmode.h (mode_iterator::start): Provide overload for opt_modes. (mode_iterator::iterate_p): Likewise. (mode_iterator::get_wider): Likewise. * expr.c (init_expr_target): Use opt_scalar_float_mode. gcc/ada/ * gcc-interface/misc.c (fp_prec_to_size): Use opt_scalar_float_mode. (fp_size_to_prec): Likewise. gcc/c-family/ * c-cppbuiltin.c (c_cpp_builtins): Use opt_scalar_float_mode. gcc/fortran/ * trans-types.c (gfc_init_kinds): Use opt_scalar_float_mode and FOR_EACH_MODE_IN_CLASS. Index: gcc/machmode.h =================================================================== --- gcc/machmode.h 2017-07-13 09:18:25.916974620 +0100 +++ gcc/machmode.h 2017-07-13 09:18:26.363931259 +0100 @@ -652,6 +652,16 @@ is_float_mode (machine_mode mode, T *flo { /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */ + template + inline void + start (opt_mode *iter, enum mode_class mclass) + { + if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode) + *iter = opt_mode (); + else + *iter = as_a (GET_CLASS_NARROWEST_MODE (mclass)); + } + inline void start (machine_mode *iter, enum mode_class mclass) { @@ -660,6 +670,13 @@ is_float_mode (machine_mode mode, T *flo /* Return true if mode iterator *ITER has not reached the end. */ + template + inline bool + iterate_p (opt_mode *iter) + { + return iter->exists (); + } + inline bool iterate_p (machine_mode *iter) { @@ -669,6 +686,13 @@ is_float_mode (machine_mode mode, T *flo /* Set mode iterator *ITER to the next widest mode in the same class, if any. */ + template + inline void + get_wider (opt_mode *iter) + { + *iter = GET_MODE_WIDER_MODE (**iter); + } + inline void get_wider (machine_mode *iter) { Index: gcc/expr.c =================================================================== --- gcc/expr.c 2017-07-13 09:18:22.928278591 +0100 +++ gcc/expr.c 2017-07-13 09:18:26.362931356 +0100 @@ -112,7 +112,6 @@ static HOST_WIDE_INT int_expr_size (tree init_expr_target (void) { rtx pat; - machine_mode mode; int num_clobbers; rtx mem, mem1; rtx reg; @@ -131,7 +130,7 @@ init_expr_target (void) pat = gen_rtx_SET (NULL_RTX, NULL_RTX); PATTERN (insn) = pat; - for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES; + for (machine_mode mode = VOIDmode; (int) mode < NUM_MACHINE_MODES; mode = (machine_mode) ((int) mode + 1)) { int regno; @@ -177,9 +176,11 @@ init_expr_target (void) mem = gen_rtx_MEM (VOIDmode, gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1)); - FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) + opt_scalar_float_mode mode_iter; + FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT) { - machine_mode srcmode; + scalar_float_mode mode = *mode_iter; + scalar_float_mode srcmode; FOR_EACH_MODE_UNTIL (srcmode, mode) { enum insn_code ic; Index: gcc/ada/gcc-interface/misc.c =================================================================== --- gcc/ada/gcc-interface/misc.c 2017-07-13 09:18:21.521430343 +0100 +++ gcc/ada/gcc-interface/misc.c 2017-07-13 09:18:26.361931453 +0100 @@ -1311,11 +1311,11 @@ enumerate_modes (void (*f) (const char * int fp_prec_to_size (int prec) { - machine_mode mode; + opt_scalar_float_mode mode; FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) - if (GET_MODE_PRECISION (mode) == prec) - return GET_MODE_BITSIZE (mode); + if (GET_MODE_PRECISION (*mode) == prec) + return GET_MODE_BITSIZE (*mode); gcc_unreachable (); } @@ -1325,11 +1325,11 @@ fp_prec_to_size (int prec) int fp_size_to_prec (int size) { - machine_mode mode; + opt_scalar_float_mode mode; FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) - if (GET_MODE_BITSIZE (mode) == size) - return GET_MODE_PRECISION (mode); + if (GET_MODE_BITSIZE (*mode) == size) + return GET_MODE_PRECISION (*mode); gcc_unreachable (); } Index: gcc/c-family/c-cppbuiltin.c =================================================================== --- gcc/c-family/c-cppbuiltin.c 2017-07-13 09:18:21.523430126 +0100 +++ gcc/c-family/c-cppbuiltin.c 2017-07-13 09:18:26.361931453 +0100 @@ -1186,9 +1186,10 @@ c_cpp_builtins (cpp_reader *pfile) if (flag_building_libgcc) { /* Properties of floating-point modes for libgcc2.c. */ - machine_mode mode; - FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) + opt_scalar_float_mode mode_iter; + FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT) { + scalar_float_mode mode = *mode_iter; const char *name = GET_MODE_NAME (mode); char *macro_name = (char *) alloca (strlen (name) Index: gcc/fortran/trans-types.c =================================================================== --- gcc/fortran/trans-types.c 2017-07-13 09:18:20.865501731 +0100 +++ gcc/fortran/trans-types.c 2017-07-13 09:18:26.363931259 +0100 @@ -363,6 +363,7 @@ #define NAMED_SUBROUTINE(a,b,c,d) \ gfc_init_kinds (void) { machine_mode mode; + opt_scalar_float_mode float_mode_iter; int i_index, r_index, kind; bool saw_i4 = false, saw_i8 = false; bool saw_r4 = false, saw_r8 = false, saw_r10 = false, saw_r16 = false; @@ -418,11 +419,11 @@ gfc_init_kinds (void) /* Set the maximum integer kind. Used with at least BOZ constants. */ gfc_max_integer_kind = gfc_integer_kinds[i_index - 1].kind; - for (r_index = 0, mode = MIN_MODE_FLOAT; mode <= MAX_MODE_FLOAT; - mode = (machine_mode) ((int) mode + 1)) + r_index = 0; + FOR_EACH_MODE_IN_CLASS (float_mode_iter, MODE_FLOAT) { - const struct real_format *fmt = - REAL_MODE_FORMAT (mode); + scalar_float_mode mode = *float_mode_iter; + const struct real_format *fmt = REAL_MODE_FORMAT (mode); int kind; if (fmt == NULL) @@ -433,8 +434,7 @@ gfc_init_kinds (void) /* Only let float, double, long double and __float128 go through. Runtime support for others is not provided, so they would be useless. */ - if (!targetm.libgcc_floating_mode_supported_p ((machine_mode) - mode)) + if (!targetm.libgcc_floating_mode_supported_p (mode)) continue; if (mode != TYPE_MODE (float_type_node) && (mode != TYPE_MODE (double_type_node))