This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] tree-cfg.c: Use VEC instead of VARRAY.
- From: Kazu Hirata <kazu at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 29 Dec 2005 06:36:19 -0800
- Subject: [patch] tree-cfg.c: Use VEC instead of VARRAY.
Hi,
Attached is a patch to use VEC instead of VARRAY.
Tested on x86_64-pc-linux-gnu. Will commit in 48 hours or so as
preapproved.
Kazu Hirata
2005-12-29 Kazu Hirata <kazu@codesourcery.com>
* basic-block.h (control_flow_graph): Change the type of
x_label_to_block_map to VEC(basic_block,gc) *.
* tree-cfg.c (init_empty_tree_cfg, label_to_block_fn,
set_bb_for_stmt): Adjust the uses of x_label_to_block_map.
Index: basic-block.h
===================================================================
--- basic-block.h (revision 109060)
+++ basic-block.h (working copy)
@@ -376,7 +376,7 @@ struct control_flow_graph GTY(())
/* Mapping of labels to their associated blocks. At present
only used for the tree CFG. */
- varray_type x_label_to_block_map;
+ VEC(basic_block,gc) *x_label_to_block_map;
enum profile_status {
PROFILE_ABSENT,
Index: tree-cfg.c
===================================================================
--- tree-cfg.c (revision 109060)
+++ tree-cfg.c (working copy)
@@ -134,8 +134,10 @@ init_empty_tree_cfg (void)
VARRAY_BB_INIT (basic_block_info, initial_cfg_capacity, "basic_block_info");
/* Build a mapping of labels to their associated blocks. */
- VARRAY_BB_INIT (label_to_block_map, initial_cfg_capacity,
- "label to block map");
+ label_to_block_map = VEC_alloc (basic_block, gc, initial_cfg_capacity);
+ VEC_safe_grow (basic_block, gc, label_to_block_map, initial_cfg_capacity);
+ memset (VEC_address (basic_block, label_to_block_map),
+ 0, sizeof (basic_block) * initial_cfg_capacity);
BASIC_BLOCK (ENTRY_BLOCK) = ENTRY_BLOCK_PTR;
BASIC_BLOCK (EXIT_BLOCK) = EXIT_BLOCK_PTR;
@@ -804,9 +806,10 @@ label_to_block_fn (struct function *ifun
bsi_insert_before (&bsi, stmt, BSI_NEW_STMT);
uid = LABEL_DECL_UID (dest);
}
- if (VARRAY_SIZE (ifun->cfg->x_label_to_block_map) <= (unsigned int)uid)
+ if (VEC_length (basic_block, ifun->cfg->x_label_to_block_map)
+ <= (unsigned int) uid)
return NULL;
- return VARRAY_BB (ifun->cfg->x_label_to_block_map, uid);
+ return VEC_index (basic_block, ifun->cfg->x_label_to_block_map, uid);
}
/* Create edges for a goto statement at block BB. */
@@ -2714,15 +2717,26 @@ set_bb_for_stmt (tree t, basic_block bb)
uid = LABEL_DECL_UID (t);
if (uid == -1)
{
+ unsigned old_len = VEC_length (basic_block, label_to_block_map);
LABEL_DECL_UID (t) = uid = cfun->last_label_uid++;
- if (VARRAY_SIZE (label_to_block_map) <= (unsigned) uid)
- VARRAY_GROW (label_to_block_map, 3 * uid / 2);
+ if (old_len <= (unsigned) uid)
+ {
+ basic_block *addr;
+ unsigned new_len = 3 * uid / 2;
+
+ VEC_safe_grow (basic_block, gc, label_to_block_map,
+ new_len);
+ addr = VEC_address (basic_block, label_to_block_map);
+ memset (&addr[old_len],
+ 0, sizeof (basic_block) * (new_len - old_len));
+ }
}
else
/* We're moving an existing label. Make sure that we've
removed it from the old block. */
- gcc_assert (!bb || !VARRAY_BB (label_to_block_map, uid));
- VARRAY_BB (label_to_block_map, uid) = bb;
+ gcc_assert (!bb
+ || !VEC_index (basic_block, label_to_block_map, uid));
+ VEC_replace (basic_block, label_to_block_map, uid, bb);
}
}
}