From patchwork Tue Apr 27 15:32:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 1470787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=KHZFeAsu; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FV5Y04q8sz9sPf for ; Wed, 28 Apr 2021 01:39:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE8E4398E46C; Tue, 27 Apr 2021 15:39:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE8E4398E46C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1619537968; bh=fbq9FgvxrZu1qGKjDbFQNVZwtxdKlWNk4Nkh5WIc8nE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=KHZFeAsu9Cb4twVwY+zOakBo56R2GxUsLU5G1qG72TNpvU5I0Y4I7TOx6Qux66dfR wFwZk3YWzt0TBo6SWUkIyBfjkAR3lfU9AUN9IeK9TFVAern9jcsRSWfjX8IuWvEPfl OaribGmNrsTlVU1WGeOqbwvzK8mfXM/33qUtoCm8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 2029E394FC1E for ; Tue, 27 Apr 2021 15:39:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2029E394FC1E Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13RFWdBp044038; Tue, 27 Apr 2021 11:39:24 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 386jjb6x0m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 11:39:24 -0400 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13RFX0nR045213; Tue, 27 Apr 2021 11:39:23 -0400 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 386jjb6x09-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 11:39:23 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13RFHGGh025764; Tue, 27 Apr 2021 15:34:22 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma02dal.us.ibm.com with ESMTP id 384qdhyxmb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 15:34:22 +0000 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13RFYMUa32440796 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Apr 2021 15:34:22 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 041F56A058; Tue, 27 Apr 2021 15:34:22 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D37206A051; Tue, 27 Apr 2021 15:34:21 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.53.174.68]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTPS; Tue, 27 Apr 2021 15:34:21 +0000 (GMT) Received: by ltcden2-lp1.aus.stglabs.ibm.com (Postfix, from userid 1006) id 5720641397AD; Tue, 27 Apr 2021 10:34:21 -0500 (CDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 21/57] rs6000: Write output to the builtins init file, part 3 of 3 Date: Tue, 27 Apr 2021 10:32:56 -0500 Message-Id: <0871ae2385f8ba813623940667ffccd0ee2ee2bd.1619537141.git.wschmidt@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: VKsGkliOfrbvR6DOtP2rF2dbkHNRtqoG X-Proofpoint-ORIG-GUID: 2BexSh0Rfa8Qob9zKR_TBOIi5On-B1ok X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-27_08:2021-04-27, 2021-04-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 lowpriorityscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270108 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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-Patchwork-Original-From: Bill Schmidt via Gcc-patches From: Bill Schmidt Reply-To: Bill Schmidt Cc: jakub@redhat.com, Bill Schmidt , jlaw@tachyum.com, dje.gcc@gmail.com, segher@kernel.crashing.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 2021-03-03 Bill Schmidt gcc/ * config/rs6000/rs6000-gen-builtins.c (typemap): New struct. (TYPE_MAP_SIZE): New defined constant. (type_map): New initialized filescope variable. (map_token_to_type_node): New function. (write_type_node): Likewise. (write_fntype_init): Implement. --- gcc/config/rs6000/rs6000-gen-builtins.c | 173 ++++++++++++++++++++++++ 1 file changed, 173 insertions(+) diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c index 82c0567756b..7ef297d04f5 100644 --- a/gcc/config/rs6000/rs6000-gen-builtins.c +++ b/gcc/config/rs6000/rs6000-gen-builtins.c @@ -468,6 +468,106 @@ static rbt_strings fntype_rbt; identifiers to the order in which they were encountered. */ static rbt_strings bifo_rbt; +/* Mapping from type tokens to type node names. */ +struct typemap +{ + const char *key; + const char *value; +}; + +/* This table must be kept in alphabetical order, as we use binary + search for table lookups in map_token_to_type_node. The table + maps tokens from a fntype string to a tree type. For example, + in "si_ftype_hi" we would map "si" to "intSI_type_node" and + map "hi" to "intHI_type_node". */ +#define TYPE_MAP_SIZE 84 +static typemap type_map[TYPE_MAP_SIZE] = + { + { "bi", "bool_int" }, + { "bv16qi", "bool_V16QI" }, + { "bv2di", "bool_V2DI" }, + { "bv4si", "bool_V4SI" }, + { "bv8hi", "bool_V8HI" }, + { "ci", "integer" }, + { "dd", "dfloat64" }, + { "df", "double" }, + { "di", "long_long_integer" }, + { "hi", "intHI" }, + { "if", "ibm128_float" }, + { "ld", "long_double" }, + { "lg", "long_integer" }, + { "pbv16qi", "ptr_bool_V16QI" }, + { "pbv2di", "ptr_bool_V2DI" }, + { "pbv4si", "ptr_bool_V4SI" }, + { "pbv8hi", "ptr_bool_V8HI" }, + { "pcvoid", "pcvoid" }, + { "pdd", "ptr_dfloat64" }, + { "pdf", "ptr_double" }, + { "pdi", "ptr_long_long_integer" }, + { "phi", "ptr_intHI" }, + { "pif", "ptr_ibm128_float" }, + { "pld", "ptr_long_double" }, + { "plg", "ptr_long_integer" }, + { "pqi", "ptr_intQI" }, + { "psf", "ptr_float" }, + { "psi", "ptr_intSI" }, + { "ptd", "ptr_dfloat128" }, + { "ptf", "ptr_float128" }, + { "pti", "ptr_intTI" }, + { "pudi", "ptr_long_long_unsigned" }, + { "puhi", "ptr_uintHI" }, + { "pulg", "ptr_long_unsigned" }, + { "puqi", "ptr_uintQI" }, + { "pusi", "ptr_uintSI" }, + { "puti", "ptr_uintTI" }, + { "puv16qi", "ptr_unsigned_V16QI" }, + { "puv1ti", "ptr_unsigned_V1TI" }, + { "puv2di", "ptr_unsigned_V2DI" }, + { "puv4si", "ptr_unsigned_V4SI" }, + { "puv8hi", "ptr_unsigned_V8HI" }, + { "pv", "ptr" }, + { "pv16qi", "ptr_V16QI" }, + { "pv1poi", "ptr_vector_pair" }, + { "pv1pxi", "ptr_vector_quad" }, + { "pv1ti", "ptr_V1TI" }, + { "pv2df", "ptr_V2DF" }, + { "pv2di", "ptr_V2DI" }, + { "pv4sf", "ptr_V4SF" }, + { "pv4si", "ptr_V4SI" }, + { "pv8hi", "ptr_V8HI" }, + { "pvp8hi", "ptr_pixel_V8HI" }, + { "qi", "intQI" }, + { "sd", "dfloat32" }, + { "sf", "float" }, + { "si", "intSI" }, + { "st", "const_str" }, + { "td", "dfloat128" }, + { "tf", "float128" }, + { "ti", "intTI" }, + { "udi", "long_long_unsigned" }, + { "uhi", "unsigned_intHI" }, + { "ulg", "long_unsigned" }, + { "uqi", "unsigned_intQI" }, + { "usi", "unsigned_intSI" }, + { "uti", "unsigned_intTI" }, + { "uv16qi", "unsigned_V16QI" }, + { "uv1ti", "unsigned_V1TI" }, + { "uv2di", "unsigned_V2DI" }, + { "uv4si", "unsigned_V4SI" }, + { "uv8hi", "unsigned_V8HI" }, + { "v", "void" }, + { "v16qi", "V16QI" }, + { "v1poi", "vector_pair" }, + { "v1pxi", "vector_quad" }, + { "v1ti", "V1TI" }, + { "v2df", "V2DF" }, + { "v2di", "V2DI" }, + { "v4sf", "V4SF" }, + { "v4si", "V4SI" }, + { "v8hi", "V8HI" }, + { "vp8hi", "pixel_V8HI" }, + }; + /* Pointer to a diagnostic function. */ void (*diag) (const char *, ...) __attribute__ ((format (printf, 1, 2))) = NULL; @@ -2242,10 +2342,83 @@ write_fntype (char *str) fprintf (init_file, "tree %s;\n", str); } +/* Look up TOK in the type map and return the corresponding string used + to build the type node. */ +static const char * +map_token_to_type_node (char *tok) +{ + int low = 0; + int high = TYPE_MAP_SIZE - 1; + int mid = (low + high) >> 1; + int cmp; + + while ((cmp = strcmp (type_map[mid].key, tok)) && low < high) + { + if (cmp < 0) + low = (low == mid ? mid + 1 : mid); + else + high = (high == mid ? mid - 1: mid); + mid = (low + high) >> 1; + } + + if (low > high) + { + (*diag) ("token '%s' doesn't appear in the type map!\n", tok); + exit (EC_INTERR); + } + + return type_map[mid].value; +} + +/* Write the type node corresponding to TOK. */ +static void +write_type_node (char *tok, bool indent) +{ + if (indent) + fprintf (init_file, " "); + const char *str = map_token_to_type_node (tok); + fprintf (init_file, "%s_type_node", str); +} + /* Write an initializer for a function type identified by STR. */ void write_fntype_init (char *str) { + char *tok; + + /* Check whether we have a "tf" token in this string, representing + a float128_type_node. It's possible that float128_type_node is + undefined (occurs for -maltivec -mno-vsx, for example), so we + must guard against that. */ + int tf_found = strstr (str, "tf") != NULL; + + /* Avoid side effects of strtok on the original string by using a copy. */ + char *buf = (char *) malloc (strlen (str) + 1); + strcpy (buf, str); + + if (tf_found) + fprintf (init_file, " if (float128_type_node)\n "); + + fprintf (init_file, " %s\n = build_function_type_list (", buf); + tok = strtok (buf, "_"); + write_type_node (tok, tf_found); + tok = strtok (0, "_"); + assert (tok); + assert (!strcmp (tok, "ftype")); + + tok = strtok (0, "_"); + if (tok) + fprintf (init_file, ",\n\t\t\t\t"); + + /* Note: A function with no arguments ends with '_ftype_v'. */ + while (tok && strcmp (tok, "v")) + { + write_type_node (tok, tf_found); + tok = strtok (0, "_"); + fprintf (init_file, ",\n\t\t\t\t"); + } + fprintf (init_file, "NULL_TREE);\n"); + free (buf); } /* Write everything to the header file (rs6000-builtins.h). */