[patch] c-common.c: Stop using TREE_LIST for saved_function_name_decls.
Kazu Hirata
kazu@codesourcery.com
Fri Jun 2 19:04:00 GMT 2006
Hi,
Attached is a patch to stop using TREE_LIST for
saved_function_name_decls and use the VEC API instead.
Note that saved_function_name_decls works as a stack, which can be
translated to the VEC API in a very straightforward manner using
VEC_safe_push and VEC_pop.
I'd like to point out that saved_function_name_decls is a stack that
contains child stacks that are constructed in start_fname_decls.
Those child stacks still use TREE_LIST. I'll take care of that in a
separate patch.
Tested on x86_64-pc-linux-gnu. OK to apply to the LTO branch (and 4.3
once in Stage 1)?
Kazu Hirata
2006-06-02 Kazu Hirata <kazu@codesourcery.com>
* c-common.c (saved_function_name_decl_d,
saved_function_name_decl): New.
(saved_function_name_decls): Change the type to
VEC(saved_function_name_decl,gc) *.
(start_fname_decls, finish_fname_decls, fname_decl): Adjust
the uses of saved_function_name_decls.
* c-common.h (CTI_SAVED_FUNCTION_NAME_DECLS,
saved_function_name_decls): Remove.
Index: c-common.c
===================================================================
--- c-common.c (revision 114291)
+++ c-common.c (working copy)
@@ -189,13 +189,20 @@ cpp_reader *parse_in; /* Declared in c-
tree pretty_function_name_decl_node;
tree c99_function_name_decl_node;
- Stack of nested function name VAR_DECLs.
-
- tree saved_function_name_decls;
-
*/
tree c_global_trees[CTI_MAX];
+
+typedef struct saved_function_name_decl_d GTY(()) {
+ tree decl;
+ tree stmts;
+} saved_function_name_decl;
+
+DEF_VEC_O(saved_function_name_decl);
+DEF_VEC_ALLOC_O(saved_function_name_decl,gc);
+
+/* Stack of nested function name VAR_DECLs. */
+VEC(saved_function_name_decl,gc) *saved_function_name_decls;
/* Switches common to the C front ends. */
@@ -670,10 +677,16 @@ start_fname_decls (void)
}
}
if (saved || saved_function_name_decls)
- /* Normally they'll have been NULL, so only push if we've got a
- stack, or they are non-NULL. */
- saved_function_name_decls = tree_cons (saved, NULL_TREE,
- saved_function_name_decls);
+ {
+ saved_function_name_decl *sfnd;
+
+ /* Normally they'll have been NULL, so only push if we've got a
+ stack, or they are non-NULL. */
+ sfnd = VEC_safe_push (saved_function_name_decl, gc,
+ saved_function_name_decls, NULL);
+ sfnd->decl = saved;
+ sfnd->stmts = NULL_TREE;
+ }
}
/* Finish up the current bindings, adding them into the current function's
@@ -686,10 +699,16 @@ finish_fname_decls (void)
{
unsigned ix;
tree stmts = NULL_TREE;
- tree stack = saved_function_name_decls;
+ saved_function_name_decl *p;
- for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack))
- append_to_statement_list (TREE_VALUE (stack), &stmts);
+ while (!VEC_empty (saved_function_name_decl, saved_function_name_decls))
+ {
+ p = VEC_last (saved_function_name_decl, saved_function_name_decls);
+ if (p->stmts == NULL_TREE)
+ break;
+ append_to_statement_list (p->stmts, &stmts);
+ VEC_pop (saved_function_name_decl, saved_function_name_decls);
+ }
if (stmts)
{
@@ -705,21 +724,26 @@ finish_fname_decls (void)
for (ix = 0; fname_vars[ix].decl; ix++)
*fname_vars[ix].decl = NULL_TREE;
- if (stack)
+ if (!VEC_empty (saved_function_name_decl, saved_function_name_decls))
{
/* We had saved values, restore them. */
tree saved;
- for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved))
+ for (saved = VEC_last (saved_function_name_decl,
+ saved_function_name_decls)->decl;
+ saved;
+ saved = TREE_CHAIN (saved))
{
tree decl = TREE_PURPOSE (saved);
unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved));
*fname_vars[ix].decl = decl;
}
- stack = TREE_CHAIN (stack);
+ VEC_pop (saved_function_name_decl, saved_function_name_decls);
}
- saved_function_name_decls = stack;
+
+ if (VEC_empty (saved_function_name_decl, saved_function_name_decls))
+ saved_function_name_decls = NULL;
}
/* Return the text name of the current function, suitably prettified
@@ -822,8 +846,13 @@ fname_decl (unsigned int rid, tree id)
decl = (*make_fname_decl) (id, fname_vars[ix].pretty);
stmts = pop_stmt_list (stmts);
if (!IS_EMPTY_STMT (stmts))
- saved_function_name_decls
- = tree_cons (decl, stmts, saved_function_name_decls);
+ {
+ saved_function_name_decl *sfnd;
+ sfnd = VEC_safe_push (saved_function_name_decl, gc,
+ saved_function_name_decls, NULL);
+ sfnd->decl = decl;
+ sfnd->stmts = stmts;
+ }
*fname_vars[ix].decl = decl;
input_location = saved_location;
}
Index: c-common.h
===================================================================
--- c-common.h (revision 114291)
+++ c-common.h (working copy)
@@ -155,7 +155,6 @@ enum c_tree_index
CTI_FUNCTION_NAME_DECL,
CTI_PRETTY_FUNCTION_NAME_DECL,
CTI_C99_FUNCTION_NAME_DECL,
- CTI_SAVED_FUNCTION_NAME_DECLS,
CTI_VOID_ZERO,
@@ -200,7 +199,6 @@ struct c_common_identifier GTY(())
#define function_name_decl_node c_global_trees[CTI_FUNCTION_NAME_DECL]
#define pretty_function_name_decl_node c_global_trees[CTI_PRETTY_FUNCTION_NAME_DECL]
#define c99_function_name_decl_node c_global_trees[CTI_C99_FUNCTION_NAME_DECL]
-#define saved_function_name_decls c_global_trees[CTI_SAVED_FUNCTION_NAME_DECLS]
/* A node for `((void) 0)'. */
#define void_zero_node c_global_trees[CTI_VOID_ZERO]
More information about the Gcc-patches
mailing list