3 Copyright (C) 2002, 2004-2005, 2009-2012 Free Software Foundation,
6 This file is part of Bison, the GNU Compiler Compiler.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 relation_print (relation r, relation_node size, FILE *out)
35 for (i = 0; i < size; ++i)
37 fprintf (out, "%3lu: ", (unsigned long int) i);
39 for (j = 0; r[i][j] != END_NODE; ++j)
40 fprintf (out, "%3lu ", (unsigned long int) r[i][j]);
47 /*---------------------------------------------------------------.
48 | digraph & traverse. |
50 | The following variables are used as common storage between the |
52 `---------------------------------------------------------------*/
55 static relation_nodes INDEX;
56 static relation_nodes VERTICES;
57 static relation_node top;
58 static relation_node infinity;
62 traverse (relation_node i)
68 INDEX[i] = height = top;
71 for (j = 0; R[i][j] != END_NODE; ++j)
73 if (INDEX[R[i][j]] == 0)
76 if (INDEX[i] > INDEX[R[i][j]])
77 INDEX[i] = INDEX[R[i][j]];
79 bitset_or (F[i], F[i], F[R[i][j]]);
82 if (INDEX[i] == height)
91 bitset_copy (F[j], F[i]);
97 relation_digraph (relation r, relation_node size, bitsetv *function)
102 INDEX = xcalloc (size + 1, sizeof *INDEX);
103 VERTICES = xnmalloc (size + 1, sizeof *VERTICES);
109 for (i = 0; i < size; i++)
110 if (INDEX[i] == 0 && R[i])
120 /*-------------------------------------------.
121 | Destructively transpose R_ARG, of size N. |
122 `-------------------------------------------*/
125 relation_transpose (relation *R_arg, relation_node n)
129 relation new_R = xnmalloc (n, sizeof *new_R);
130 /* END_R[I] -- next entry of NEW_R[I]. */
131 relation end_R = xnmalloc (n, sizeof *end_R);
132 /* NEDGES[I] -- total size of NEW_R[I]. */
133 size_t *nedges = xcalloc (n, sizeof *nedges);
137 if (trace_flag & trace_sets)
139 fputs ("relation_transpose: input\n", stderr);
140 relation_print (r, n, stderr);
144 for (i = 0; i < n; i++)
146 for (j = 0; r[i][j] != END_NODE; ++j)
150 for (i = 0; i < n; i++)
152 relation_node *sp = NULL;
155 sp = xnmalloc (nedges[i] + 1, sizeof *sp);
156 sp[nedges[i]] = END_NODE;
163 for (i = 0; i < n; i++)
165 for (j = 0; r[i][j] != END_NODE; ++j)
166 *end_R[r[i][j]]++ = i;
171 /* Free the input: it is replaced with the result. */
172 for (i = 0; i < n; i++)
176 if (trace_flag & trace_sets)
178 fputs ("relation_transpose: output\n", stderr);
179 relation_print (new_R, n, stderr);