summaryrefslogtreecommitdiff
path: root/gcc/cfg.c
diff options
context:
space:
mode:
authorkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-02 19:09:03 +0000
committerkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-02 19:09:03 +0000
commit4dafd3e415dd406091b1f7aca0ccc91c61d8cfa7 (patch)
treeb1167a1b882befa5f056b6a12ff5fd8f25e4aebc /gcc/cfg.c
parentefffc4a45a097227984137001618d3c1729e7ffd (diff)
downloadgcc-4dafd3e415dd406091b1f7aca0ccc91c61d8cfa7.tar.gz
* cfg.c (connect_src, connect_dest, disconnect_src,
disconnct_dest): New. (unchecked_make_edge, remove_edge, redirect_edge_succ, redirect_edge_pred): Use the new functions. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95790 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cfg.c')
-rw-r--r--gcc/cfg.c133
1 files changed, 69 insertions, 64 deletions
diff --git a/gcc/cfg.c b/gcc/cfg.c
index 6737003e60c..d180f3e8907 100644
--- a/gcc/cfg.c
+++ b/gcc/cfg.c
@@ -243,6 +243,63 @@ expunge_block (basic_block b)
clear out BB pointer of dead statements consistently. */
}
+/* Connect E to E->src. */
+
+static inline void
+connect_src (edge e)
+{
+ VEC_safe_push (edge, e->src->succs, e);
+}
+
+/* Connect E to E->dest. */
+
+static inline void
+connect_dest (edge e)
+{
+ basic_block dest = e->dest;
+ VEC_safe_push (edge, dest->preds, e);
+ e->dest_idx = EDGE_COUNT (dest->preds) - 1;
+}
+
+/* Disconnect edge E from E->src. */
+
+static inline void
+disconnect_src (edge e)
+{
+ basic_block src = e->src;
+ edge_iterator ei;
+ edge tmp;
+
+ for (ei = ei_start (src->succs); (tmp = ei_safe_edge (ei)); )
+ {
+ if (tmp == e)
+ {
+ VEC_unordered_remove (edge, src->succs, ei.index);
+ return;
+ }
+ else
+ ei_next (&ei);
+ }
+
+ gcc_unreachable ();
+}
+
+/* Disconnect edge E from E->dest. */
+
+static inline void
+disconnect_dest (edge e)
+{
+ basic_block dest = e->dest;
+ unsigned int dest_idx = e->dest_idx;
+
+ VEC_unordered_remove (edge, dest->preds, dest_idx);
+
+ /* If we removed an edge in the middle of the edge vector, we need
+ to update dest_idx of the edge that moved into the "hole". */
+ if (dest_idx < EDGE_COUNT (dest->preds))
+ EDGE_PRED (dest, dest_idx)->dest_idx = dest_idx;
+}
+
/* Create an edge connecting SRC and DEST with flags FLAGS. Return newly
created edge. Use this only if you are sure that this edge can't
possibly already exist. */
@@ -254,13 +311,12 @@ unchecked_make_edge (basic_block src, basic_block dst, int flags)
e = ggc_alloc_cleared (sizeof (*e));
n_edges++;
- VEC_safe_push (edge, src->succs, e);
- VEC_safe_push (edge, dst->preds, e);
-
e->src = src;
e->dest = dst;
e->flags = flags;
- e->dest_idx = EDGE_COUNT (dst->preds) - 1;
+
+ connect_src (e);
+ connect_dest (e);
execute_on_growing_pred (e);
@@ -334,38 +390,10 @@ make_single_succ_edge (basic_block src, basic_block dest, int flags)
void
remove_edge (edge e)
{
- edge tmp;
- basic_block src, dest;
- unsigned int dest_idx;
- bool found = false;
- edge_iterator ei;
-
execute_on_shrinking_pred (e);
- src = e->src;
- dest = e->dest;
- dest_idx = e->dest_idx;
-
- for (ei = ei_start (src->succs); (tmp = ei_safe_edge (ei)); )
- {
- if (tmp == e)
- {
- VEC_unordered_remove (edge, src->succs, ei.index);
- found = true;
- break;
- }
- else
- ei_next (&ei);
- }
-
- gcc_assert (found);
-
- VEC_unordered_remove (edge, dest->preds, dest_idx);
-
- /* If we removed an edge in the middle of the edge vector, we need
- to update dest_idx of the edge that moved into the "hole". */
- if (dest_idx < EDGE_COUNT (dest->preds))
- EDGE_PRED (dest, dest_idx)->dest_idx = dest_idx;
+ disconnect_src (e);
+ disconnect_dest (e);
free_edge (e);
}
@@ -375,22 +403,15 @@ remove_edge (edge e)
void
redirect_edge_succ (edge e, basic_block new_succ)
{
- basic_block dest = e->dest;
- unsigned int dest_idx = e->dest_idx;
-
execute_on_shrinking_pred (e);
- VEC_unordered_remove (edge, dest->preds, dest_idx);
+ disconnect_dest (e);
- /* If we removed an edge in the middle of the edge vector, we need
- to update dest_idx of the edge that moved into the "hole". */
- if (dest_idx < EDGE_COUNT (dest->preds))
- EDGE_PRED (dest, dest_idx)->dest_idx = dest_idx;
+ e->dest = new_succ;
/* Reconnect the edge to the new successor block. */
- VEC_safe_push (edge, new_succ->preds, e);
- e->dest = new_succ;
- e->dest_idx = EDGE_COUNT (new_succ->preds) - 1;
+ connect_dest (e);
+
execute_on_growing_pred (e);
}
@@ -423,28 +444,12 @@ redirect_edge_succ_nodup (edge e, basic_block new_succ)
void
redirect_edge_pred (edge e, basic_block new_pred)
{
- edge tmp;
- edge_iterator ei;
- bool found = false;
+ disconnect_src (e);
- /* Disconnect the edge from the old predecessor block. */
- for (ei = ei_start (e->src->succs); (tmp = ei_safe_edge (ei)); )
- {
- if (tmp == e)
- {
- VEC_unordered_remove (edge, e->src->succs, ei.index);
- found = true;
- break;
- }
- else
- ei_next (&ei);
- }
-
- gcc_assert (found);
+ e->src = new_pred;
/* Reconnect the edge to the new predecessor block. */
- VEC_safe_push (edge, new_pred->succs, e);
- e->src = new_pred;
+ connect_src (e);
}
/* Clear all basic block flags, with the exception of partitioning. */