From patchwork Wed Aug 5 14:35:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 140662 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 274B74BAE7D3 for ; Wed, 5 Aug 2026 14:37:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 274B74BAE7D3 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=mWLISWn8 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010034.outbound.protection.outlook.com [52.101.46.34]) by sourceware.org (Postfix) with ESMTPS id 8FD354BA2E35 for ; Wed, 5 Aug 2026 14:36:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FD354BA2E35 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nvidia.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8FD354BA2E35 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.101.46.34 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785940579; cv=pass; b=N5/UBhYP/0yl+sw3eJf9eDh1dFDFwsCqLd0zfTM7Y6F7Q9yIJez8Okj7lmKgUzQtMCFl2tIlqdEW1DVVCjTjqaiGc8j1X0bSHghcXDl/mFRjwhXpOAGJdaSBDmaHLiqY4Z2INnIELWUiFxzmeK8INFJ6mHFURsmP/X5HioFq/pE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785940579; c=relaxed/simple; bh=sZouonBnYa8bOG2SkBcMUCd55A4JynSYuJFNMcYBuvE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rDaUYtSiDPp361gCz6XF4K7GDCPSIevAu6BIdwPt7Lnc3xKJoanxBXH5ZD7uPO+FA4p9DF1qqtTbQint6IYT74/EyRRWE8I5aRoV6irhGumCtVi6Z34PiwZsHjbxYdKJnrEKih6/B4/HGn5uP7anQMKW1FtRm/g+0Dz57PGsQbs= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=mWLISWn8 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FD354BA2E35 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dJgIDK/urVbiDVPhLteIsMeDbgWwhe/zUMM1gsf1G33d7njZh4QSrNvQECwUngQNeEoVLSCu1i1pcthEplw/rxN2PywN1HlA8ukp0GTc7GsJCSKrqYA9NjmmtFljHkUwW7tAoXmo/pKE78hyCmS2IIdm09oiaF9oCg7JtUxsf1DLQe4SeHDDUYfgDKSQbrhvkXDfxie9BNCSRjASegMWYakTi+8ghUMiiOMTyPRil6wLZtBF/R2Zd/KDW5yBGU/9tYbU78+lbQzWchxuf3l6j/MKodkb9BmCWVR092Yw1hgC5XvpNVtL5t9juRW13b0KQLJp9BtL57+y9iG5mqU/Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QItjbUOUrnKzll4C3vOTqLYHgXicBgOPPQHU29jWr6A=; b=xDA3ivVZN7F//wgYsOAZHkexB1eruR6IBvMjWz5b15urVzXgdozC/5qCav8zlcEIW1PgfZBQZMPODnO6O19TzY/n21WT4C/ALN/3U7qePWBRSHwyMoQlfpdJPxygwPqmiWncA6B6AXqkrxpRvbJkQs8taKtNv8/DvbGGTapzWZ1W6RSpxQtSUAxkoe2FDSnPZ5GDI7szdX1IQdMkGYL2GdBnsZfUtE/YLEiiQUe6TKZlMYehZdqsgPog5ycO0Hh0qta1vI9ude5P4wUgoHS/T1EXgR6QD5/zA4drZB8hmHBpmPpjmckOXB0zFaGzB2+1ekhSHylCnpNFjquyzQj8Cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QItjbUOUrnKzll4C3vOTqLYHgXicBgOPPQHU29jWr6A=; b=mWLISWn8NzKBSMfg8mJU1MHjLLd8NWb6fNKm/OMcftdgC1jnAw2e7o7Uy5KKwUTNm2IK/xbTRAYVzOv3ZCoxzvB6nJvWQlCNsU+VMFyLKQ0pTeTFoKLhOBi0m1WkoBIRz4qfrx+xuno6ko9Zpyfij+6lFw/5stptSPJMbr7K1RZww0V9l9pwV87PyQrdG0aQ+G03P5WUli9B+2bpLzyKjo/sM4jPj2ytkcN43kvDFFHXLqCgXb9+id+SEHT+sxOjtDvCTyN4fdppnpbty4oC5FHRe/tAW9G665MYIAkN8KlTQz3xSS0uY6pt6rPupcuCXZyixuem5z4OWQiKQUGt3A== Received: from BN9PR03CA0549.namprd03.prod.outlook.com (2603:10b6:408:138::14) by SN7PR12MB6885.namprd12.prod.outlook.com (2603:10b6:806:263::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.19; Wed, 5 Aug 2026 14:36:07 +0000 Received: from BL6PEPF00020E66.namprd04.prod.outlook.com (2603:10b6:408:138:cafe::8e) by BN9PR03CA0549.outlook.office365.com (2603:10b6:408:138::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.17 via Frontend Transport; Wed, 5 Aug 2026 14:36:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF00020E66.mail.protection.outlook.com (10.167.249.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.8 via Frontend Transport; Wed, 5 Aug 2026 14:36:06 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Wed, 5 Aug 2026 07:35:39 -0700 Received: from ktkachov-mlt.nvidia.com (10.126.231.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 5 Aug 2026 07:35:37 -0700 From: To: CC: , , , Kyrylo Tkachov Subject: [PATCH 1/4] gensupport: Centralize machine-generator output management Date: Wed, 5 Aug 2026 16:35:23 +0200 Message-ID: <20260805143526.27275-1-ktkachov@nvidia.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 X-Originating-IP: [10.126.231.37] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00020E66:EE_|SN7PR12MB6885:EE_ X-MS-Office365-Filtering-Correlation-Id: a2e9dd7d-2585-49fd-3dec-08def2fee2aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700016|376014|23010399003|18002099003|11063799006|5023799004|56012099006|3023799007|6133799003|10067099003; X-Microsoft-Antispam-Message-Info: Kjx71WKpXQUDndVq5WNKx046IgbmuMTXjiSxbYUpgRVmJFTEMRYSKjpSIDU2Ykxsm6rAMsZAzm3fvNopPlVoq3jUhedH8NZhxtIsr2v45xuvoGS47EHJdoZwYZnf02GwTCekEDqxOtTKwgNfX8IU+pFsg8ZQWVdt0wv44ZUOsVjoPo0XvMLbUSqsXBaCI1CGBzC+gyGFSp76SBCiJfH6M3dmC+vwDi8j984ZJzR8es0F8vDfNKa0cGjSWB68K/eR2ohGr5TNZcPoT1ErS/PZMIaLv2uRM0LRQQ71vl219Y+/56BwjU/5dkAdVIMH6YTRQ9kUTwkC8s3+uD/HZkMY4mMTbXftbZyZn/J6pxTp82A4+P3OGa5AMEF/DdexWd9ncQW+C7CSXuvZd/A4ebL05hZ6i0sxhm74GGxoopxG/6SvdNUrAIgv+k79+u85SwP42vzsukNEAH8RbS7nAyJfgcY5YvsQrP9TCsgxG30rUKIkcMJUvDcjkYeGBNPtdhtrE+7JugWxqqFFGdxM73bUIPo3YPunPnIkmTf+Ksb4F+4n7FgRJSSWQGS0OgibLU6+5LM/X7qlbrrYh957RxYlGUhNc2hHtXHUw5vma+heL4S9e18oDLdGPpf8FMp20dUuCkew2OAREy41r35NCG10LdeAiK1u5XqvhJ2+kg1rv3XJImzGNjpYb8PWV9oeGgDRvIhaAS2rEa2lCTrJUr3e3A== X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700016)(376014)(23010399003)(18002099003)(11063799006)(5023799004)(56012099006)(3023799007)(6133799003)(10067099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xULS2Y49nDBpGifBL5v4q5gHvYk8F3a1cSTosN4HGP/gQCKShsjX0KPhg2sSlSFszB1XYvKJTTK5QQJyG6dti96I/Fjzna/9fAehRHKcmmDBEFvIjsxkO09E5gsw3PeZawMYVb9JJQOUobfdEbsjz8nXBDODKSrEol5fiENnPCy4M465Meq6/LSi41ohQ9+K2vS4kUBue/hlPjWWJKMR+8KUrXbufjU7Xz+P3Slk8uJFt4BNQzbLWea49gVzUVgfw+i4amGQBD42/gRWuWMnz9cTB2pXoHW/7Z6+GAsVRkgAhX/bQbG2nYY763BclhrcB9+7UaIXcU2BokVA0NC0DjlKbAP+NMrfg1ZLxNGT8brAV0CASN82vVQRXgrIjCidtN7VBQt4F5WxUlzJGBSafwp95rbW8Fj1Y9WLHG9kt5+FagNiv3bV+88GMEVT07V8 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2026 14:36:06.9678 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a2e9dd7d-2585-49fd-3dec-08def2fee2aa X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00020E66.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6885 X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, LOCAL_AUTHENTICATION_FAIL_SPF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@gcc.gnu.org From: Kyrylo Tkachov genemit and genrecog use the same size-based output selection, but each generator owns its file names, opens files during option parsing, and closes them separately. Adding more partitioned generators would copy this logic. Put the common output record and lifecycle helpers in gensupport. The helpers validate names, delay file opening until option parsing is complete, select only partition outputs by current size, and close every output with a useful diagnostic. Fixed outputs, such as headers, use the same record but do not participate in selection. Convert genemit and genrecog to the common interface. Also remove the unused output index and disabled round-robin code from choose_output, and remove a genrecog selection whose result is discarded. Diagnose missing or repeated genrecog -H options, remove its fixed header-name limit, and stop printing parsed output options to standard output. Robin added the shared choose_output helper for PR111600, following the size-based policy that Tamar used in genmatch. Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux. Ok for trunk? Thanks, Kyrill gcc/ChangeLog: * gensupport.h (generator_output): New structure. (add_generator_output, open_generator_outputs): Declare. (close_generator_outputs): Likewise. (choose_output): Accept generator_output records. Remove the output index parameter. * gensupport.cc (add_generator_output): New function. (open_generator_outputs, close_generator_outputs): Likewise. (choose_output): Select only partition records. Remove the output index and disabled round-robin implementation. * genemit.cc (output_files): Use generator_output records. (handle_arg): Register output names. (main): Use the common open, selection, and close helpers. * genrecog.cc (print_subroutine_group): Accept generator_output records. (header_name): Change to a pointer. (header): Remove global variable. (output_files): Use generator_output records. (handle_arg): Register output names and validate -H. (main): Validate and register the header output. Use the common open, selection, and close helpers. Remove an unused output selection. Suggested-by: Tamar Christina Signed-off-by: Kyrylo Tkachov --- gcc/genemit.cc | 25 ++++++--------- gcc/genrecog.cc | 64 +++++++++++++++---------------------- gcc/gensupport.cc | 80 ++++++++++++++++++++++++++++++++++++----------- gcc/gensupport.h | 16 +++++++++- 4 files changed, 112 insertions(+), 73 deletions(-) diff --git a/gcc/genemit.cc b/gcc/genemit.cc index 6323aeb19fc..4cddaaa59b9 100644 --- a/gcc/genemit.cc +++ b/gcc/genemit.cc @@ -878,15 +878,14 @@ from the machine description file `md'. */\n\n"); fprintf (file, "#include \"target.h\"\n\n"); } -auto_vec output_files; +auto_vec output_files; static bool handle_arg (const char *arg) { if (arg[1] == 'O') { - FILE *file = fopen (&arg[2], "w"); - output_files.safe_push (file); + add_generator_output (output_files, &arg[2], true); return true; } return false; @@ -910,13 +909,13 @@ main (int argc, const char **argv) md_rtx_info info; if (output_files.is_empty ()) - output_files.safe_push (stdout); + add_generator_output (output_files, NULL, true); + open_generator_outputs (output_files); - for (auto f : output_files) - print_header (f); + for (const generator_output &output : output_files) + print_header (output.file); FILE *file = NULL; - unsigned file_idx; /* Read the machine description. */ while (read_md_rtx (&info)) @@ -941,7 +940,7 @@ main (int argc, const char **argv) for (auto &info : queue) { - file = choose_output (output_files, file_idx); + file = choose_output (output_files); fprintf (file, "/* %s:%d */\n", info.loc.filename, info.loc.lineno); switch (GET_CODE (info.def)) @@ -964,7 +963,7 @@ main (int argc, const char **argv) } } - file = choose_output (output_files, file_idx); + file = choose_output (output_files); /* Write out the routines to add CLOBBERs to a pattern and say whether they clobber a hard reg. */ @@ -978,10 +977,6 @@ main (int argc, const char **argv) handle_overloaded_gen (oname, file); } - int ret = SUCCESS_EXIT_CODE; - for (FILE *f : output_files) - if (fclose (f) != 0) - ret = FATAL_EXIT_CODE; - - return ret; + return (close_generator_outputs (output_files) + ? SUCCESS_EXIT_CODE : FATAL_EXIT_CODE); } diff --git a/gcc/genrecog.cc b/gcc/genrecog.cc index 663620224ab..ab9f3723e89 100644 --- a/gcc/genrecog.cc +++ b/gcc/genrecog.cc @@ -5288,11 +5288,10 @@ print_subroutine (FILE *f, output_state *os, state *s, int proc_id, /* Print out a routine of type TYPE that performs ROOT. */ static void -print_subroutine_group (vec &vec, FILE *header, output_state *os, +print_subroutine_group (const vec &outputs, FILE *header, + output_state *os, routine_type type, state *root) { - FILE *f; - unsigned idx; os->type = type; if (use_subroutines_p) { @@ -5305,19 +5304,14 @@ print_subroutine_group (vec &vec, FILE *header, output_state *os, unsigned int i; state *s; - FILE *f = header; FOR_EACH_VEC_ELT (subroutines, i, s) print_subroutine (header, os, s, i + 1, true); FOR_EACH_VEC_ELT (subroutines, i, s) - { - f = choose_output (vec, idx); - print_subroutine (f, os, s, i + 1); - } + print_subroutine (choose_output (outputs), os, s, i + 1); } /* Output the main routine. */ - f = choose_output (vec, idx); - print_subroutine (f, os, root, 0); + print_subroutine (choose_output (outputs), os, root, 0); } /* Return the rtx pattern for the list of rtxes in a define_peephole2. */ @@ -5388,24 +5382,22 @@ remove_clobbers (acceptance_type *acceptance_ptr, rtx *pattern_ptr) return true; } -auto_vec output_files; -char header_name[255]; -FILE *header = NULL; +auto_vec output_files; +const char *header_name; static bool handle_arg (const char *arg) { - printf ("%s\n", arg); if (arg[1] == 'O') { - FILE *file = fopen (&arg[2], "w"); - output_files.safe_push (file); + add_generator_output (output_files, &arg[2], true); return true; } if (arg[1] == 'H') { - snprintf (header_name, 255, "%s", &arg[2]); - header = fopen (header_name, "w"); + if (header_name) + fatal ("option -H specified more than once"); + header_name = &arg[2]; return true; } return false; @@ -5421,14 +5413,18 @@ main (int argc, const char **argv) if (!init_rtx_reader_args_cb (argc, argv, handle_arg)) return (FATAL_EXIT_CODE); + if (!header_name) + fatal ("no -H output file specified"); if (output_files.is_empty ()) - output_files.safe_push (stdout); - - for (auto f : output_files) - write_header (f, header_name); + add_generator_output (output_files, NULL, true); + unsigned int header_index + = add_generator_output (output_files, header_name, false); + open_generator_outputs (output_files); + FILE *header = output_files[header_index].file; - FILE *file = NULL; - unsigned file_idx; + for (const generator_output &output : output_files) + if (output.partition_p) + write_header (output.file, header_name); /* Read the machine description. */ @@ -5436,7 +5432,6 @@ main (int argc, const char **argv) while (read_md_rtx (&info)) { rtx def = info.def; - file = choose_output (output_files, file_idx); acceptance_type acceptance; acceptance.partial_p = false; @@ -5494,8 +5489,9 @@ main (int argc, const char **argv) if (have_error) return FATAL_EXIT_CODE; - for (auto f : output_files) - fprintf (f, "%s", "\n\n"); + for (const generator_output &output : output_files) + if (output.partition_p) + fprintf (output.file, "%s", "\n\n"); /* Optimize each routine in turn. */ optimize_subroutine_group ("recog", &insn_root); @@ -5522,10 +5518,7 @@ main (int argc, const char **argv) print_pattern (header, &os, routine, true); FOR_EACH_VEC_ELT (patterns, i, routine) - { - file = choose_output (output_files, file_idx); - print_pattern (file, &os, routine); - } + print_pattern (choose_output (output_files), &os, routine); } /* Print out the matching routines. */ @@ -5533,11 +5526,6 @@ main (int argc, const char **argv) print_subroutine_group (output_files, header, &os, SPLIT, &split_root); print_subroutine_group (output_files, header, &os, PEEPHOLE2, &peephole2_root); - fclose (header); - - int ret = SUCCESS_EXIT_CODE; - for (FILE *f : output_files) - if (fclose (f) != 0) - ret = FATAL_EXIT_CODE; - return ret; + return (close_generator_outputs (output_files) + ? SUCCESS_EXIT_CODE : FATAL_EXIT_CODE); } diff --git a/gcc/gensupport.cc b/gcc/gensupport.cc index 5fcc30d340e..9439ddd97d8 100644 --- a/gcc/gensupport.cc +++ b/gcc/gensupport.cc @@ -3935,35 +3935,77 @@ find_optab (optab_pattern *p, const char *name) return false; } -/* Find the file to write into next. We try to evenly distribute the contents - over the different files. */ +/* Add output NAME to OUTPUTS. A null NAME means standard output. + PARTITION_P is true if the output participates in size-based selection. + Return its index. */ -#define SIZED_BASED_CHUNKS 1 +unsigned int +add_generator_output (vec &outputs, const char *name, + bool partition_p) +{ + gcc_assert (name || outputs.is_empty ()); + if (name) + for (const generator_output &output : outputs) + if (output.name && canonical_filename_eq (name, output.name)) + fatal ("output file %s specified more than once", name); + + generator_output output = { name, name ? NULL : stdout, partition_p }; + unsigned int index = outputs.length (); + outputs.safe_push (output); + return index; +} + +/* Open each named file in OUTPUTS. */ + +void +open_generator_outputs (vec &outputs) +{ + for (generator_output &output : outputs) + if (!output.file) + { + output.file = fopen (output.name, "w"); + if (!output.file) + fatal ("cannot open file %s: %s", output.name, xstrerror (errno)); + } +} + +/* Return the shortest partition file in OUTPUTS. */ FILE * -choose_output (const vec &parts, unsigned &idx) +choose_output (const vec &outputs) { - if (parts.length () == 0) - gcc_unreachable (); -#ifdef SIZED_BASED_CHUNKS FILE *shortest = NULL; long min = 0; - idx = 0; - for (unsigned i = 0; i < parts.length (); i++) + for (const generator_output &output : outputs) { - FILE *part = parts[i]; - long len = ftell (part); + if (!output.partition_p) + continue; + long len = ftell (output.file); if (!shortest || min > len) { - shortest = part; + shortest = output.file; min = len; - idx = i; - } + } } + if (!shortest) + gcc_unreachable (); return shortest; -#else - static int current_file; - idx = current_file++ % parts.length (); - return parts[idx]; -#endif +} + +/* Close all files in OUTPUTS. Return true if every close succeeds. */ + +bool +close_generator_outputs (const vec &outputs) +{ + bool ok = true; + for (const generator_output &output : outputs) + { + if (fclose (output.file) != 0) + { + error ("cannot close output %s: %s", + output.name ? output.name : "", xstrerror (errno)); + ok = false; + } + } + return ok; } diff --git a/gcc/gensupport.h b/gcc/gensupport.h index 86dd1103436..880505355b2 100644 --- a/gcc/gensupport.h +++ b/gcc/gensupport.h @@ -232,6 +232,20 @@ extern void compute_test_codes (rtx, file_location, char *); extern file_location get_file_location (rtx); extern const char *get_emit_function (rtx); extern bool find_optab (optab_pattern *, const char *); -extern FILE *choose_output (const vec &, unsigned &); + +/* An output file produced by a machine-description generator. Partition + files participate in size-based output selection. */ +struct generator_output +{ + const char *name; + FILE *file; + bool partition_p; +}; + +extern unsigned int add_generator_output (vec &, + const char *, bool); +extern void open_generator_outputs (vec &); +extern FILE *choose_output (const vec &); +extern bool close_generator_outputs (const vec &); #endif /* GCC_GENSUPPORT_H */ From patchwork Wed Aug 5 14:35:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 140664 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 135334BAE7DF for ; Wed, 5 Aug 2026 14:37:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 135334BAE7DF Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=uBfPxZvs X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazlp170120005.outbound.protection.outlook.com [IPv6:2a01:111:f403:c105::5]) by sourceware.org (Postfix) with ESMTPS id 55AE64BA2E32 for ; Wed, 5 Aug 2026 14:36:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55AE64BA2E32 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nvidia.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 55AE64BA2E32 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c105::5 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785940579; cv=pass; b=FNxP0Mb/AZJJ8u+zdOfVJCeNFSRLvUkHmFPluJsA9wivbI8L3uBf9KnWR1h2FGXte0c8rXnGP1MpDSLaIWktnCXuEGNNoSrnTKbsPlrjXcd4jq1QQ8aCeP+l5Z5DQ63AfrsSoTK2Go9+B305trV8/msAPr6X3MS7+DyPomowZXw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785940579; c=relaxed/simple; bh=NS/cBOhVL1ZRt5JQciIsVJSRqx6gOdNgDgRUaM0EPBE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iMevylYs6W2BoESDjky41WyanrujXZEL+i19syYFI5BaeW0lIbN3+XAKiQRAMFpkscaR7GXI3VzoZOnqjcW3XemeOZKQpvRmYlVoPPSVScDCUD94f0mr3hA0L+fztA8B7YAjIx8yvKnjdpQBfnmZ0hpu9fkj+3traNh37P04MAw= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=uBfPxZvs DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55AE64BA2E32 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KYeUcj1Sad4N6v9hjeiv3pReyhbomTdZCXSvQMXuuEbddPQSJOchW1D1MDBWBGEYhv4JDiIb4VkqilE/nVvOraGvA1OqOuIHWORMBddSt54z5KRfNPM94Yi3jIN7ALu1kNMVtqWl2Ol9MlGEvhXnOcTQ7TdGn/xi5x78kC1+AJKBmywXZg9XpE4EYXpk8uh7nEEaTkqW/rSGIRuOpQGuppQe88JnSRlgLii/x/jvcJzpHt+8iSfEWo2dH+QRoKpxcktYdhHKmWtVA7Y2bcpxKEF+l2ihGExTPjE5f2GSk4oNhNsNMWk4LSMSCuMjBKr45f0EloL6NkyHvZrXC1KRbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mlesGJsJrUO1eFaisPsqvB4TzW+0CqCzobhZodyGmv4=; b=udUsZWTIGWOvbEu+4etW6DksGF+bRzmY36GY473q2kubXCiaaE2nck5aP7VghMNepPLQ53d17mTaDLI1a1BSYNBr61irV66TyMgYHuxgekKSJWXc/w/ra6I82Q5ghuWAGVUt2OoSFjUu0P7W14QQ+1vWASBcZfRxVG33K7uSxozkmbJ1mxybb0BEH2bRWPjHwCzRJ+ctluiiQXhZquYuUeZJXXIl8vUT5kztt9FiY6lNS7n2sr/RW7r00MJKnu0mM6CCvTt77zNOlagb/WaaQydri1knJgAtqVJ7G8qEVTV9w6EwZ88zzToz6er+x9JKcu0IjmIa1aYwXec0DMDOQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mlesGJsJrUO1eFaisPsqvB4TzW+0CqCzobhZodyGmv4=; b=uBfPxZvspLNjIFmNUgbIrQ3Lu6oFMVYTDRKJ6lLRS4S01tJk41w5e8/EUfGwv89mUQl0CbcLH5uw9tPe2nhF2FTcPCORoaZUGcwPrjdiQU6E/YeNLHVI6RdTO7f/UzFKYixJr0aiD7e3bEdcEjZ4LrLZeQjgVsatwuE8HlVa1cxFrKJmIcufqmWrfkosSOMjVWNsVwEYGKf018cY8hNg6AymeWg1ViE1acJ2Sn8PBEcBzmqGUueCzUO25sQG9wYPNAPqxUvxuDEgMP7uJvC19ahe8Acy1XUdMLSjNRB1LoJIOcZ7oMCM7ZS3DSVxMTOjEUlEBno2ILTmA7kMJPL2Eg== Received: from BLAPR03CA0158.namprd03.prod.outlook.com (2603:10b6:208:32f::24) by SJ2PR12MB9008.namprd12.prod.outlook.com (2603:10b6:a03:543::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.17; Wed, 5 Aug 2026 14:36:10 +0000 Received: from BL6PEPF00022571.namprd02.prod.outlook.com (2603:10b6:208:32f:cafe::70) by BLAPR03CA0158.outlook.office365.com (2603:10b6:208:32f::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.292.19 via Frontend Transport; Wed, 5 Aug 2026 14:36:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL6PEPF00022571.mail.protection.outlook.com (10.167.249.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.8 via Frontend Transport; Wed, 5 Aug 2026 14:36:09 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 5 Aug 2026 07:35:40 -0700 Received: from ktkachov-mlt.nvidia.com (10.126.231.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 5 Aug 2026 07:35:39 -0700 From: To: CC: , , , Kyrylo Tkachov Subject: [PATCH 2/4] genopinit: Group optab patterns by condition Date: Wed, 5 Aug 2026 16:35:24 +0200 Message-ID: <20260805143526.27275-2-ktkachov@nvidia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260805143526.27275-1-ktkachov@nvidia.com> References: <20260805143526.27275-1-ktkachov@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.231.37] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00022571:EE_|SJ2PR12MB9008:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e6e3354-0c34-4aca-ede8-08def2fee454 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|23010399003|36860700016|376014|22082099003|18002099003|11063799006|6133799003|10067099003|56012099006; X-Microsoft-Antispam-Message-Info: AiZ4gBywTwbG6eRmU7gyMXFgWcBxbvGvsdQHhtJGTcJWoBVA2MQ04Q3SzAm9i0kFT4zdFhUc/beGKhEPJgNXuuKcR2sRv4PokMOboYYvFspl5PbE1qlA4ibANLKBHuj686yTfsj417qZOYyfBoCIVh5fu4NrEQcJQHl3TxI7VfmUyBOLqkKiVDJtz1ow9UqarumcRkoxdjpZsK9uI5PA3i1YZ+KV7O71V8TG7aXlQB7xFhylRo7/ZONFO7gVtM3dY6VxVHHGXcYUQCfhxKbd25zxog/tgVE1WxOC3Y69zY8bj7itY6bKxlhNtuHRCRZTnvLkFJBQ2iK08yn9sd/l9wn69GIRIZ2X1lmo2lv8C8MrJAcbYw+ZQb27jfQJcwMAyttjauZXgqZyKphjrTnnvfK/fdXcESicFW6jnORaifysSdSnkQ/Hy8wBQhCltOPVn5xy210xcUYRpM430g4ElR5r6vqSGuTaKk/OXUR+GTacoCNOl6TE4saYN/dqk8uXKJ+lkFBqz9bbHrVDkgh2fVlF2H+k4dL5iBL1SlitjPKspaxwasrW/y6AZ6lBXtm6THivaFPfh49JM4t1/b2BdJDLe5cMmMSYWMsz2RlYTlB6Sh1yvLlYXRz+t8pwnvnVYEZV+Z8ZixmtY1pbkhiaIz13lnfMZnhchbqPMU+jIVT2QSMhZU4GEVlAF622DYn9ps50TSFTGKgMEn+vYT6HTw== X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(82310400026)(23010399003)(36860700016)(376014)(22082099003)(18002099003)(11063799006)(6133799003)(10067099003)(56012099006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7O3oJd5D9rZSHVpLkME7QI5HeFD+UycKld8X7NbfJm/sSflwLPznsDxiEt17lVvZdZSuC4CLc9JG/nzDmDDmEyLAGfYcaAGo06pDtT7W6LIJeKN4fZbQT15g369mgTnmv4M5zJl8OUBb+Xk8LoeKlR8j/6l9MRtUjZwOY8PU0884DbydnmfeDQPRhGX+49tDE087JcolXhRGo9kA36alEqz02hTi/RggYSNI2UbAtg5w55cc79jcy8bNq/UxG63fwszVVlr6OqIQ/DieS63TfzRJHkV5uZkyLtB3qF44f5un5tBk9LfIWsZ7vn1vNeDNBkEDCrnAaa4wYSEoHwxUfn7C/MmZ4nED++KCwKglUpxI77TtNzHFcoPpAxSXTTHxqaXrFt/81Y/2cJ7TAHFE3Ms7nVo/+u3eXOpExnsPcgGmvkb/2myNz2s+Lqlam4Na X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2026 14:36:09.7644 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e6e3354-0c34-4aca-ede8-08def2fee454 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00022571.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9008 X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, LOCAL_AUTHENTICATION_FAIL_SPF, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@gcc.gnu.org From: Kyrylo Tkachov insn-opinit.cc initializes one Boolean value for every optab pattern. Many assignments use the same target condition. The repeated assignments make the generated file expensive to optimize and produce a large initializer function. A measured AArch64 file has 3,412 patterns but only 128 exact conditions. A measured RISC-V file has 14,984 patterns but only 963 exact conditions. Record an index for each exact condition string while genopinit reads the machine description. Emit one representative HAVE_* value per condition and a compact pattern-to-condition map. Initialize pat_enable with one sequential loop. Use unsigned char or unsigned short when their ISO C minimum ranges hold all condition indices. Otherwise use unsigned int, which holds every GCC vec index on a supported host. For example, these four AArch64 HAVE_* macros all expand to TARGET_SVE. A shortened part of the old initializer is: ena[1021] = HAVE_while_ultsivnx16bi; /* TARGET_SVE */ ena[1022] = HAVE_while_ultdivnx16bi; /* TARGET_SVE */ ena[1023] = HAVE_while_ultsivnx8bi; /* TARGET_SVE */ ena[1024] = HAVE_while_ultdivnx8bi; /* TARGET_SVE */ The new initializer contains four one-byte condition indices and one representative TARGET_SVE expression: static const unsigned char pat_condition[NUM_OPTAB_PATTERNS] = { /* ... */ 9, 9, 9, 9, /* ... */ }; void init_all_optabs (struct target_optabs *optabs) { const bool condition_values[] = { /* ... */ !!HAVE_movvnx32bi, /* TARGET_SVE, condition 9 */ /* ... */ }; for (unsigned int i = 0; i < NUM_OPTAB_PATTERNS; ++i) optabs->pat_enable[i] = condition_values[pat_condition[i]]; } The initializer therefore contains one TARGET_SVE expression for these four patterns instead of four copies. The same reduction applies to every shared condition. The condition values remain local to init_all_optabs, so each call evaluates them for the current target options. Each pat_enable entry also remains independent for swap_optab_enable. On AArch64, direct compilation of insn-opinit.cc takes about 94% less wall time and 64% less peak memory. On x86_64, it takes about 34% less wall time and 19% less peak memory. The AArch64 initializer text is about 95% smaller. The x86_64 initializer text is about 77% smaller. Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux. Ok for trunk? Thanks, Kyrill gcc/ChangeLog: * genopinit.cc (pattern_info): New. (patterns): Use pattern_info. (condition_map, condition_representatives): New. (gen_insn): Record the condition index for each pattern. (pattern_cmp): Use pattern_info. (main): Emit one value per condition, a compact condition map, and one initialization loop. Suggested-by: Tamar Christina Signed-off-by: Kyrylo Tkachov --- gcc/genopinit.cc | 98 +++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/gcc/genopinit.cc b/gcc/genopinit.cc index 62eaf5bd378..77aaa6a858e 100644 --- a/gcc/genopinit.cc +++ b/gcc/genopinit.cc @@ -35,22 +35,45 @@ static const char * const rtx_upname[] = { #undef DEF_RTL_EXPR +struct pattern_info : optab_pattern +{ + unsigned int condition_index; +}; + /* Vector in which to collect insns that match. */ -static vec patterns; +static vec patterns; + +/* Maps each condition to its index in CONDITION_REPRESENTATIVES. */ +static hash_map condition_map; + +/* One representative optab pattern name for each unique condition. */ +static vec condition_representatives; static void gen_insn (md_rtx_info *info) { - optab_pattern p; + pattern_info p; if (find_optab (&p, XSTR (info->def, 0))) - patterns.safe_push (p); + { + const char *condition = get_c_test (info->def); + bool existed; + unsigned int &condition_index + = condition_map.get_or_insert (condition, &existed); + if (!existed) + { + condition_index = condition_representatives.length (); + condition_representatives.safe_push (p.name); + } + p.condition_index = condition_index; + patterns.safe_push (p); + } } static int pattern_cmp (const void *va, const void *vb) { - const optab_pattern *a = (const optab_pattern *)va; - const optab_pattern *b = (const optab_pattern *)vb; + const pattern_info *a = (const pattern_info *)va; + const pattern_info *b = (const pattern_info *)vb; return a->sort_num - b->sort_num; } @@ -178,7 +201,7 @@ main (int argc, const char **argv) { FILE *h_file, *s_file; unsigned int i, j, n, last_kind[5]; - optab_pattern *p; + pattern_info *p; progname = "genopinit"; @@ -367,44 +390,33 @@ main (int argc, const char **argv) fprintf (s_file, " { %#08x, CODE_FOR_%s },\n", p->sort_num, p->name); fprintf (s_file, "};\n\n"); - /* Some targets like riscv have a large number of patterns. In order to - prevent pathological situations in dataflow analysis split the init - function into separate ones that initialize 1000 patterns each. */ - - const int patterns_per_function = 1000; - - if (patterns.length () > patterns_per_function) - { - unsigned num_init_functions - = patterns.length () / patterns_per_function + 1; - for (i = 0; i < num_init_functions; i++) - { - fprintf (s_file, "static void\ninit_optabs_%02d " - "(struct target_optabs *optabs)\n{\n", i); - fprintf (s_file, " bool *ena = optabs->pat_enable;\n"); - unsigned start = i * patterns_per_function; - unsigned end = MIN (patterns.length (), - (i + 1) * patterns_per_function); - for (j = start; j < end; ++j) - fprintf (s_file, " ena[%u] = HAVE_%s;\n", j, patterns[j].name); - fprintf (s_file, "}\n\n"); - } - - fprintf (s_file, "void\ninit_all_optabs " - "(struct target_optabs *optabs)\n{\n"); - for (i = 0; i < num_init_functions; ++i) - fprintf (s_file, " init_optabs_%02d (optabs);\n", i); - fprintf (s_file, "}\n\n"); - } + /* Base the first two limits on the minimum ranges required by ISO C. The + host that compiles the generated file can differ from the machine that + runs this generator. GCC hosts have at least 32-bit int, while vec has + a 31-bit capacity, so unsigned int holds all remaining indices. */ + const char *condition_index_type; + if (condition_representatives.length () <= 256) + condition_index_type = "unsigned char"; + else if (condition_representatives.length () <= 65536) + condition_index_type = "unsigned short"; else - { - fprintf (s_file, "void\ninit_all_optabs " - "(struct target_optabs *optabs)\n{\n"); - fprintf (s_file, " bool *ena = optabs->pat_enable;\n"); - for (i = 0; patterns.iterate (i, &p); ++i) - fprintf (s_file, " ena[%u] = HAVE_%s;\n", i, p->name); - fprintf (s_file, "}\n\n"); - } + condition_index_type = "unsigned int"; + fprintf (s_file, "static const %s " + "pat_condition[NUM_OPTAB_PATTERNS] = {\n", condition_index_type); + for (i = 0; patterns.iterate (i, &p); ++i) + fprintf (s_file, " %u,\n", p->condition_index); + fprintf (s_file, "};\n\n"); + + fprintf (s_file, "void\ninit_all_optabs " + "(struct target_optabs *optabs)\n{\n" + " const bool condition_values[] = {\n"); + for (i = 0; i < condition_representatives.length (); ++i) + fprintf (s_file, " !!HAVE_%s,\n", condition_representatives[i]); + fprintf (s_file, + " };\n" + " for (unsigned int i = 0; i < NUM_OPTAB_PATTERNS; ++i)\n" + " optabs->pat_enable[i] = condition_values[pat_condition[i]];\n" + "}\n\n"); fprintf (s_file, "/* Returns TRUE if the target supports any of the partial vector\n" From patchwork Wed Aug 5 14:35:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 140665 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A0C64BAE7EB for ; Wed, 5 Aug 2026 14:37:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A0C64BAE7EB Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=ElM9B2yz X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azlp170120001.outbound.protection.outlook.com [IPv6:2a01:111:f403:c107::1]) by sourceware.org (Postfix) with ESMTPS id 5962A4BA79BB for ; Wed, 5 Aug 2026 14:36:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5962A4BA79BB Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nvidia.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5962A4BA79BB Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c107::1 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785940582; cv=pass; b=c3Of6Dpm66Y5HSRJu3Om5MvqMEfiR/747ONbiMBT9Ac8li0dbLbkN/07Sm1io6PdOU6GE6kIaFeYNaUOsp3LRS8Q2QzRI4iT4fbDDpjayK0dyFv+Qm333RMITIdDgUAFUJnDMEcR07R6k+N/2BkthQn0Kk2pYzr6EZP4J1rbULA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785940582; c=relaxed/simple; bh=sYACgdSzJeUELAuSnHAJ1syySQ9d/3nWwgtGlQagyiY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mU39De6suq0gL+M6CGIatYM4oloRmC+vE9D977pBtQpSCol1AlOvIQAzRVrVu8aLs/E6lNE3zrmyA7wvdiDWIrOCNALy+7hpA17LZs0TgtCBkAzW8c2TnNCXl/bi/FJ3pg5OXy1aC4qcassDWWilAmfGmLDbUPLRd/1drQcn5GM= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=ElM9B2yz DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5962A4BA79BB ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Bfh3+3debF3WO/nIkUUT7gFYDTIpnHlyenRU5n3Erf+vTnvy1dIDzFONh4xEfeUOUkk3dVoHdZRpo47bPfZlC0VDAueMOzYhXwHJnPYZ/dx4Px8UuNWy6Ze6pwbStjvdHEmhDqxpeIuyMExZf8koaz5SfmyVckPKKSYml8aY2Spcyw+nhuNTis/JeSOzy4UWBuZOIBmLWv/w0V+/Qh8Bn3f3g/nKhHZz3C66hZ9qQQxndFX2P/eHiHcY0z58dKwrNwaBalFmS4HELCvdzxc5mZhni/LEQgONYtey+KPCbAy5CgfZRaVFevlKafmusK85lWxu49EjQdmKlxMd+n6/bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=p2XkGY3q50YtiYfUfK9llov8g3W05SWuknanvKzK4lI=; b=bjnlJPLCZUfUnO2GZm94OVZXoZ0KQvVZQR8gnY0oFy4wuVWXPnPoGBeMbtj8qg9fnyKZu089ZMMePPPFsDPj1h3mR8IQX2wloQy4+Ur5279tSjh57FceukGaxMUkPKUcfx3bnxgGSLSifUA/mHLA9Kx5BdKoAsb5nYqopeD6dPeiSkR7fsNkniTL0wyoq020rhumxdA2FsgrYc+cF8cYtlWDxPFjc7rmYKwgopQaeERk3O7+iPjVajHussJg4vSshv4GYTMkV1lP1nUJAEjYKnlTa/xMivseSKoGYOPN9t2oAcN37If0CQ7LJEX2lyH7RnbRySjwp2F5oSNwwHO1DQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p2XkGY3q50YtiYfUfK9llov8g3W05SWuknanvKzK4lI=; b=ElM9B2yzz4dVWg6fiaVWwFpXNwU7x5pkXkvsjixytBWRTvfPOub/+hWNH7bolbbgxCOn5Y35g1mARMF+sb/j72s7jmBp/V+Y8Xsrxxpkoa4T0Qa3wanWPkCm1v20wLHwDvAPhW+O2LRiVSrN+mPKiatGIzKNYSCMFy7z4KJAEfAaa3WsWLzR9QTxuvQ0scavWRB58iXyWz4xKolkgbC4NA6yQM8nkHKi/8i3+c1jJ6Gn63tdovNbDKxdXOiO4Q1+Qte4ShbiS2cdgWf96JcaLMVzmE2oBLPfokE8SClimgzIsibx34N6w2SAzg1SctM1CCPBXNUUZPchsyLiRQl2+w== Received: from BN9PR03CA0586.namprd03.prod.outlook.com (2603:10b6:408:10d::21) by SA1PR12MB8859.namprd12.prod.outlook.com (2603:10b6:806:37c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.19; Wed, 5 Aug 2026 14:36:11 +0000 Received: from BL6PEPF00020E63.namprd04.prod.outlook.com (2603:10b6:408:10d:cafe::8f) by BN9PR03CA0586.outlook.office365.com (2603:10b6:408:10d::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.292.19 via Frontend Transport; Wed, 5 Aug 2026 14:36:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF00020E63.mail.protection.outlook.com (10.167.249.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.8 via Frontend Transport; Wed, 5 Aug 2026 14:36:10 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Wed, 5 Aug 2026 07:35:42 -0700 Received: from ktkachov-mlt.nvidia.com (10.126.231.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 5 Aug 2026 07:35:40 -0700 From: To: CC: , , , Kyrylo Tkachov Subject: [PATCH 3/4] genattrtab: Distribute generated code across multiple files Date: Wed, 5 Aug 2026 16:35:25 +0200 Message-ID: <20260805143526.27275-3-ktkachov@nvidia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260805143526.27275-1-ktkachov@nvidia.com> References: <20260805143526.27275-1-ktkachov@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.231.37] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00020E63:EE_|SA1PR12MB8859:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a6b23c7-d12e-412d-cf2a-08def2fee4b3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|376014|36860700016|1800799024|82310400026|6133799003|10067099003|56012099006|5023799004|11063799006|18002099003|22082099003|3023799007; X-Microsoft-Antispam-Message-Info: 6nocQzyc7deaS4KCcPTNhKgMu1e1x9B3DLCNOlls57cDagXCg8xVVV0usBO2RToAEG5GdqCRgl2PetBmDXszgHaatmTKmvnViKcXAU8cfPSNBOrhYv6q3HMUaFtMXeSobN04K3H795JWHqzPT9qWPxbU1ROlfcIX0aQ5HbkrA/ov1c1Sgi8Wl9IVV80pQIqlzSRQMBaAzCbQI8+CTGrzymccpnyzR0ZW9LChLYJ9s2aOYQgLDKhSwGexJ9eMJaZ4qCcHsuB2DxwMQ2aBVikSCpvZcTePZxd1p27epVsOXx9VlpllYA2CxNfgnp5gH1pcPbx0vRjybMtYQnFVdxAJY4KMNJtwJP7bhmVKByVvTnojvaU+z+1fCs2Xkeci5rDZ/EXmE0thrxYf8mQMGZYRKWf17e78NKFoal0A35N5jSQLyp+qfvekNrGDSZMvXPh4V66csh1F5Y6Kh/e5voRfqSeCQGk9jh7Pj4PWFPWONVsoj6VgX2HcWpWFEBjmGW4h/QA6bKCbmhzejiH1e7w1X3dgRUifxRb/Imb8U5+YS7ILFldo4mSaSVF+nJiR6uxcaXdYdjDMtQKq/oVpsGgISJUJMjmSqx0zqGk37lBPm0YhlnuZej0HSYixmdPUkV5uWgOaVcnHZ5paJoWGKao7ipi0m7JqC7AzC7uZ2lGHWfWuP+rmc1Zd8afUGH+WNDPBXkKRsKXPyfgiM49AwgH+ww== X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(23010399003)(376014)(36860700016)(1800799024)(82310400026)(6133799003)(10067099003)(56012099006)(5023799004)(11063799006)(18002099003)(22082099003)(3023799007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: stsRQVWcGpLrKlV1aXPsOBfef76EBxWfCuSPUQRFCxHUt+8Fvmjx5aUNlJ7yU39H+6RdKtLP4xYLwoAb24PCs/NEHGc7ZxczAJYxpk4Ees6zD4CyT2/wc2Fc9HotAhE1HmVJ+iNn4G+PuqKKp4aAvVPE1dZSMuzctIoFTjW7N+YucwJkToQfctotHBcAwtBRgSHqHIsYGJOqnu9ycjienYl8eSHI+a7ViflAPBkT9PLx0U/puZqq5AIbTAN5QGLi3VMX28KNW2YBIgCcL0P/Eas7uB7BJkVRNhBa+sICoLlJYZYcJMaQqbUVOpjigr1Ou6/jdR7Q0GOpKuPuzmTCtB/P49a60ejalgLakyBdOfcjkWyE2iAkUEC4h/ocYNY/g80ktg2gUfvax1m/qx/UdZLbcGSQzaYRa0hpQCQTEcckB00195BCX/IUVQBW1uvA X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2026 14:36:10.4008 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a6b23c7-d12e-412d-cf2a-08def2fee4b3 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00020E63.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8859 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LOCAL_AUTHENTICATION_FAIL_SPF, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@gcc.gnu.org From: Kyrylo Tkachov insn-attrtab.cc contains many independent get_attr_* functions. Several have large switches over every instruction code, making the single source one of the slowest objects in a measured AArch64 bootstrap. Let genattrtab write multiple attribute outputs, following genemit and genrecog. Reuse --with-insnemit-partitions and make -A repeatable. Register the -A, -D, and -L outputs through the common gensupport machinery. This gives all output roles one validation, open, selection, and close lifecycle. Place each attribute function in the shortest partition. Also distribute the fixed delay and length functions. Keep DFA and latency functions in their existing single files. The functions refer to one another through insn-attr.h and insn-attr-common.h, so generated headers do not change. With one -A option, all three outputs are byte-identical to the previous generator. With ten AArch64 partitions, the largest attribute part is about 85% smaller and its compile time is about 67% lower than for the original source. Native AArch64 and RISC-V cross all-gcc builds pass. Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux. Ok for trunk? Thanks, Kyrill gcc/ChangeLog: * Makefile.in (INSNATTRTAB_SPLITS_SEQ, INSNATTRTAB_SEQ_SRC) (INSNATTRTAB_SEQ_TMP, INSNATTRTAB_SEQ_O): New variables. (OBJS): Replace insn-attrtab.o with $(INSNATTRTAB_SEQ_O). (MOSTLYCLEANFILES): Add $(INSNATTRTAB_SEQ_SRC), retaining the legacy unnumbered source for cleanup. (.PRECIOUS): Use $(INSNATTRTAB_SEQ_SRC). (s-attrtab): Generate and move numbered attribute files. Stop when a move fails. * configure.ac (--with-insnemit-partitions): Document all generators which use the option. * configure: Regenerate. * genattrtab.cc (attr_file_name, attr_file): Remove. (output_files): New variable. (dfa_file_name, latency_file_name): Retain output names. (make_automaton_attrs): Write to the first attribute partition. (handle_arg): Register repeatable attribute outputs. (main): Register fixed outputs and use the common output helpers. Distribute attribute, delay, and length functions. * final.cc (length_unit_log): Update comment for partitioned output. * config/arc/arc-protos.h (regno_clobbered_p): Likewise. * config/ia64/ia64.cc (bundling): Likewise. * config/ia64/t-ia64 (insn-attrtab.o-warn): Replace with per-partition warning variables. * config/sh/sh.h (code_for_indirect_jump_scratch): Update comment for partitioned output. contrib/ChangeLog: * filter-clang-warnings.py (skip_warning): Match numbered attribute files. Signed-off-by: Kyrylo Tkachov --- contrib/filter-clang-warnings.py | 2 +- gcc/Makefile.in | 32 ++++++++--- gcc/config/arc/arc-protos.h | 3 +- gcc/config/ia64/ia64.cc | 4 +- gcc/config/ia64/t-ia64 | 3 +- gcc/config/sh/sh.h | 5 +- gcc/configure | 11 ++-- gcc/configure.ac | 6 +- gcc/final.cc | 2 +- gcc/genattrtab.cc | 99 +++++++++++++++++--------------- 10 files changed, 98 insertions(+), 69 deletions(-) diff --git a/contrib/filter-clang-warnings.py b/contrib/filter-clang-warnings.py index 8eec366b4bc..6b01b559b6e 100755 --- a/contrib/filter-clang-warnings.py +++ b/contrib/filter-clang-warnings.py @@ -56,7 +56,7 @@ def skip_warning(filename, message): 'ipa-strub.cc': ['-Wunused-but-set-variable'], 'insn-modes.cc': ['-Wshift-count-overflow'], 'insn-emit.cc': ['-Wtautological-compare'], - 'insn-attrtab.cc': ['-Wparentheses-equality'], + 'insn-attrtab': ['-Wparentheses-equality'], 'omp-builtins.def': ['-Wc++11-narrowing'], 'wide-int.h': ['-Wnontrivial-memcall'], 'i386.md': ['-Wparentheses-equality', '-Wtautological-compare', diff --git a/gcc/Makefile.in b/gcc/Makefile.in index ee2f9022eab..19957477e5b 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -241,6 +241,14 @@ INSNRECOG_SEQ_SRC = $(patsubst %, insn-recog-%.cc, $(INSNRECOG_SPLITS_SEQ)) INSNRECOG_SEQ_TMP = $(patsubst %, tmp-recog-%.cc, $(INSNRECOG_SPLITS_SEQ)) INSNRECOG_SEQ_O = $(patsubst %, insn-recog-%.o, $(INSNRECOG_SPLITS_SEQ)) +# Re-use the split number for insn-attrtab as well. +INSNATTRTAB_SPLITS_SEQ = $(wordlist 1,$(NUM_INSNEMIT_SPLITS),$(one_to_9999)) +INSNATTRTAB_SEQ_SRC = $(patsubst %, insn-attrtab-%.cc, \ + $(INSNATTRTAB_SPLITS_SEQ)) +INSNATTRTAB_SEQ_TMP = $(patsubst %, tmp-attrtab-%.cc, \ + $(INSNATTRTAB_SPLITS_SEQ)) +INSNATTRTAB_SEQ_O = $(patsubst %, insn-attrtab-%.o, $(INSNATTRTAB_SPLITS_SEQ)) + # These files are to have specific diagnostics suppressed, or are not to # be subject to -Werror: # flex output may yield harmless "no previous prototype" warnings @@ -1405,7 +1413,7 @@ OBJS = \ $(GIMPLE_MATCH_PD_SEQ_O) \ gimple-match-exports.o \ $(GENERIC_MATCH_PD_SEQ_O) \ - insn-attrtab.o \ + $(INSNATTRTAB_SEQ_O) \ insn-automata.o \ insn-dfatab.o \ $(INSNEMIT_SEQ_O) \ @@ -1986,8 +1994,10 @@ FULL_DRIVER_NAME=$(target_noncanonical)-gcc-$(version)$(exeext) MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \ insn-output.cc $(INSNRECOG_SEQ_SRC) insn-recog.h \ $(INSNEMIT_SEQ_SRC) insn-extract.cc insn-peep.cc \ - insn-attr.h insn-attr-common.h insn-attrtab.cc insn-dfatab.cc \ - insn-latencytab.cc insn-opinit.cc insn-opinit.h insn-preds.cc insn-constants.h \ + insn-attr.h insn-attr-common.h $(INSNATTRTAB_SEQ_SRC) insn-attrtab.cc \ + insn-dfatab.cc insn-latencytab.cc insn-opinit.cc \ + insn-opinit.h insn-preds.cc \ + insn-constants.h \ tm-preds.h tm-constrs.h checksum-options $(GIMPLE_MATCH_PD_SEQ_SRC) \ $(GENERIC_MATCH_PD_SEQ_SRC) gimple-match-auto.h generic-match-auto.h \ tree-check.h min-insn-modes.cc insn-modes.cc insn-modes.h insn-modes-inline.h \ @@ -2763,7 +2773,7 @@ $(common_out_object_file): $(common_out_file) .PRECIOUS: insn-config.h insn-flags.h insn-codes.h insn-constants.h \ $(INSNEMIT_SEQ_SRC) insn-recog.h $(INSNRECOG_SEQ_SRC) \ insn-extract.cc insn-output.cc \ - insn-peep.cc insn-attr.h insn-attr-common.h insn-attrtab.cc \ + insn-peep.cc insn-attr.h insn-attr-common.h $(INSNATTRTAB_SEQ_SRC) \ insn-dfatab.cc insn-latencytab.cc insn-preds.cc \ $(GIMPLE_MATCH_PD_SEQ_SRC) $(GENERIC_MATCH_PD_SEQ_SRC) \ gimple-match-auto.h generic-match-auto.h insn-target-def.h @@ -2850,13 +2860,19 @@ s-check : build/gencheck$(build_exeext) $(SHELL) $(srcdir)/../move-if-change tmp-check.h tree-check.h $(STAMP) s-check -# genattrtab produces three files: tmp-{attrtab.cc,dfatab.cc,latencytab.cc} -insn-attrtab.cc insn-dfatab.cc insn-latencytab.cc: s-attrtab ; @true +# genattrtab splits the attribute functions like genemit and additionally +# produces tmp-dfatab.cc and tmp-latencytab.cc. +$(INSNATTRTAB_SEQ_SRC): s-attrtab ; @true +insn-dfatab.cc insn-latencytab.cc: s-attrtab ; @true s-attrtab : $(MD_DEPS) build/genattrtab$(build_exeext) \ insn-conditions.md $(RUN_GEN) build/genattrtab$(build_exeext) $(md_file) insn-conditions.md \ - -Atmp-attrtab.cc -Dtmp-dfatab.cc -Ltmp-latencytab.cc - $(SHELL) $(srcdir)/../move-if-change tmp-attrtab.cc insn-attrtab.cc + $(addprefix -A,${INSNATTRTAB_SEQ_TMP}) \ + -Dtmp-dfatab.cc -Ltmp-latencytab.cc + for id in $(INSNATTRTAB_SPLITS_SEQ); do \ + $(SHELL) $(srcdir)/../move-if-change tmp-attrtab-$$id.cc \ + insn-attrtab-$$id.cc || exit 1; \ + done $(SHELL) $(srcdir)/../move-if-change tmp-dfatab.cc insn-dfatab.cc $(SHELL) $(srcdir)/../move-if-change tmp-latencytab.cc insn-latencytab.cc $(STAMP) s-attrtab diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h index fc36d52ead0..380f2c39777 100644 --- a/gcc/config/arc/arc-protos.h +++ b/gcc/config/arc/arc-protos.h @@ -93,7 +93,8 @@ extern bool arc_text_label (rtx_insn *insn); extern bool arc_short_comparison_p (rtx, int); extern bool arc_epilogue_uses (int regno); extern bool arc_eh_uses (int regno); -/* insn-attrtab.cc doesn't include reload.h, which declares regno_clobbered_p. */ +/* Generated attribute code does not include reload.h, which declares + regno_clobbered_p. */ extern int regno_clobbered_p (unsigned int, rtx_insn *, machine_mode, int); extern bool arc_legitimize_reload_address (rtx *, machine_mode, int, int); extern void arc_secondary_reload_conv (rtx, rtx, rtx, bool); diff --git a/gcc/config/ia64/ia64.cc b/gcc/config/ia64/ia64.cc index b06158ba7bc..292c6b3d939 100644 --- a/gcc/config/ia64/ia64.cc +++ b/gcc/config/ia64/ia64.cc @@ -9286,8 +9286,8 @@ bundling (FILE *dump, int verbose, rtx_insn *prev_head_insn, rtx_insn *tail) curr_state = curr_state->next) if (verbose >= 2 && dump) { - /* This structure is taken from generated code of the - pipeline hazard recognizer (see file insn-attrtab.cc). + /* This structure is taken from the generated pipeline hazard + recognizer code. Please don't forget to change the structure if a new automaton is added to .md file. */ struct DFA_chip diff --git a/gcc/config/ia64/t-ia64 b/gcc/config/ia64/t-ia64 index 4c37dd89fba..2bf590d89df 100644 --- a/gcc/config/ia64/t-ia64 +++ b/gcc/config/ia64/t-ia64 @@ -22,7 +22,8 @@ ia64-c.o: $(srcdir)/config/ia64/ia64-c.cc $(CONFIG_H) $(SYSTEM_H) \ $(srcdir)/config/ia64/ia64-c.cc # genattrtab generates very long string literals. -insn-attrtab.o-warn = -Wno-error +$(foreach id, $(INSNATTRTAB_SPLITS_SEQ), \ + $(eval insn-attrtab-$(id).o-warn = -Wno-error)) ia64.o: $(srcdir)/config/ia64/ia64.cc debug.h $(PARAMS_H) sel-sched.h reload.h \ $(OPTS_H) dumpfile.h $(HASH_TABLE_H) diff --git a/gcc/config/sh/sh.h b/gcc/config/sh/sh.h index 9b2ed6a33db..f3973e7fcab 100644 --- a/gcc/config/sh/sh.h +++ b/gcc/config/sh/sh.h @@ -24,8 +24,9 @@ along with GCC; see the file COPYING3. If not see #include "config/vxworks-dummy.h" -/* Unfortunately, insn-attrtab.cc doesn't include insn-codes.h. We can't - include it here, because bconfig.h is also included by gencodes.cc . */ +/* Unfortunately, generated attribute code does not include insn-codes.h. + We can't include it here, because bconfig.h is also included by + gencodes.cc . */ /* ??? No longer true. */ extern int code_for_indirect_jump_scratch; diff --git a/gcc/configure b/gcc/configure index eea63c9721c..c9f1feee86b 100755 --- a/gcc/configure +++ b/gcc/configure @@ -1882,8 +1882,8 @@ Optional Packages: Set the number of partitions to make for gimple and generic when splitting match.pd. [default=10] --with-insnemit-partitions=num - Set the number of partitions of insn-emit.cc for - genemit and genrecog to create. [default=10] + Set the number of partitions used by genemit, + genrecog and genattrtab. [default=10] --with-dwarf2 force the default debug format to be DWARF 2 (or later) --with-specs=SPECS add SPECS to driver command-line processing @@ -7907,7 +7907,8 @@ fi -# Specify the number of splits of insn-emit.cc and insn-recog.cc to generate. +# Specify the number of output partitions used by the machine-description +# generators. # Check whether --with-insnemit-partitions was given. if test "${with_insnemit_partitions+set}" = set; then : @@ -21921,7 +21922,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21924 "configure" +#line 21925 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -22027,7 +22028,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 22030 "configure" +#line 22031 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index 58576227136..a8b0a08f20d 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -902,10 +902,12 @@ fi AC_SUBST(DEFAULT_MATCHPD_PARTITIONS) -# Specify the number of splits of insn-emit.cc and insn-recog.cc to generate. +# Specify the number of output partitions used by the machine-description +# generators. AC_ARG_WITH(insnemit-partitions, [AS_HELP_STRING([--with-insnemit-partitions=num], -[Set the number of partitions of insn-emit.cc for genemit and genrecog to create. [default=10]])], +[Set the number of partitions used by genemit, genrecog and genattrtab. +[default=10]])], [DEFAULT_INSNEMIT_PARTITIONS="$with_insnemit_partitions"], [DEFAULT_INSNEMIT_PARTITIONS=10]) if (test $DEFAULT_INSNEMIT_PARTITIONS -lt 1); then AC_MSG_ERROR(m4_normalize([ diff --git a/gcc/final.cc b/gcc/final.cc index 0152be59fc8..e2761d056ea 100644 --- a/gcc/final.cc +++ b/gcc/final.cc @@ -142,7 +142,7 @@ static int override_discriminator; /* Whether to force emission of a line note before the next insn. */ static bool force_source_line = false; -extern const int length_unit_log; /* This is defined in insn-attrtab.cc. */ +extern const int length_unit_log; /* Defined in generated attribute code. */ /* Nonzero while outputting an `asm' with operands. This means that inconsistencies are the user's fault, so don't die. diff --git a/gcc/genattrtab.cc b/gcc/genattrtab.cc index a2cf08d5305..eab05cefeb8 100644 --- a/gcc/genattrtab.cc +++ b/gcc/genattrtab.cc @@ -305,16 +305,17 @@ static rtx min_fn (rtx); functions and tables. This made insn-attrtab.cc _the_ bottle-neck in a parallel build, and even made it impossible to build GCC on machines with relatively small RAM space (PR other/29442). Therefore, the - attribute functions/tables are now written out to three separate - files: all "*insn_default_latency" functions go to LATENCY_FILE_NAME, - all "*internal_dfa_insn_code" functions go to DFA_FILE_NAME, and the - rest goes to ATTR_FILE_NAME. */ + attribute functions/tables are now written out to separate files: all + "*insn_default_latency" functions go to the latency output, all + "*internal_dfa_insn_code" functions go to the DFA output, and the rest is + distributed across the attribute outputs the way genemit and genrecog + distribute their output. */ -static const char *attr_file_name = NULL; -static const char *dfa_file_name = NULL; -static const char *latency_file_name = NULL; +/* The files produced by the generator. */ +static auto_vec output_files; -static FILE *attr_file, *dfa_file, *latency_file; +static FILE *dfa_file, *latency_file; +static const char *dfa_file_name, *latency_file_name; /* Hash table for sharing RTL and strings. */ @@ -4981,6 +4982,9 @@ make_automaton_attrs (void) tune_attr = find_tune_attr (all_insn_reservs->condexp); if (tune_attr != NULL) { + /* The function pointers and init_sched_attrs go to the first + attribute file. */ + FILE *attr_file = output_files[0].file; rtx *condexps = XNEWVEC (rtx, n_insn_reservs * 3); struct attr_value *val; bool first = true; @@ -5206,29 +5210,22 @@ write_header (FILE *outf) fprintf (outf, "#define operands recog_data.operand\n\n"); } -static FILE * -open_outfile (const char *file_name) -{ - FILE *outf; - outf = fopen (file_name, "w"); - if (! outf) - fatal ("cannot open file %s: %s", file_name, xstrerror (errno)); - write_header (outf); - return outf; -} - static bool handle_arg (const char *arg) { switch (arg[1]) { case 'A': - attr_file_name = &arg[2]; + add_generator_output (output_files, &arg[2], true); return true; case 'D': + if (dfa_file_name) + fatal ("option -D specified more than once"); dfa_file_name = &arg[2]; return true; case 'L': + if (latency_file_name) + fatal ("option -L specified more than once"); latency_file_name = &arg[2]; return true; default: @@ -5248,9 +5245,22 @@ main (int argc, const char **argv) if (!init_rtx_reader_args_cb (argc, argv, handle_arg)) return FATAL_EXIT_CODE; - attr_file = open_outfile (attr_file_name); - dfa_file = open_outfile (dfa_file_name); - latency_file = open_outfile (latency_file_name); + if (output_files.is_empty ()) + fatal ("no -A output file specified"); + if (!dfa_file_name) + fatal ("no -D output file specified"); + if (!latency_file_name) + fatal ("no -L output file specified"); + + unsigned int dfa_index + = add_generator_output (output_files, dfa_file_name, false); + unsigned int latency_index + = add_generator_output (output_files, latency_file_name, false); + open_generator_outputs (output_files); + dfa_file = output_files[dfa_index].file; + latency_file = output_files[latency_index].file; + for (generator_output &output : output_files) + write_header (output.file); obstack_init (hash_obstack); obstack_init (temp_obstack); @@ -5363,50 +5373,47 @@ main (int argc, const char **argv) /* Perform any possible optimizations to speed up compilation. */ optimize_attrs (num_insn_codes); - /* Now write out all the `gen_attr_...' routines. Do these before the - special routines so that they get defined before they are used. */ + /* Now write out all the `get_attr_...' routines. The DFA and latency + routines go to their own files; the rest are distributed across the + attribute files. They only refer to each other through the extern + declarations in insn-attr.h and insn-attr-common.h. */ for (i = 0; i < MAX_ATTRS_INDEX; i++) for (attr = attrs[i]; attr; attr = attr->next) { - FILE *outf; + FILE *outf; - if (startswith(attr->name, "*internal_dfa_insn_code")) + if (attr->is_special || attr->is_const) + continue; + + if (startswith (attr->name, "*internal_dfa_insn_code")) outf = dfa_file; else if (startswith (attr->name, "*insn_default_latency")) outf = latency_file; else - outf = attr_file; + outf = choose_output (output_files); - if (! attr->is_special && ! attr->is_const) - write_attr_get (outf, attr); + write_attr_get (outf, attr); } /* Write out delay eligibility information, if DEFINE_DELAY present. (The function to compute the number of delay slots will be written below.) */ - write_eligible_delay (attr_file, "delay"); + write_eligible_delay (choose_output (output_files), "delay"); if (have_annul_true) - write_eligible_delay (attr_file, "annul_true"); + write_eligible_delay (choose_output (output_files), "annul_true"); else - write_dummy_eligible_delay (attr_file, "annul_true"); + write_dummy_eligible_delay (choose_output (output_files), "annul_true"); if (have_annul_false) - write_eligible_delay (attr_file, "annul_false"); + write_eligible_delay (choose_output (output_files), "annul_false"); else - write_dummy_eligible_delay (attr_file, "annul_false"); + write_dummy_eligible_delay (choose_output (output_files), "annul_false"); /* Write out constant delay slot info. */ - write_const_num_delay_slots (attr_file); - - write_length_unit_log (attr_file); + write_const_num_delay_slots (choose_output (output_files)); - if (fclose (attr_file) != 0) - fatal ("cannot close file %s: %s", attr_file_name, xstrerror (errno)); - if (fclose (dfa_file) != 0) - fatal ("cannot close file %s: %s", dfa_file_name, xstrerror (errno)); - if (fclose (latency_file) != 0) - fatal ("cannot close file %s: %s", latency_file_name, xstrerror (errno)); + write_length_unit_log (choose_output (output_files)); - return SUCCESS_EXIT_CODE; + return (close_generator_outputs (output_files) + ? SUCCESS_EXIT_CODE : FATAL_EXIT_CODE); } - From patchwork Wed Aug 5 14:35:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 140663 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CE954BA2E32 for ; Wed, 5 Aug 2026 14:37:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CE954BA2E32 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=Blmw98yD X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010028.outbound.protection.outlook.com [52.101.61.28]) by sourceware.org (Postfix) with ESMTPS id 187574BA9013 for ; Wed, 5 Aug 2026 14:36:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 187574BA9013 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nvidia.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 187574BA9013 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.101.61.28 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785940585; cv=pass; b=H9NfAJkceN3ur75FOuVTrfy1rtVMBQx/axP0jTzFcyHuh2LFsp/9fJc9nSGxijDJ31yxryOLWRMqTij88t27kGHklVOKsf/MpiJS7RMa56EC7Rwo4p6fKKbECIHADoVkOAvXaPMfJUmcmkjYl8i+MxJ7xbriDOMQrzZhaEapJyE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785940585; c=relaxed/simple; bh=uQvaKFgXdDctPacJk0468+biP2Yx44+rjlaxMRaAzJs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kcNs1u5aBJj9625SI1PRzZ9iFSGUfeXN48GEJVrG6ncWBIgOQrLi/cAFaf1lPLttz6b7QHq0pRy+1mruywpdIK7yUFnZgiDOklLbacDQGe+t+j3fYdjbI/JoeXXEHkwEE66jln+GILeqODtRYbp1Ll8v4dzuAuyHDBWgwHM5Crk= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=Blmw98yD DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 187574BA9013 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AzLhOgxNRehY95WB7JhmkwxQrF3KqvBv0r0JQWdhiBbhteAz/t/wz9ykuThwxxXxGcXWyH1FNxKSrQfdIMc9bevnCz2X12L1l3P9o94UFYeoSAkXu344Fj9bAhfWbKcQcc1wXejchucXpDHkYdTi+kgt08vc7gQ5hL38iyI909KO4QQmYkX0NvgFiMQA3r95XADclM0vDPoHPXCkVC/86nDUqRflaLSEAN04WsviyYxpqvNhOV/i0BS1r9mgVx3lpoMdscQ0aLGbRDZqnGWONy3iM2OCutLzctEN+D584rPooAmHrb/glNo0CAsueIT6KRtJT79SSfIMtQuwoCTNzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PZB8IdcLTnBOPYsw9QuszBRQ2Y2V391q2fobxOC79Qk=; b=Jinphb2dyRCJeO2441NqXuZdgRWKPtUZaxz5H+iM5ipUGAFVIw6/FD5Zh6gmtAA7vOZeOgFG5xZCF2veCsgHAnikfHA68LKSZgBYcRspOkA7i/7T56t3pnqKqJckmXzUl869fWQz2ZdQqAGxBtn1whv2CFKg6Fy81ib4HsF+llFg6Ob1ucEOuSBsIrvpyIRxOVbxPaxWadpuumG2HxM6tzhODpZLvyYHpPmrUXCs/9tjuduz5EcO92ikcgl/NvgC2eQn4RbNgcixjPIFlPABrr0iU4JuOTlLcaGLmQ3nO6dCeRD1FfiJqwFYNKKaEXacXp4Oy4OYoG9pmMfCh8miQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PZB8IdcLTnBOPYsw9QuszBRQ2Y2V391q2fobxOC79Qk=; b=Blmw98yDj3nJQEpys+e9rGPZWMRRGDbqd1Fd6m6ns1hfy23uai+jBz28uWTn2DbofwCCzLR3MC5UnbWigP5MFug5KyOOmZbfFKX9ECFVYigInMQpm0QETQs1SiBoGAbF1O6fQtwCT4bnyHLhZiC3iAGakJT9xmNb5FMbXp984KN97WbObKL4opHT8WkZ4eckXu5jUrvA8OOS9Ndm28EmwyhAQESOFEjLq3ZpCp5Fbv6/kp9wi3cvbT7IbcooZ8YyAKuQwZPjYTjHCSxd0hBugjsZk4/ovVH+4UGDYLx+nFiDX2mnjPfevVFzDhWZqwhzLgy3GWql531AFmlq17u5wQ== Received: from BN9PR03CA0516.namprd03.prod.outlook.com (2603:10b6:408:131::11) by CYYPR12MB8730.namprd12.prod.outlook.com (2603:10b6:930:c1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.19; Wed, 5 Aug 2026 14:36:14 +0000 Received: from BL6PEPF00020E65.namprd04.prod.outlook.com (2603:10b6:408:131:cafe::29) by BN9PR03CA0516.outlook.office365.com (2603:10b6:408:131::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.292.16 via Frontend Transport; Wed, 5 Aug 2026 14:36:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF00020E65.mail.protection.outlook.com (10.167.249.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.8 via Frontend Transport; Wed, 5 Aug 2026 14:36:13 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Wed, 5 Aug 2026 07:35:44 -0700 Received: from ktkachov-mlt.nvidia.com (10.126.231.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 5 Aug 2026 07:35:42 -0700 From: To: CC: , , , Kyrylo Tkachov Subject: [PATCH 4/4] configure: Add target defaults for MD generator partitions Date: Wed, 5 Aug 2026 16:35:26 +0200 Message-ID: <20260805143526.27275-4-ktkachov@nvidia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260805143526.27275-1-ktkachov@nvidia.com> References: <20260805143526.27275-1-ktkachov@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.231.37] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00020E65:EE_|CYYPR12MB8730:EE_ X-MS-Office365-Filtering-Correlation-Id: d3f6f21b-0736-41ef-fecb-08def2fee693 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700016|23010399003|376014|1800799024|82310400026|6133799003|10067099003|11063799006|56012099006|22082099003|18002099003|3023799007; X-Microsoft-Antispam-Message-Info: lqMe4NYV8rogwT9RzZ5alBKvcZEF7pgkV45VBiqhV/u3EMgNWuKkLfPTRWqOKGW5BjS9yDliT8Ph1XoxKwHCdHEPbxUkJNfqD4RqKwbkkAaE0IOgQ/iy15KCxyyyHhSFJQfCW9I6xLyNIGt0UIYBigLsndQsk5h7Vc3tcOTjVwts/Nc9UNN+HUKWa0JF/lz29BUKX/dhV34xBAVXvrps178EacHUhicT2MI46Cqiu+gFava8JHh9D4jqLEAalUdb9rQhMSmNQiafPmtVOMdOD0v6THXU/SarG2ByogL4puMQYt8VMmmvKBFTMd5gis00+6nRNA2aA8rqSUDjbXHxL2YaI/A1wddBC+GL7oBkzayzO4DDhziWlTaGCBDivQwMt0p+5RABRZjlYGiHtTtWlYONN5P5DuF82ZrhQh2vhJE/x64KpUvhlFNjbYv0wKpKfqKTnAcVFMd1xLrwENnXjztEKooB5IC2sd9ZJidEH9W/Sw4V0kzIpuh/J/yOhFPGZg1IuinxO4OGA+E7HVIocN1Pc3WkHa00yWXzHbUTRYNQmzM8zteK5S1yng6zLBTiR8KJ+yV4+sPsb0dBfyZpburw+D+D8Yzze1KlmjyCrNS4YuBxKTMzgSIE6o/Hg6mpLighaEcJbk74pqN0RPp6KGuveQZZmH4XUvIcClZi2N4Fm3/JssGdRUQZBJ9tOP+4Kdwwk9gAhdIS2WTj4+eBbw== X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(36860700016)(23010399003)(376014)(1800799024)(82310400026)(6133799003)(10067099003)(11063799006)(56012099006)(22082099003)(18002099003)(3023799007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +XOcf+MSVHaWLjmE6TgFAGVDnaPAJWZDdWJXXN86fHfuDCPDFBToR2u0fliYc83JC3YGn2AFiBZPBg6tUBykxJcDGAj5oZpMX1Laun7/fjDTsDTyIt6iAmHs9n5Jru+lGm2/S+4Ub1cU0HAqCrR/xDN1LUgIVlpPFJftEoZNCUQDH1MPloJLB+V0Gr7OEk4udffEAnlJal1dUi+gDSqPx9kMDvmrZIVIgdfYsAbnv9B9Dakrb4cstwj+JEMUF5ZDKCqLTfZ+C3ZqQKah5TuQldnQzyMVXB3c0Qo+INXsx59Umbt7NaHhyLF4e5FedMnjUwC0F/j1jxk+Ga7DsMnSwy0EQlm5PNdBYga1RqN76CFvFkk0ezx9CMF/e6RMy4UWmaU3HA4kZdeYRoYpFJgs1vv/CFxmUaBCbA8fqDZp3tuQml8NkEVniR5yJmGxAuPN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2026 14:36:13.5380 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d3f6f21b-0736-41ef-fecb-08def2fee693 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00020E65.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8730 X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, LOCAL_AUTHENTICATION_FAIL_SPF, MEDICAL_SUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@gcc.gnu.org From: Kyrylo Tkachov The generated emit, recog, and attrtab sources have different shapes. One partition count therefore does not give each generator the same compile critical path. Tamar Christina suggested a colon-separated configuration value so that each generator can have an independent count. The existing --with-insnemit-partitions name refers only to genemit, but the option now controls three machine-description generators. Add --with-md-generator-partitions as the canonical name. Given --with-insnemit-partitions was in previously-released GCC, do we need to keep it? This patch keeps it as an alias, but I can remove it if needed. Accept either one count for all three generators or E:R:A for separate genemit, genrecog, and genattrtab counts. Let config.gcc set the target default in either form. Keep 10 as the generic default and let an explicit configure option take precedence. Reject malformed values and counts outside the 1 to 9999 range supported by one_to_9999. Make each generator stamp depend on Makefile. This regenerates the source set after reconfigure changes a count, including when the new set has files that did not exist before. Stop when any emit or recog output move fails. The previous foreach command reported only the status of the last move. Remove all numbered generator sources during mostlyclean, including files left after a partition-count decrease. I think we want each target to have the option of setting the defaults as the optimal split is ultimately a function of the complexity and "shape" of the target MD files. Set the AArch64 default to 16:16:8, for example. Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux. Ok for trunk? Thanks, Kyrill gcc/ChangeLog: * Makefile.in (NUM_INSNRECOG_SPLITS): New variable. (INSNRECOG_SPLITS_SEQ): Use it. (NUM_INSNATTRTAB_SPLITS): New variable. (INSNATTRTAB_SPLITS_SEQ): Use it. (MOSTLYCLEANFILES): Remove all numbered generator sources. (s-tmp-emit, s-tmp-recog): Stop when an output move fails. (s-tmp-emit, s-tmp-recog, s-attrtab): Depend on Makefile. * config.gcc (default_md_generator_partitions): New variable. Document its scalar and tuple forms. (aarch64*-*-*): Set the target default. * configure.ac (--with-md-generator-partitions): New option. (--with-insnemit-partitions): Keep as a deprecated alias. Use the target default when no option is specified. Validate and substitute all three counts. * configure: Regenerate. * doc/install.texi (--with-md-generator-partitions): Document. Suggested-by: Tamar Christina Signed-off-by: Kyrylo Tkachov --- gcc/Makefile.in | 37 ++++++++++-------- gcc/config.gcc | 8 ++++ gcc/configure | 92 ++++++++++++++++++++++++++++++++++++++------ gcc/configure.ac | 82 +++++++++++++++++++++++++++++++++++---- gcc/doc/install.texi | 11 ++++++ 5 files changed, 194 insertions(+), 36 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 19957477e5b..7bd4a1009e1 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -235,14 +235,16 @@ INSNEMIT_SEQ_SRC = $(patsubst %, insn-emit-%.cc, $(INSNEMIT_SPLITS_SEQ)) INSNEMIT_SEQ_TMP = $(patsubst %, tmp-emit-%.cc, $(INSNEMIT_SPLITS_SEQ)) INSNEMIT_SEQ_O = $(patsubst %, insn-emit-%.o, $(INSNEMIT_SPLITS_SEQ)) -# Re-use the split number for insn-recog as well. -INSNRECOG_SPLITS_SEQ = $(wordlist 1,$(NUM_INSNEMIT_SPLITS),$(one_to_9999)) +# The number of splits to be made for the insn-recog files. +NUM_INSNRECOG_SPLITS = @DEFAULT_INSNRECOG_PARTITIONS@ +INSNRECOG_SPLITS_SEQ = $(wordlist 1,$(NUM_INSNRECOG_SPLITS),$(one_to_9999)) INSNRECOG_SEQ_SRC = $(patsubst %, insn-recog-%.cc, $(INSNRECOG_SPLITS_SEQ)) INSNRECOG_SEQ_TMP = $(patsubst %, tmp-recog-%.cc, $(INSNRECOG_SPLITS_SEQ)) INSNRECOG_SEQ_O = $(patsubst %, insn-recog-%.o, $(INSNRECOG_SPLITS_SEQ)) -# Re-use the split number for insn-attrtab as well. -INSNATTRTAB_SPLITS_SEQ = $(wordlist 1,$(NUM_INSNEMIT_SPLITS),$(one_to_9999)) +# The number of splits to be made for the insn-attrtab files. +NUM_INSNATTRTAB_SPLITS = @DEFAULT_INSNATTRTAB_PARTITIONS@ +INSNATTRTAB_SPLITS_SEQ = $(wordlist 1,$(NUM_INSNATTRTAB_SPLITS),$(one_to_9999)) INSNATTRTAB_SEQ_SRC = $(patsubst %, insn-attrtab-%.cc, \ $(INSNATTRTAB_SPLITS_SEQ)) INSNATTRTAB_SEQ_TMP = $(patsubst %, tmp-attrtab-%.cc, \ @@ -1992,9 +1994,9 @@ TREECHECKING = @TREECHECKING@ FULL_DRIVER_NAME=$(target_noncanonical)-gcc-$(version)$(exeext) MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \ - insn-output.cc $(INSNRECOG_SEQ_SRC) insn-recog.h \ - $(INSNEMIT_SEQ_SRC) insn-extract.cc insn-peep.cc \ - insn-attr.h insn-attr-common.h $(INSNATTRTAB_SEQ_SRC) insn-attrtab.cc \ + insn-output.cc insn-recog-*.cc insn-recog.h \ + insn-emit-*.cc insn-extract.cc insn-peep.cc \ + insn-attr.h insn-attr-common.h insn-attrtab-*.cc insn-attrtab.cc \ insn-dfatab.cc insn-latencytab.cc insn-opinit.cc \ insn-opinit.h insn-preds.cc \ insn-constants.h \ @@ -2831,24 +2833,27 @@ $(simple_generated_c:insn-%.cc=s-%): s-%: build/gen%$(build_exeext) # genemit splits its output into different files and doesn't write to # stdout. (but rather to tmp-emit-01.cc..tmp-emit-10.cc) $(INSNEMIT_SEQ_SRC): s-tmp-emit; @true -s-tmp-emit: build/genemit$(build_exeext) $(MD_DEPS) insn-conditions.md +s-tmp-emit: build/genemit$(build_exeext) $(MD_DEPS) insn-conditions.md Makefile $(RUN_GEN) build/genemit$(build_exeext) $(md_file) insn-conditions.md \ $(addprefix -O,${INSNEMIT_SEQ_TMP}) - $(foreach id, $(INSNEMIT_SPLITS_SEQ), \ - $(SHELL) $(srcdir)/../move-if-change tmp-emit-$(id).cc \ - insn-emit-$(id).cc;) + for id in $(INSNEMIT_SPLITS_SEQ); do \ + $(SHELL) $(srcdir)/../move-if-change tmp-emit-$$id.cc \ + insn-emit-$$id.cc || exit 1; \ + done $(STAMP) s-tmp-emit # Same for genrecog. $(INSNRECOG_SEQ_SRC): s-tmp-recog; @true insn-recog.h: s-tmp-recog; @true -s-tmp-recog: build/genrecog$(build_exeext) $(MD_DEPS) insn-conditions.md +s-tmp-recog: build/genrecog$(build_exeext) $(MD_DEPS) \ + insn-conditions.md Makefile $(RUN_GEN) build/genrecog$(build_exeext) $(md_file) insn-conditions.md \ -Hinsn-recog.h \ $(addprefix -O,${INSNRECOG_SEQ_TMP}) - $(foreach id, $(INSNRECOG_SPLITS_SEQ), \ - $(SHELL) $(srcdir)/../move-if-change tmp-recog-$(id).cc \ - insn-recog-$(id).cc;) + for id in $(INSNRECOG_SPLITS_SEQ); do \ + $(SHELL) $(srcdir)/../move-if-change tmp-recog-$$id.cc \ + insn-recog-$$id.cc || exit 1; \ + done $(STAMP) s-tmp-recog # gencheck doesn't read the machine description, and the file produced @@ -2865,7 +2870,7 @@ s-check : build/gencheck$(build_exeext) $(INSNATTRTAB_SEQ_SRC): s-attrtab ; @true insn-dfatab.cc insn-latencytab.cc: s-attrtab ; @true s-attrtab : $(MD_DEPS) build/genattrtab$(build_exeext) \ - insn-conditions.md + insn-conditions.md Makefile $(RUN_GEN) build/genattrtab$(build_exeext) $(md_file) insn-conditions.md \ $(addprefix -A,${INSNATTRTAB_SEQ_TMP}) \ -Dtmp-dfatab.cc -Ltmp-latencytab.cc diff --git a/gcc/config.gcc b/gcc/config.gcc index 0477bf22c8a..2bb4baefed7 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -54,6 +54,12 @@ # support, the default value of # $default_gnu_indirect_function is set to # "no" except for targets which are known to be OK. +# +# default_md_generator_partitions +# The default partition counts for genemit, genrecog, +# and genattrtab. Set this to N to use the same count +# for all three generators, or to E:R:A to set each +# count separately. # This file sets the following shell variables for use by the # autoconf-generated configure script: @@ -240,6 +246,7 @@ gdb_needs_out_file_path= thread_file= default_use_cxa_atexit=no default_gnu_indirect_function=no +default_md_generator_partitions=10 target_gtfiles= need_64bit_isa= native_system_header_dir=/usr/include @@ -335,6 +342,7 @@ cpu_is_64bit= case ${target} in aarch64*-*-*) cpu_type=aarch64 + default_md_generator_partitions=16:16:8 extra_headers="${extra_headers} arm_fp16.h" extra_headers="${extra_headers} arm_neon.h" extra_headers="${extra_headers} arm_bf16.h" diff --git a/gcc/configure b/gcc/configure index c9f1feee86b..ad516b4cdd4 100755 --- a/gcc/configure +++ b/gcc/configure @@ -859,6 +859,8 @@ enable_gcov enable_shared enable_fixed_point enable_decimal_float +DEFAULT_INSNATTRTAB_PARTITIONS +DEFAULT_INSNRECOG_PARTITIONS DEFAULT_INSNEMIT_PARTITIONS DEFAULT_MATCHPD_PARTITIONS with_multi_buildlist @@ -987,6 +989,7 @@ enable_multilib enable_multiarch with_stack_clash_protection_guard_size with_matchpd_partitions +with_md_generator_partitions with_insnemit_partitions enable___cxa_atexit enable_decimal_float @@ -1881,9 +1884,12 @@ Optional Packages: --with-matchpd-partitions=num Set the number of partitions to make for gimple and generic when splitting match.pd. [default=10] - --with-insnemit-partitions=num - Set the number of partitions used by genemit, - genrecog and genattrtab. [default=10] + --with-md-generator-partitions=num|emit:recog:attrtab + Set the partition counts used by genemit, genrecog + and genattrtab. A single number sets all three + counts. [default=target dependent] + --with-insnemit-partitions=num|emit:recog:attrtab + Deprecated alias for --with-md-generator-partitions. --with-dwarf2 force the default debug format to be DWARF 2 (or later) --with-specs=SPECS add SPECS to driver command-line processing @@ -7908,21 +7914,33 @@ fi # Specify the number of output partitions used by the machine-description -# generators. +# generators. Select and validate the effective value after config.gcc has +# supplied the target default. +md_generator_partitions_set=no +md_generator_partitions_legacy=no + +# Check whether --with-md-generator-partitions was given. +if test "${with_md_generator_partitions+set}" = set; then : + withval=$with_md_generator_partitions; md_generator_partitions=$with_md_generator_partitions +md_generator_partitions_set=yes +fi + # Check whether --with-insnemit-partitions was given. if test "${with_insnemit_partitions+set}" = set; then : - withval=$with_insnemit_partitions; DEFAULT_INSNEMIT_PARTITIONS="$with_insnemit_partitions" -else - DEFAULT_INSNEMIT_PARTITIONS=10 + withval=$with_insnemit_partitions; if test "$md_generator_partitions_set" = yes; then + as_fn_error $? "--with-md-generator-partitions and --with-insnemit-partitions cannot be used together." "$LINENO" 5 fi - -if (test $DEFAULT_INSNEMIT_PARTITIONS -lt 1); then - as_fn_error $? "Invalid value $DEFAULT_INSNEMIT_PARTITIONS for --with-insnemit-partitions. Cannot be negative." "$LINENO" 5 +md_generator_partitions=$with_insnemit_partitions +md_generator_partitions_set=yes +md_generator_partitions_legacy=yes fi + + + # Enable __cxa_atexit for C++. # Check whether --enable-__cxa_atexit was given. if test "${enable___cxa_atexit+set}" = set; then : @@ -12995,6 +13013,56 @@ target_gtfiles= # Collect target-machine-specific information. . ${srcdir}/config.gcc || exit 1 +# Use the target default unless the user specified an option. +if test "$md_generator_partitions_set" = no; then + md_generator_partitions=$default_md_generator_partitions +fi + +case "$md_generator_partitions" in + '' | *[!0-9:]* | :* | *: | *:*:*:*) + DEFAULT_INSNATTRTAB_PARTITIONS= + ;; + *:*:*) + IFS=: read -r DEFAULT_INSNEMIT_PARTITIONS DEFAULT_INSNRECOG_PARTITIONS \ + DEFAULT_INSNATTRTAB_PARTITIONS <&5 +$as_echo "$as_me: WARNING: --with-insnemit-partitions is deprecated. Use --with-md-generator-partitions instead." >&2;} +fi + extra_objs="${host_extra_objs} ${extra_objs}" extra_gcc_objs="${host_extra_gcc_objs} ${extra_gcc_objs}" @@ -21922,7 +21990,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21925 "configure" +#line 21993 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -22028,7 +22096,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 22031 "configure" +#line 22099 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index a8b0a08f20d..50046571d22 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -903,19 +903,31 @@ fi AC_SUBST(DEFAULT_MATCHPD_PARTITIONS) # Specify the number of output partitions used by the machine-description -# generators. +# generators. Select and validate the effective value after config.gcc has +# supplied the target default. +md_generator_partitions_set=no +md_generator_partitions_legacy=no +AC_ARG_WITH(md-generator-partitions, +[AS_HELP_STRING([--with-md-generator-partitions=num|emit:recog:attrtab], +[Set the partition counts used by genemit, genrecog and genattrtab. +A single number sets all three counts. [default=target dependent]])], +[md_generator_partitions=$with_md_generator_partitions +md_generator_partitions_set=yes]) AC_ARG_WITH(insnemit-partitions, -[AS_HELP_STRING([--with-insnemit-partitions=num], -[Set the number of partitions used by genemit, genrecog and genattrtab. -[default=10]])], -[DEFAULT_INSNEMIT_PARTITIONS="$with_insnemit_partitions"], [DEFAULT_INSNEMIT_PARTITIONS=10]) -if (test $DEFAULT_INSNEMIT_PARTITIONS -lt 1); then +[AS_HELP_STRING([--with-insnemit-partitions=num|emit:recog:attrtab], +[Deprecated alias for --with-md-generator-partitions.])], +[if test "$md_generator_partitions_set" = yes; then AC_MSG_ERROR(m4_normalize([ - Invalid value $DEFAULT_INSNEMIT_PARTITIONS for --with-insnemit-partitions. \ - Cannot be negative.])) + --with-md-generator-partitions and --with-insnemit-partitions \ + cannot be used together.])) fi +md_generator_partitions=$with_insnemit_partitions +md_generator_partitions_set=yes +md_generator_partitions_legacy=yes]) AC_SUBST(DEFAULT_INSNEMIT_PARTITIONS) +AC_SUBST(DEFAULT_INSNRECOG_PARTITIONS) +AC_SUBST(DEFAULT_INSNATTRTAB_PARTITIONS) # Enable __cxa_atexit for C++. AC_ARG_ENABLE(__cxa_atexit, @@ -1928,6 +1940,60 @@ target_gtfiles= # Collect target-machine-specific information. . ${srcdir}/config.gcc || exit 1 +# Use the target default unless the user specified an option. +if test "$md_generator_partitions_set" = no; then + md_generator_partitions=$default_md_generator_partitions +fi + +case "$md_generator_partitions" in + '' | *[[!0-9:]]* | :* | *: | *:*:*:*) + DEFAULT_INSNATTRTAB_PARTITIONS= + ;; + *:*:*) + IFS=: read -r DEFAULT_INSNEMIT_PARTITIONS DEFAULT_INSNRECOG_PARTITIONS \ + DEFAULT_INSNATTRTAB_PARTITIONS <