From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 948313851A8E for ; Thu, 25 Aug 2022 13:05:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 948313851A8E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CDB7DD6E for ; Thu, 25 Aug 2022 06:05:57 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DE6203F71A for ; Thu, 25 Aug 2022 06:05:52 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 3/6] Make graphds_scc pass the node order back to callers References: Date: Thu, 25 Aug 2022 14:05:51 +0100 In-Reply-To: (Richard Sandiford's message of "Thu, 25 Aug 2022 14:04:47 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-50.6 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: As a side-effect, graphds_scc constructs a vector in which all nodes in an SCC are listed consecutively. This can be useful information, so that the patch adds an optional pass-back parameter for it. The interface is similar to the one for graphds_dfs. gcc/ * graphds.cc (graphds_scc): Add a pass-back parameter for the final node order. --- gcc/graphds.cc | 13 ++++++++++--- gcc/graphds.h | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gcc/graphds.cc b/gcc/graphds.cc index 91a2ca5c225..2a108fd475f 100644 --- a/gcc/graphds.cc +++ b/gcc/graphds.cc @@ -281,7 +281,14 @@ graphds_dfs (struct graph *g, int *qs, int nq, vec *qt, numbers assigned by the previous pass. If SUBGRAPH is not NULL, it specifies the subgraph of G whose strongly connected components we want to determine. If SKIP_EDGE_P is not NULL, it points to a callback function. - Edge E will be skipped if callback function returns true. + Edge E will be skipped if callback function returns true. If SCC_GROUPING + is not null, the nodes will be added to it in the following order: + + - If SCC A is a direct or indirect predecessor of SCC B in the SCC dag, + A's nodes come before B's nodes. + + - All of an SCC's nodes are listed consecutively, although the order + of the nodes within an SCC is not really meaningful. After running this function, v->component is the number of the strongly connected component for each vertex of G. Returns the number of the @@ -289,7 +296,7 @@ graphds_dfs (struct graph *g, int *qs, int nq, vec *qt, int graphds_scc (struct graph *g, bitmap subgraph, - skip_edge_callback skip_edge_p) + skip_edge_callback skip_edge_p, vec *scc_grouping) { int *queue = XNEWVEC (int, g->n_vertices); vec postorder = vNULL; @@ -317,7 +324,7 @@ graphds_scc (struct graph *g, bitmap subgraph, for (i = 0; i < nq; i++) queue[i] = postorder[nq - i - 1]; - comp = graphds_dfs (g, queue, nq, NULL, true, subgraph, skip_edge_p); + comp = graphds_dfs (g, queue, nq, scc_grouping, true, subgraph, skip_edge_p); free (queue); postorder.release (); diff --git a/gcc/graphds.h b/gcc/graphds.h index c54d8767fa7..e0e4d802cbb 100644 --- a/gcc/graphds.h +++ b/gcc/graphds.h @@ -58,7 +58,8 @@ void identify_vertices (struct graph *, int, int); typedef bool (*skip_edge_callback) (struct graph_edge *); int graphds_dfs (struct graph *, int *, int, vec *, bool, bitmap, skip_edge_callback = NULL); -int graphds_scc (struct graph *, bitmap, skip_edge_callback = NULL); +int graphds_scc (struct graph *, bitmap, skip_edge_callback = NULL, + vec * = NULL); void graphds_domtree (struct graph *, int, int *, int *, int *); typedef void (*graphds_edge_callback) (struct graph *, struct graph_edge *, void *); -- 2.25.1