From patchwork Tue Sep 10 14:21:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schulze Frielinghaus X-Patchwork-Id: 1983279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=ucAsgyYP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X35YX208Kz1y1w for ; Wed, 11 Sep 2024 00:24:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6905B385DDDA for ; Tue, 10 Sep 2024 14:24:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6905B385DDDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1725978252; bh=6IR/X3X+BbVcY/B60NDiw7LHIW3xp01E6a8r5PNupRk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ucAsgyYPJcYkIGLrvLk2B1Cqv8ylI/Sa5UvEEv5UjvLIAQnbjFR26gXcFoHUOqEUL kHXPdcXzp1ckJg+ggrQHMKiI5wUav6795XuS9aIjKKnSsJkDepo5AqlT/QdVrjdNTi GX7u2W2/pucB/AiE65ec/Mrp92cLvn1E5ItNPO9s= 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 9B368385C6C7; Tue, 10 Sep 2024 14:21:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B368385C6C7 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9B368385C6C7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725978122; cv=none; b=fgsXV6Ht/4gsV35eDE2DFZTi0WYIw2Og8Ns8Ik4D3lyA65FULladxwvRdKrsE5seP/PNI8oQTWxP5iYTgidLCEnaYVnYWif04VcOH8cfdH4f0unym9Rb6EP6z51d0+LNyNbR3Oo/CYFPJ34PBD/m+brM1F5fMfP7+PyfbNT7Y00= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725978122; c=relaxed/simple; bh=6SJ/dI3NHiZOipj5eeew2HxZD2e62O/cYheyid/Qf14=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tsVnnMiYwk+lZLJvik5UZ/qN4NkFFzE7/+yxPGzKJ4Osll3m1XKhaOoigxzlgU5RNIcwrjsGFQu1HLUeL7fmjKlsIypXjxURNYDNwlVZfpWlHHJRhX4GEQGFyfjyGOyVDi+lxo1TG11/rnijb/JLyWfr4vFsGxTyXsdEGTa/1io= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48ADYcSI025281; Tue, 10 Sep 2024 14:21:58 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41gejag2gq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Sep 2024 14:21:58 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48ADwBvm013465; Tue, 10 Sep 2024 14:21:57 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 41h3cm3m94-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Sep 2024 14:21:57 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48AELtVq42271160 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 14:21:55 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB7A220040; Tue, 10 Sep 2024 14:21:55 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9CC272004B; Tue, 10 Sep 2024 14:21:55 +0000 (GMT) Received: from a8345010.lnxne.boe (unknown [9.152.108.100]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTPS; Tue, 10 Sep 2024 14:21:55 +0000 (GMT) From: Stefan Schulze Frielinghaus To: gcc-patches@gcc.gnu.org Cc: Stefan Schulze Frielinghaus Subject: [RFC 3/4] genoutput: Verify hard register constraints Date: Tue, 10 Sep 2024 16:21:00 +0200 Message-ID: <20240910142121.3285492-4-stefansf@gcc.gnu.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240910142121.3285492-1-stefansf@gcc.gnu.org> References: <20240910142121.3285492-1-stefansf@gcc.gnu.org> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: w-TciPssd_UleZdFIvoSzYsancVpHLbB X-Proofpoint-GUID: w-TciPssd_UleZdFIvoSzYsancVpHLbB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-10_04,2024-09-09_02,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 phishscore=0 mlxlogscore=669 spamscore=0 impostorscore=0 adultscore=0 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409100105 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Since genoutput has no information about hard register names we cannot statically verify those names in constraints of the machine description. Therefore, we have to do it at runtime. Although verification shouldn't be too expensive, restrict it to checking builds. This should be sufficient since hard register constraints in machine descriptions probably change rarely, and each commit should be tested with checking anyway, or at the very least before a release is taken. --- gcc/genoutput.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ gcc/output.h | 2 ++ gcc/toplev.cc | 4 ++++ 3 files changed, 52 insertions(+) diff --git a/gcc/genoutput.cc b/gcc/genoutput.cc index 2ffb2fb28d2..4f4fde83608 100644 --- a/gcc/genoutput.cc +++ b/gcc/genoutput.cc @@ -200,6 +200,8 @@ static const char indep_constraints[] = ",=+%*?!^$#&g"; static class constraint_data * constraints_by_letter_table[1 << CHAR_BIT]; +static hash_set used_reg_names; + static int mdep_constraint_len (const char *, file_location, int); static void note_constraint (md_rtx_info *); @@ -1156,6 +1158,45 @@ main (int argc, const char **argv) output_insn_data (); output_get_insn_name (); + /* Since genoutput has no information about hard register names we cannot + statically verify hard register names in constraints of the machine + description. Therefore, we have to do it at runtime. Although + verification shouldn't be too expensive, restrict it to checking builds. + */ + printf ("\n\n#if CHECKING_P\n"); + if (used_reg_names.is_empty ()) + printf ("void verify_reg_names_in_constraints () { }\n"); + else + { + size_t max_len = 0; + for (auto it = used_reg_names.begin (); it != used_reg_names.end (); ++it) + { + size_t len = strlen (*it); + if (len > max_len) + max_len = len; + } + printf ("void\nverify_reg_names_in_constraints ()\n{\n"); + printf (" static const char hregnames[%zu][%zu] = {\n", + used_reg_names.elements (), max_len + 1); + auto it = used_reg_names.begin (); + while (it != used_reg_names.end ()) + { + printf (" \"%s\"", *it); + ++it; + if (it != used_reg_names.end ()) + printf (","); + printf ("\n"); + } + printf (" };\n"); + printf (" for (size_t i = 0; i < %zu; ++i)\n", + used_reg_names.elements ()); + printf (" if (decode_reg_name (hregnames[i]) < 0)\n"); + printf (" internal_error (\"invalid register %%qs used in " + "constraint of machine description\", hregnames[i]);\n"); + printf ("}\n"); + } + printf ("#endif\n"); + fflush (stdout); return (ferror (stdout) != 0 || have_error ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); @@ -1294,6 +1335,11 @@ mdep_constraint_len (const char *s, file_location loc, int opno) ptrdiff_t len = end - s; if (*end == '}' && len > 1 && len < 31) { + char *regname = new char[len]; + memcpy (regname, s + 1, len - 1); + regname[len - 1] = '\0'; + if (used_reg_names.add (regname)) + delete[] regname; return len + 1; } } diff --git a/gcc/output.h b/gcc/output.h index 46b0033b221..5f0f8a6098c 100644 --- a/gcc/output.h +++ b/gcc/output.h @@ -636,4 +636,6 @@ extern int default_address_cost (rtx, machine_mode, addr_space_t, bool); /* Stack usage. */ extern void output_stack_usage (void); +extern void verify_reg_names_in_constraints (); + #endif /* ! GCC_OUTPUT_H */ diff --git a/gcc/toplev.cc b/gcc/toplev.cc index bc442a08c63..34c372ad1a2 100644 --- a/gcc/toplev.cc +++ b/gcc/toplev.cc @@ -1817,6 +1817,10 @@ backend_init_target (void) static void backend_init (void) { +#if CHECKING_P + verify_reg_names_in_constraints (); +#endif + init_emit_once (); init_rtlanal ();