From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37521 invoked by alias); 9 Dec 2016 13:00:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 37376 invoked by uid 89); 9 Dec 2016 13:00:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=distinguished, maintained, Hx-languages-length:3886 X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Dec 2016 13:00:16 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7ACCFC14; Fri, 9 Dec 2016 05:00:08 -0800 (PST) Received: from localhost (e105548-lin.manchester.arm.com [10.45.32.67]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 25F803F477 for ; Fri, 9 Dec 2016 05:00:08 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [11/67] Add a float_mode_for_size helper function References: <87h96dp8u6.fsf@e105548-lin.cambridge.arm.com> Date: Fri, 09 Dec 2016 13:00:00 -0000 In-Reply-To: <87h96dp8u6.fsf@e105548-lin.cambridge.arm.com> (Richard Sandiford's message of "Fri, 09 Dec 2016 12:48:01 +0000") Message-ID: <8760mtntpl.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2016-12/txt/msg00781.txt.bz2 This provides a type-safe way to ask for a float mode and get it as a scalar_float_mode. gcc/ 2016-11-24 Richard Sandiford Alan Hayward David Sherwood * coretypes.h (opt_scalar_float_mode): New typedef. * machmode.h (float_mode_for_size): New function. * emit-rtl.c (double_mode): Delete. (init_emit_once): Use float_mode_for_size. * stor-layout.c (layout_type): Likewise. diff --git a/gcc/coretypes.h b/gcc/coretypes.h index f4c1859..8341cab 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -58,6 +58,7 @@ typedef const struct rtx_def *const_rtx; class machine_mode; class scalar_float_mode; template class opt_mode; +typedef opt_mode opt_scalar_float_mode; /* Subclasses of rtx_def, using indentation to show the class hierarchy, along with the relevant invariant. diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c index 3bcafbb..efddad4 100644 --- a/gcc/emit-rtl.c +++ b/gcc/emit-rtl.c @@ -71,7 +71,6 @@ struct target_rtl *this_target_rtl = &default_target_rtl; machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */ machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */ -machine_mode double_mode; /* Mode whose width is DOUBLE_TYPE_SIZE. */ machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */ /* Datastructures maintained for currently processed function in RTL form. */ @@ -5864,7 +5863,7 @@ init_emit_once (void) { int i; machine_mode mode; - machine_mode double_mode; + scalar_float_mode double_mode; /* Initialize the CONST_INT, CONST_WIDE_INT, CONST_DOUBLE, CONST_FIXED, and memory attribute hash tables. */ @@ -5908,7 +5907,7 @@ init_emit_once (void) else const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE); - double_mode = mode_for_size (DOUBLE_TYPE_SIZE, MODE_FLOAT, 0); + double_mode = *float_mode_for_size (DOUBLE_TYPE_SIZE); real_from_integer (&dconst0, double_mode, 0, SIGNED); real_from_integer (&dconst1, double_mode, 1, SIGNED); diff --git a/gcc/machmode.h b/gcc/machmode.h index 996f991..41a3a00 100644 --- a/gcc/machmode.h +++ b/gcc/machmode.h @@ -513,7 +513,16 @@ extern const unsigned char mode_complex[NUM_MACHINE_MODES]; extern machine_mode mode_for_size (unsigned int, enum mode_class, int); -/* Similar, but find the smallest mode for a given width. */ +/* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one + exists. */ + +inline opt_scalar_float_mode +float_mode_for_size (unsigned int size) +{ + return dyn_cast (mode_for_size (size, MODE_FLOAT, 0)); +} + +/* Similar to mode_for_size, but find the smallest mode for a given width. */ extern machine_mode smallest_mode_for_size (unsigned int, enum mode_class); diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 834cf8b..2cde94e 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -2132,14 +2132,16 @@ layout_type (tree type) break; case REAL_TYPE: - /* Allow the caller to choose the type mode, which is how decimal - floats are distinguished from binary ones. */ - if (TYPE_MODE (type) == VOIDmode) - SET_TYPE_MODE (type, - mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0)); - TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type))); - TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type))); - break; + { + /* Allow the caller to choose the type mode, which is how decimal + floats are distinguished from binary ones. */ + if (TYPE_MODE (type) == VOIDmode) + SET_TYPE_MODE (type, *float_mode_for_size (TYPE_PRECISION (type))); + scalar_float_mode mode = as_a (TYPE_MODE (type)); + TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (mode)); + TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (mode)); + break; + } case FIXED_POINT_TYPE: /* TYPE_MODE (type) has been set already. */