Add a directory forgotten in merge.
[official-gcc.git] / gcc / dominance.c
blob957911f67b24328d172b106753868e846c30e5ab
1 /* Calculate (post)dominators in slightly super-linear time.
2 Copyright (C) 2000, 2003 Free Software Foundation, Inc.
3 Contributed by Michael Matz (matz@ifh.de).
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 /* This file implements the well known algorithm from Lengauer and Tarjan
23 to compute the dominators in a control flow graph. A basic block D is said
24 to dominate another block X, when all paths from the entry node of the CFG
25 to X go also over D. The dominance relation is a transitive reflexive
26 relation and its minimal transitive reduction is a tree, called the
27 dominator tree. So for each block X besides the entry block exists a
28 block I(X), called the immediate dominator of X, which is the parent of X
29 in the dominator tree.
31 The algorithm computes this dominator tree implicitly by computing for
32 each block its immediate dominator. We use tree balancing and path
33 compression, so its the O(e*a(e,v)) variant, where a(e,v) is the very
34 slowly growing functional inverse of the Ackerman function. */
36 #include "config.h"
37 #include "system.h"
38 #include "coretypes.h"
39 #include "tm.h"
40 #include "rtl.h"
41 #include "hard-reg-set.h"
42 #include "basic-block.h"
43 #include "errors.h"
44 #include "et-forest.h"
46 struct dominance_info
48 et_forest_t forest;
49 varray_type varray;
50 basic_block *idom;
53 #define BB_NODE(info, bb) \
54 ((et_forest_node_t)VARRAY_GENERIC_PTR ((info)->varray, (bb)->index + 2))
55 #define SET_BB_NODE(info, bb, node) \
56 (VARRAY_GENERIC_PTR ((info)->varray, (bb)->index + 2) = (node))
58 /* We name our nodes with integers, beginning with 1. Zero is reserved for
59 'undefined' or 'end of list'. The name of each node is given by the dfs
60 number of the corresponding basic block. Please note, that we include the
61 artificial ENTRY_BLOCK (or EXIT_BLOCK in the post-dom case) in our lists to
62 support multiple entry points. As it has no real basic block index we use
63 'last_basic_block' for that. Its dfs number is of course 1. */
65 /* Type of Basic Block aka. TBB */
66 typedef unsigned int TBB;
68 /* We work in a poor-mans object oriented fashion, and carry an instance of
69 this structure through all our 'methods'. It holds various arrays
70 reflecting the (sub)structure of the flowgraph. Most of them are of type
71 TBB and are also indexed by TBB. */
73 struct dom_info
75 /* The parent of a node in the DFS tree. */
76 TBB *dfs_parent;
77 /* For a node x key[x] is roughly the node nearest to the root from which
78 exists a way to x only over nodes behind x. Such a node is also called
79 semidominator. */
80 TBB *key;
81 /* The value in path_min[x] is the node y on the path from x to the root of
82 the tree x is in with the smallest key[y]. */
83 TBB *path_min;
84 /* bucket[x] points to the first node of the set of nodes having x as key. */
85 TBB *bucket;
86 /* And next_bucket[x] points to the next node. */
87 TBB *next_bucket;
88 /* After the algorithm is done, dom[x] contains the immediate dominator
89 of x. */
90 TBB *dom;
92 /* The following few fields implement the structures needed for disjoint
93 sets. */
94 /* set_chain[x] is the next node on the path from x to the representant
95 of the set containing x. If set_chain[x]==0 then x is a root. */
96 TBB *set_chain;
97 /* set_size[x] is the number of elements in the set named by x. */
98 unsigned int *set_size;
99 /* set_child[x] is used for balancing the tree representing a set. It can
100 be understood as the next sibling of x. */
101 TBB *set_child;
103 /* If b is the number of a basic block (BB->index), dfs_order[b] is the
104 number of that node in DFS order counted from 1. This is an index
105 into most of the other arrays in this structure. */
106 TBB *dfs_order;
107 /* If x is the DFS-index of a node which corresponds with a basic block,
108 dfs_to_bb[x] is that basic block. Note, that in our structure there are
109 more nodes that basic blocks, so only dfs_to_bb[dfs_order[bb->index]]==bb
110 is true for every basic block bb, but not the opposite. */
111 basic_block *dfs_to_bb;
113 /* This is the next free DFS number when creating the DFS tree or forest. */
114 unsigned int dfsnum;
115 /* The number of nodes in the DFS tree (==dfsnum-1). */
116 unsigned int nodes;
119 static void init_dom_info (struct dom_info *);
120 static void free_dom_info (struct dom_info *);
121 static void calc_dfs_tree_nonrec (struct dom_info *, basic_block,
122 enum cdi_direction);
123 static void calc_dfs_tree (struct dom_info *, enum cdi_direction);
124 static void compress (struct dom_info *, TBB);
125 static TBB eval (struct dom_info *, TBB);
126 static void link_roots (struct dom_info *, TBB, TBB);
127 static void calc_idoms (struct dom_info *, enum cdi_direction);
128 void debug_dominance_info (dominance_info);
130 /* Helper macro for allocating and initializing an array,
131 for aesthetic reasons. */
132 #define init_ar(var, type, num, content) \
133 do \
135 unsigned int i = 1; /* Catch content == i. */ \
136 if (! (content)) \
137 (var) = xcalloc ((num), sizeof (type)); \
138 else \
140 (var) = xmalloc ((num) * sizeof (type)); \
141 for (i = 0; i < num; i++) \
142 (var)[i] = (content); \
145 while (0)
147 /* Allocate all needed memory in a pessimistic fashion (so we round up).
148 This initializes the contents of DI, which already must be allocated. */
150 static void
151 init_dom_info (struct dom_info *di)
153 /* We need memory for n_basic_blocks nodes and the ENTRY_BLOCK or
154 EXIT_BLOCK. */
155 unsigned int num = n_basic_blocks + 1 + 1;
156 init_ar (di->dfs_parent, TBB, num, 0);
157 init_ar (di->path_min, TBB, num, i);
158 init_ar (di->key, TBB, num, i);
159 init_ar (di->dom, TBB, num, 0);
161 init_ar (di->bucket, TBB, num, 0);
162 init_ar (di->next_bucket, TBB, num, 0);
164 init_ar (di->set_chain, TBB, num, 0);
165 init_ar (di->set_size, unsigned int, num, 1);
166 init_ar (di->set_child, TBB, num, 0);
168 init_ar (di->dfs_order, TBB, (unsigned int) last_basic_block + 1, 0);
169 init_ar (di->dfs_to_bb, basic_block, num, 0);
171 di->dfsnum = 1;
172 di->nodes = 0;
175 #undef init_ar
177 /* Free all allocated memory in DI, but not DI itself. */
179 static void
180 free_dom_info (struct dom_info *di)
182 free (di->dfs_parent);
183 free (di->path_min);
184 free (di->key);
185 free (di->dom);
186 free (di->bucket);
187 free (di->next_bucket);
188 free (di->set_chain);
189 free (di->set_size);
190 free (di->set_child);
191 free (di->dfs_order);
192 free (di->dfs_to_bb);
195 /* The nonrecursive variant of creating a DFS tree. DI is our working
196 structure, BB the starting basic block for this tree and REVERSE
197 is true, if predecessors should be visited instead of successors of a
198 node. After this is done all nodes reachable from BB were visited, have
199 assigned their dfs number and are linked together to form a tree. */
201 static void
202 calc_dfs_tree_nonrec (struct dom_info *di, basic_block bb, enum cdi_direction reverse)
204 /* We never call this with bb==EXIT_BLOCK_PTR (ENTRY_BLOCK_PTR if REVERSE). */
205 /* We call this _only_ if bb is not already visited. */
206 edge e;
207 TBB child_i, my_i = 0;
208 edge *stack;
209 int sp;
210 /* Start block (ENTRY_BLOCK_PTR for forward problem, EXIT_BLOCK for backward
211 problem). */
212 basic_block en_block;
213 /* Ending block. */
214 basic_block ex_block;
216 stack = xmalloc ((n_basic_blocks + 3) * sizeof (edge));
217 sp = 0;
219 /* Initialize our border blocks, and the first edge. */
220 if (reverse)
222 e = bb->pred;
223 en_block = EXIT_BLOCK_PTR;
224 ex_block = ENTRY_BLOCK_PTR;
226 else
228 e = bb->succ;
229 en_block = ENTRY_BLOCK_PTR;
230 ex_block = EXIT_BLOCK_PTR;
233 /* When the stack is empty we break out of this loop. */
234 while (1)
236 basic_block bn;
238 /* This loop traverses edges e in depth first manner, and fills the
239 stack. */
240 while (e)
242 edge e_next;
244 /* Deduce from E the current and the next block (BB and BN), and the
245 next edge. */
246 if (reverse)
248 bn = e->src;
250 /* If the next node BN is either already visited or a border
251 block the current edge is useless, and simply overwritten
252 with the next edge out of the current node. */
253 if (bn == ex_block || di->dfs_order[bn->index])
255 e = e->pred_next;
256 continue;
258 bb = e->dest;
259 e_next = bn->pred;
261 else
263 bn = e->dest;
264 if (bn == ex_block || di->dfs_order[bn->index])
266 e = e->succ_next;
267 continue;
269 bb = e->src;
270 e_next = bn->succ;
273 if (bn == en_block)
274 abort ();
276 /* Fill the DFS tree info calculatable _before_ recursing. */
277 if (bb != en_block)
278 my_i = di->dfs_order[bb->index];
279 else
280 my_i = di->dfs_order[last_basic_block];
281 child_i = di->dfs_order[bn->index] = di->dfsnum++;
282 di->dfs_to_bb[child_i] = bn;
283 di->dfs_parent[child_i] = my_i;
285 /* Save the current point in the CFG on the stack, and recurse. */
286 stack[sp++] = e;
287 e = e_next;
290 if (!sp)
291 break;
292 e = stack[--sp];
294 /* OK. The edge-list was exhausted, meaning normally we would
295 end the recursion. After returning from the recursive call,
296 there were (may be) other statements which were run after a
297 child node was completely considered by DFS. Here is the
298 point to do it in the non-recursive variant.
299 E.g. The block just completed is in e->dest for forward DFS,
300 the block not yet completed (the parent of the one above)
301 in e->src. This could be used e.g. for computing the number of
302 descendants or the tree depth. */
303 if (reverse)
304 e = e->pred_next;
305 else
306 e = e->succ_next;
308 free (stack);
311 /* The main entry for calculating the DFS tree or forest. DI is our working
312 structure and REVERSE is true, if we are interested in the reverse flow
313 graph. In that case the result is not necessarily a tree but a forest,
314 because there may be nodes from which the EXIT_BLOCK is unreachable. */
316 static void
317 calc_dfs_tree (struct dom_info *di, enum cdi_direction reverse)
319 /* The first block is the ENTRY_BLOCK (or EXIT_BLOCK if REVERSE). */
320 basic_block begin = reverse ? EXIT_BLOCK_PTR : ENTRY_BLOCK_PTR;
321 di->dfs_order[last_basic_block] = di->dfsnum;
322 di->dfs_to_bb[di->dfsnum] = begin;
323 di->dfsnum++;
325 calc_dfs_tree_nonrec (di, begin, reverse);
327 if (reverse)
329 /* In the post-dom case we may have nodes without a path to EXIT_BLOCK.
330 They are reverse-unreachable. In the dom-case we disallow such
331 nodes, but in post-dom we have to deal with them, so we simply
332 include them in the DFS tree which actually becomes a forest. */
333 basic_block b;
334 FOR_EACH_BB_REVERSE (b)
336 if (di->dfs_order[b->index])
337 continue;
338 di->dfs_order[b->index] = di->dfsnum;
339 di->dfs_to_bb[di->dfsnum] = b;
340 di->dfsnum++;
341 calc_dfs_tree_nonrec (di, b, reverse);
345 di->nodes = di->dfsnum - 1;
347 /* This aborts e.g. when there is _no_ path from ENTRY to EXIT at all. */
348 if (di->nodes != (unsigned int) n_basic_blocks + 1)
349 abort ();
352 /* Compress the path from V to the root of its set and update path_min at the
353 same time. After compress(di, V) set_chain[V] is the root of the set V is
354 in and path_min[V] is the node with the smallest key[] value on the path
355 from V to that root. */
357 static void
358 compress (struct dom_info *di, TBB v)
360 /* Btw. It's not worth to unrecurse compress() as the depth is usually not
361 greater than 5 even for huge graphs (I've not seen call depth > 4).
362 Also performance wise compress() ranges _far_ behind eval(). */
363 TBB parent = di->set_chain[v];
364 if (di->set_chain[parent])
366 compress (di, parent);
367 if (di->key[di->path_min[parent]] < di->key[di->path_min[v]])
368 di->path_min[v] = di->path_min[parent];
369 di->set_chain[v] = di->set_chain[parent];
373 /* Compress the path from V to the set root of V if needed (when the root has
374 changed since the last call). Returns the node with the smallest key[]
375 value on the path from V to the root. */
377 static inline TBB
378 eval (struct dom_info *di, TBB v)
380 /* The representant of the set V is in, also called root (as the set
381 representation is a tree). */
382 TBB rep = di->set_chain[v];
384 /* V itself is the root. */
385 if (!rep)
386 return di->path_min[v];
388 /* Compress only if necessary. */
389 if (di->set_chain[rep])
391 compress (di, v);
392 rep = di->set_chain[v];
395 if (di->key[di->path_min[rep]] >= di->key[di->path_min[v]])
396 return di->path_min[v];
397 else
398 return di->path_min[rep];
401 /* This essentially merges the two sets of V and W, giving a single set with
402 the new root V. The internal representation of these disjoint sets is a
403 balanced tree. Currently link(V,W) is only used with V being the parent
404 of W. */
406 static void
407 link_roots (struct dom_info *di, TBB v, TBB w)
409 TBB s = w;
411 /* Rebalance the tree. */
412 while (di->key[di->path_min[w]] < di->key[di->path_min[di->set_child[s]]])
414 if (di->set_size[s] + di->set_size[di->set_child[di->set_child[s]]]
415 >= 2 * di->set_size[di->set_child[s]])
417 di->set_chain[di->set_child[s]] = s;
418 di->set_child[s] = di->set_child[di->set_child[s]];
420 else
422 di->set_size[di->set_child[s]] = di->set_size[s];
423 s = di->set_chain[s] = di->set_child[s];
427 di->path_min[s] = di->path_min[w];
428 di->set_size[v] += di->set_size[w];
429 if (di->set_size[v] < 2 * di->set_size[w])
431 TBB tmp = s;
432 s = di->set_child[v];
433 di->set_child[v] = tmp;
436 /* Merge all subtrees. */
437 while (s)
439 di->set_chain[s] = v;
440 s = di->set_child[s];
444 /* This calculates the immediate dominators (or post-dominators if REVERSE is
445 true). DI is our working structure and should hold the DFS forest.
446 On return the immediate dominator to node V is in di->dom[V]. */
448 static void
449 calc_idoms (struct dom_info *di, enum cdi_direction reverse)
451 TBB v, w, k, par;
452 basic_block en_block;
453 if (reverse)
454 en_block = EXIT_BLOCK_PTR;
455 else
456 en_block = ENTRY_BLOCK_PTR;
458 /* Go backwards in DFS order, to first look at the leafs. */
459 v = di->nodes;
460 while (v > 1)
462 basic_block bb = di->dfs_to_bb[v];
463 edge e, e_next;
465 par = di->dfs_parent[v];
466 k = v;
467 if (reverse)
468 e = bb->succ;
469 else
470 e = bb->pred;
472 /* Search all direct predecessors for the smallest node with a path
473 to them. That way we have the smallest node with also a path to
474 us only over nodes behind us. In effect we search for our
475 semidominator. */
476 for (; e; e = e_next)
478 TBB k1;
479 basic_block b;
481 if (reverse)
483 b = e->dest;
484 e_next = e->succ_next;
486 else
488 b = e->src;
489 e_next = e->pred_next;
491 if (b == en_block)
492 k1 = di->dfs_order[last_basic_block];
493 else
494 k1 = di->dfs_order[b->index];
496 /* Call eval() only if really needed. If k1 is above V in DFS tree,
497 then we know, that eval(k1) == k1 and key[k1] == k1. */
498 if (k1 > v)
499 k1 = di->key[eval (di, k1)];
500 if (k1 < k)
501 k = k1;
504 di->key[v] = k;
505 link_roots (di, par, v);
506 di->next_bucket[v] = di->bucket[k];
507 di->bucket[k] = v;
509 /* Transform semidominators into dominators. */
510 for (w = di->bucket[par]; w; w = di->next_bucket[w])
512 k = eval (di, w);
513 if (di->key[k] < di->key[w])
514 di->dom[w] = k;
515 else
516 di->dom[w] = par;
518 /* We don't need to cleanup next_bucket[]. */
519 di->bucket[par] = 0;
520 v--;
523 /* Explicitly define the dominators. */
524 di->dom[1] = 0;
525 for (v = 2; v <= di->nodes; v++)
526 if (di->dom[v] != di->key[v])
527 di->dom[v] = di->dom[di->dom[v]];
530 /* The main entry point into this module. IDOM is an integer array with room
531 for last_basic_block integers, DOMS is a preallocated sbitmap array having
532 room for last_basic_block^2 bits, and POST is true if the caller wants to
533 know post-dominators.
535 On return IDOM[i] will be the BB->index of the immediate (post) dominator
536 of basic block i, and DOMS[i] will have set bit j if basic block j is a
537 (post)dominator for block i.
539 Either IDOM or DOMS may be NULL (meaning the caller is not interested in
540 immediate resp. all dominators). */
542 dominance_info
543 calculate_dominance_info (enum cdi_direction reverse)
545 struct dom_info di;
546 dominance_info info;
547 basic_block b;
549 /* Allocate structure for dominance information. */
550 info = xmalloc (sizeof (struct dominance_info));
551 info->forest = et_forest_create ();
552 info->idom = xcalloc (last_basic_block, sizeof (basic_block));
554 VARRAY_GENERIC_PTR_INIT (info->varray, last_basic_block + 3, "dominance info");
556 /* Add the two well-known basic blocks. */
557 SET_BB_NODE (info, ENTRY_BLOCK_PTR, et_forest_add_node (info->forest,
558 ENTRY_BLOCK_PTR));
559 SET_BB_NODE (info, EXIT_BLOCK_PTR, et_forest_add_node (info->forest,
560 EXIT_BLOCK_PTR));
561 FOR_EACH_BB (b)
562 SET_BB_NODE (info, b, et_forest_add_node (info->forest, b));
564 init_dom_info (&di);
565 calc_dfs_tree (&di, reverse);
566 calc_idoms (&di, reverse);
569 FOR_EACH_BB (b)
571 TBB d = di.dom[di.dfs_order[b->index]];
573 if (di.dfs_to_bb[d])
574 et_forest_add_edge (info->forest, BB_NODE (info, di.dfs_to_bb[d]), BB_NODE (info, b));
577 free_dom_info (&di);
578 return info;
581 /* Free dominance information. */
582 void
583 free_dominance_info (dominance_info info)
585 basic_block bb;
587 /* Allow users to create new basic block without setting up the dominance
588 information for them. */
589 FOR_EACH_BB (bb)
590 if (bb->index < (int)(info->varray->num_elements - 2)
591 && BB_NODE (info, bb))
592 delete_from_dominance_info (info, bb);
593 delete_from_dominance_info (info, ENTRY_BLOCK_PTR);
594 delete_from_dominance_info (info, EXIT_BLOCK_PTR);
595 et_forest_delete (info->forest);
596 VARRAY_GROW (info->varray, 0);
597 free (info->idom);
598 free (info);
601 /* Return the immediate dominator of basic block BB. */
602 basic_block
603 get_immediate_dominator (dominance_info dom, basic_block bb)
605 basic_block answer;
606 if (bb->index >= 0 && dom->idom[bb->index] != NULL)
607 return dom->idom[bb->index];
608 answer = et_forest_node_value (dom->forest,
609 et_forest_parent (dom->forest,
610 BB_NODE (dom, bb)));
611 if (bb->index >= 0)
612 dom->idom[bb->index] = answer;
613 return answer;
617 /* Set the immediate dominator of the block possibly removing
618 existing edge. NULL can be used to remove any edge. */
619 inline void
620 set_immediate_dominator (dominance_info dom, basic_block bb, basic_block dominated_by)
622 void *aux_bb_node;
623 et_forest_node_t bb_node = BB_NODE (dom, bb);
625 aux_bb_node = et_forest_parent (dom->forest, bb_node);
626 if (aux_bb_node)
627 et_forest_remove_edge (dom->forest, aux_bb_node, bb_node);
628 if (dominated_by != NULL)
630 if (bb == dominated_by)
631 abort ();
632 if (!et_forest_add_edge (dom->forest, BB_NODE (dom, dominated_by), bb_node))
633 abort ();
635 if (bb->index >= 0)
636 dom->idom[bb->index] = dominated_by;
639 /* Store all basic blocks dominated by BB into BBS and return their number. */
641 get_dominated_by (dominance_info dom, basic_block bb, basic_block **bbs)
643 int n, i;
645 *bbs = xmalloc (n_basic_blocks * sizeof (basic_block));
646 n = et_forest_enumerate_sons (dom->forest, BB_NODE (dom, bb), (et_forest_node_t *)*bbs);
647 for (i = 0; i < n; i++)
648 (*bbs)[i] = et_forest_node_value (dom->forest, (et_forest_node_t)(*bbs)[i]);
649 return n;
652 /* Redirect all edges pointing to BB to TO. */
653 void
654 redirect_immediate_dominators (dominance_info dom, basic_block bb, basic_block to)
656 et_forest_node_t *bbs = xmalloc (n_basic_blocks * sizeof (basic_block));
657 et_forest_node_t node = BB_NODE (dom, bb);
658 et_forest_node_t node2 = BB_NODE (dom, to);
659 int n = et_forest_enumerate_sons (dom->forest, node, bbs);
660 int i;
662 memset (dom->idom, 0, last_basic_block * sizeof (basic_block));
663 for (i = 0; i < n; i++)
665 et_forest_remove_edge (dom->forest, node, bbs[i]);
666 et_forest_add_edge (dom->forest, node2, bbs[i]);
668 free (bbs);
671 /* Find first basic block in the tree dominating both BB1 and BB2. */
672 basic_block
673 nearest_common_dominator (dominance_info dom, basic_block bb1, basic_block bb2)
675 if (!bb1)
676 return bb2;
677 if (!bb2)
678 return bb1;
679 return et_forest_node_value (dom->forest,
680 et_forest_common_ancestor (dom->forest,
681 BB_NODE (dom, bb1),
682 BB_NODE (dom,
683 bb2)));
686 /* Return TRUE in case BB1 is dominated by BB2. */
687 bool
688 dominated_by_p (dominance_info dom, basic_block bb1, basic_block bb2)
690 return nearest_common_dominator (dom, bb1, bb2) == bb2;
693 /* Verify invariants of dominator structure. */
694 void
695 verify_dominators (dominance_info dom)
697 int err = 0;
698 basic_block bb;
700 FOR_EACH_BB (bb)
702 basic_block dom_bb;
704 dom_bb = recount_dominator (dom, bb);
705 if (dom_bb != get_immediate_dominator (dom, bb))
707 error ("dominator of %d should be %d, not %d",
708 bb->index, dom_bb->index, get_immediate_dominator(dom, bb)->index);
709 err = 1;
712 if (err)
713 abort ();
716 /* Recount dominator of BB. */
717 basic_block
718 recount_dominator (dominance_info dom, basic_block bb)
720 basic_block dom_bb = NULL;
721 edge e;
723 for (e = bb->pred; e; e = e->pred_next)
725 if (!dominated_by_p (dom, e->src, bb))
726 dom_bb = nearest_common_dominator (dom, dom_bb, e->src);
729 return dom_bb;
732 /* Iteratively recount dominators of BBS. The change is supposed to be local
733 and not to grow further. */
734 void
735 iterate_fix_dominators (dominance_info dom, basic_block *bbs, int n)
737 int i, changed = 1;
738 basic_block old_dom, new_dom;
740 while (changed)
742 changed = 0;
743 for (i = 0; i < n; i++)
745 old_dom = get_immediate_dominator (dom, bbs[i]);
746 new_dom = recount_dominator (dom, bbs[i]);
747 if (old_dom != new_dom)
749 changed = 1;
750 set_immediate_dominator (dom, bbs[i], new_dom);
756 void
757 add_to_dominance_info (dominance_info dom, basic_block bb)
759 VARRAY_GROW (dom->varray, last_basic_block + 3);
760 dom->idom = xrealloc (dom->idom, last_basic_block * sizeof (basic_block));
761 #ifdef ENABLE_CHECKING
762 if (BB_NODE (dom, bb))
763 abort ();
764 #endif
765 SET_BB_NODE (dom, bb, et_forest_add_node (dom->forest, bb));
766 if (bb->index >= 0)
767 dom->idom[bb->index] = NULL;
770 void
771 delete_from_dominance_info (dominance_info dom, basic_block bb)
773 et_forest_remove_node (dom->forest, BB_NODE (dom, bb));
774 if (bb->index >= 0)
775 dom->idom[bb->index] = NULL;
776 SET_BB_NODE (dom, bb, NULL);
779 void
780 debug_dominance_info (dominance_info dom)
782 basic_block bb, bb2;
783 FOR_EACH_BB (bb)
784 if ((bb2 = get_immediate_dominator (dom, bb)))
785 fprintf (stderr, "%i %i\n", bb->index, bb2->index);