From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by sourceware.org (Postfix) with ESMTPS id 237ED385800D for ; Sun, 13 Dec 2020 23:59:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 237ED385800D Received: by mail-oi1-x243.google.com with SMTP id w124so14166875oia.6 for ; Sun, 13 Dec 2020 15:59:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=fIdtRU4OGChJDQ0gTf3nse1PkGajdchskfpH9Z7+QJw=; b=CvBTJx6F0qnw3JoeuttC+Oz5yc7Ei1f3b7p4aWFMMCe3g8T0qgWUGsO32E2Izsc+jx uieh1l9Gb7z6EYTC8BF71qmZqhOyxN7Qc8Xuu4g22ZA6dhFJZXfjoS6Xrmj/AL2wV820 0dDtJOf9yjJnRwd81Gqy77Us5gbcbGcCn6daYo+9ih6rjINEjaTcw1CfKw5i2P58gnoo hNOKl8y62/8P+4j7inpFuBG9+ntQbkZPxJwGlrJVrdDUdbMNALGytSu//Ij+yUCxWg3n MVUXXQpqB3EGEXA6L+t42mfFjTQ6fxV+ibXoXZNz3Hcx400ZYH7z0SDFgtk4s9nmFPER xy+A== X-Gm-Message-State: AOAM532qgLOJk1THSCIJH7YSFAmoyKsZYr8d/z3ksDirw0NnztWChBtB 02oGDvLvHZ5vXG2WkIC+X/E= X-Google-Smtp-Source: ABdhPJw9E+wUyulDPKSzXE51S3pGdv5V8ZZydl1jhOTw2497GUVw9gBF69kXNwTZ1v6Yc66tn6QEfw== X-Received: by 2002:aca:4257:: with SMTP id p84mr16022590oia.68.1607903946118; Sun, 13 Dec 2020 15:59:06 -0800 (PST) Received: from [192.168.0.41] (174-16-97-231.hlrn.qwest.net. [174.16.97.231]) by smtp.gmail.com with ESMTPSA id f14sm3760198oib.40.2020.12.13.15.59.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 13 Dec 2020 15:59:05 -0800 (PST) Subject: Re: [PATCH] add g_nonstandard_bool attribute for GIMPLE FE use To: Richard Biener , gcc-patches@gcc.gnu.org Cc: joseph@codesourcery.com References: From: Martin Sebor Message-ID: <905fd139-f616-b2f8-efe6-c6e0eed61e15@gmail.com> Date: Sun, 13 Dec 2020 16:59:04 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Dec 2020 23:59:08 -0000 On 12/11/20 2:02 AM, Richard Biener wrote: > This adds __attribute__((g_nonstandard_bool(precision))) to be able > to construct nonstandard boolean types which for the included testcase > is needed to simulate Ada and LTO interaction (Ada uses a 8 bit > precision boolean_type_node). This will also be useful for vector > unit testcases where we need to produce vector types with > non-standard boolean type components. > > -- > > Joseph, is using attributes a good enough way to extend the set of C > types for use of the GIMPLE FE? I chose to add a g_ prefix to > note use by the GIMPLE FE but since we can mix C and GIMPLE FE > functions in one TU those of course can leak into C functions > (and eventually lead to ICEs/issues there) - but the attribute is > simply ignored when not compiling with -fgimple. > > I figured there's no documentation about GIMPLE FE "extensions", > I'll see to write something as followup (there's a small section > in sourcebuild.texi and the -fgimple docs itself). I chose to > not document this attribute in the place we document attributes > supposed to be used in production. > > OK for trunk? "nonstandard" isn't a very descriptive name. The leading g_ prefix also looks a little too terse (is that supposed to stand dor GIMPLE?). I would suggest choosing a better name, say, bool_precision. Since there's also a build_nonstandard_integer_type, if extending the attribute to integers supported by the function could be similarly useful then simply "precision" might be sufficient. Martin > > I'll push the actual vectorizer fix for PR95582 separately, this > patch is only "needed" to add a testcase for the PR. > > Thanks, > Richard. > > 2020-12-11 Richard Biener > > PR tree-optimization/95582 > gcc/c-family/ > * c-attribs.c (c_common_attribute_table): Add entry for > g_nonstandard_bool. > (handle_g_nonstandard_bool_attribute): New. > > gcc/testsuite/ > * gcc.dg/pr95582.c: New testcase. > --- > gcc/c-family/c-attribs.c | 41 ++++++++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr95582.c | 19 ++++++++++++++++ > 2 files changed, 60 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/pr95582.c > > diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c > index f7dad7a91d7..be3009865b1 100644 > --- a/gcc/c-family/c-attribs.c > +++ b/gcc/c-family/c-attribs.c > @@ -161,6 +161,8 @@ static tree handle_copy_attribute (tree *, tree, tree, int, bool *); > static tree handle_nsobject_attribute (tree *, tree, tree, int, bool *); > static tree handle_objc_root_class_attribute (tree *, tree, tree, int, bool *); > static tree handle_objc_nullability_attribute (tree *, tree, tree, int, bool *); > +static tree handle_g_nonstandard_bool_attribute (tree *, tree, tree, int, > + bool *); > > /* Helper to define attribute exclusions. */ > #define ATTR_EXCL(name, function, type, variable) \ > @@ -274,6 +276,8 @@ const struct attribute_spec c_common_attribute_table[] = > { > /* { name, min_len, max_len, decl_req, type_req, fn_type_req, > affects_type_identity, handler, exclude } */ > + { "g_nonstandard_bool", 1, 1, false, true, false, true, > + handle_g_nonstandard_bool_attribute, NULL }, > { "packed", 0, 0, false, false, false, false, > handle_packed_attribute, > attr_aligned_exclusions }, > @@ -894,6 +898,43 @@ validate_attr_arg (tree node[2], tree name, tree newarg) > > /* Attribute handlers common to C front ends. */ > > +/* Handle a "g_nonstandard_bool" attribute; arguments as in > + struct attribute_spec.handler. */ > + > +static tree > +handle_g_nonstandard_bool_attribute (tree *node, tree name, tree args, > + int ARG_UNUSED (flags), bool *no_add_attrs) > +{ > + *no_add_attrs = true; > + if (!flag_gimple) > + { > + warning (OPT_Wattributes, "%qE attribute ignored", name); > + return NULL_TREE; > + } > + > + if (!TYPE_P (*node) || TREE_CODE (*node) != BOOLEAN_TYPE) > + { > + warning (OPT_Wattributes, "%qE attribute only supported on " > + "boolean types", name); > + return NULL_TREE; > + } > + > + unsigned HOST_WIDE_INT prec = HOST_WIDE_INT_M1U; > + if (tree_fits_uhwi_p (TREE_VALUE (args))) > + prec = tree_to_uhwi (TREE_VALUE (args)); > + if (prec > MAX_FIXED_MODE_SIZE) > + { > + warning (OPT_Wattributes, "%qE attribute with unsupported boolean " > + "precision", name); > + return NULL_TREE; > + } > + > + tree new_type = build_nonstandard_boolean_type (prec); > + *node = lang_hooks.types.reconstruct_complex_type (*node, new_type); > + > + return NULL_TREE; > +} > + > /* Handle a "packed" attribute; arguments as in > struct attribute_spec.handler. */ > > diff --git a/gcc/testsuite/gcc.dg/pr95582.c b/gcc/testsuite/gcc.dg/pr95582.c > new file mode 100644 > index 00000000000..cba3354557b > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr95582.c > @@ -0,0 +1,19 @@ > +/* { dg-do compile } */ > +/* { dg-options "-fgimple -O3" } */ > + > +typedef _Bool bool8 __attribute__((g_nonstandard_bool(8))); > + > +bool8 data[16]; > + > +void __GIMPLE(ssa) foo(int f) > +{ > + _Bool t; > + bool8 tp; > + > +__BB(2): > + t_2 = f_1(D) != 0; > + tp_3 = (bool8) t_2; > + data[0] = tp_3; > + data[1] = tp_3; > + return; > +} >