dpatel 02/09/05 18:15:21
Modified: gcc/cp cp-tree.h decl.c decl2.c
Log:
Reorganize cp_bining_level to avoid walking chain of all
variables multiple time.
Revision Changes Path
1.68 +6 -0 gcc3/gcc/cp/cp-tree.h
Index: cp-tree.h
===================================================================
RCS file: /cvs/Darwin/gcc3/gcc/cp/cp-tree.h,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- cp-tree.h 2002/08/26 05:40:58 1.67
+++ cp-tree.h 2002/09/06 01:15:19 1.68
@@ -3755,6 +3755,12 @@
extern int walk_globals PARAMS ((walk_globals_pred,
walk_globals_fn,
void *));
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+extern int walk_vtables PARAMS ((walk_globals_pred,
+ walk_globals_fn,
+ void *));
+/* APPLE LOCAL end cp_binding_level dpatel */
typedef int (*walk_namespaces_fn) PARAMS ((tree, void *));
extern int walk_namespaces PARAMS ((walk_namespaces_fn,
void *));
1.115 +110 -36 gcc3/gcc/cp/decl.c
Index: decl.c
===================================================================
RCS file: /cvs/Darwin/gcc3/gcc/cp/decl.c,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -r1.114 -r1.115
--- decl.c 2002/09/02 03:50:02 1.114
+++ decl.c 2002/09/06 01:15:19 1.115
@@ -117,6 +117,10 @@
static void warn_about_implicit_typename_lookup PARAMS ((tree, tree));
static int walk_namespaces_r PARAMS ((tree, walk_namespaces_fn, void *));
static int walk_globals_r PARAMS ((tree, void *));
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+static int walk_vtables_r PARAMS ((tree, void *));
+/* APPLE LOCAL end cp_binding_level dpatel */
static void add_decl_to_level PARAMS ((tree, struct cp_binding_level *));
static tree make_label_decl PARAMS ((tree, int));
static void use_label PARAMS ((tree));
@@ -336,6 +340,18 @@
are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD. */
tree names;
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+ /* Count of elements in names chain. */
+ size_t names_size;
+
+ /* A chain of NAMESPACE_DECL nodes. */
+ tree namespaces;
+
+ /* A chain of VTABLE_DECL nodes. */
+ tree vtables;
+/* APPLE LOCAL end cp_binding_level dpatel */
+
/* A list of structure, union and enum definitions, for looking up
tag names.
It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
@@ -1026,10 +1042,31 @@
tree decl;
struct cp_binding_level *b;
{
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+ if (TREE_CODE (decl) == NAMESPACE_DECL
+ && !DECL_NAMESPACE_ALIAS (decl))
+ {
+ TREE_CHAIN (decl) = b->namespaces;
+ b->namespaces = decl;
+ }
+ else if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
+ {
+ TREE_CHAIN (decl) = b->vtables;
+ b->vtables = decl;
+ }
+ else
+ {
+/* APPLE LOCAL end cp_binding_level dpatel */
/* We build up the list in reverse order, and reverse it later if
necessary. */
TREE_CHAIN (decl) = b->names;
b->names = decl;
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+ b->names_size++;
+ }
+/* APPLE LOCAL end cp_binding_level dpatel */
}
/* Bind DECL to ID in the current_binding_level, assumed to be a local
@@ -1766,6 +1803,57 @@
return NAMESPACE_LEVEL (ns)->names;
}
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+/* Move this struct from original location. */
+struct walk_globals_data {
+ walk_globals_pred p;
+ walk_globals_fn f;
+ void *data;
+};
+/* APPLE LOCAL end cp_binding_level dpatel */
+
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+/* Walk the vtable declarations in NAMESPACE. Whenever one is found
+ for which P returns non-zero, call F with its address. If any call
+ to F returns a non-zero value, return a non-zero value. */
+
+static int
+walk_vtables_r (namespace, data)
+ tree namespace;
+ void *data;
+{
+ struct walk_globals_data* wgd = (struct walk_globals_data *) data;
+ walk_globals_fn f = wgd->f;
+ void *d = wgd->data;
+ tree decl = NAMESPACE_LEVEL (namespace)->vtables;
+ int result = 0;
+
+ for (; decl ; decl = TREE_CHAIN (decl))
+ result != (*f) (&decl, d);
+
+ return result;
+}
+
+/* Walk the vtable declarations. Whenever one is found for which P
+ returns non-zero, call F with its address. If any call to F
+ returns a non-zero value, return a non-zero value. */
+int
+walk_vtables (p, f, data)
+ walk_globals_pred p;
+ walk_globals_fn f;
+ void *data;
+{
+ struct walk_globals_data wgd;
+ wgd.p = p;
+ wgd.f = f;
+ wgd.data = data;
+
+ return walk_namespaces (walk_vtables_r, &wgd);
+}
+/* APPLE LOCAL end cp_binding_level dpatel */
+
/* Walk all the namespaces contained NAMESPACE, including NAMESPACE
itself, calling F for each. The DATA is passed to F as well. */
@@ -1775,22 +1863,19 @@
walk_namespaces_fn f;
void *data;
{
- tree current;
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+ tree current = NAMESPACE_LEVEL (namespace)->namespaces;
+/* APPLE LOCAL end cp_binding_level dpatel */
int result = 0;
result |= (*f) (namespace, data);
-
- for (current = cp_namespace_decls (namespace);
- current;
- current = TREE_CHAIN (current))
- {
- if (TREE_CODE (current) != NAMESPACE_DECL
- || DECL_NAMESPACE_ALIAS (current))
- continue;
- /* We found a namespace. */
- result |= walk_namespaces_r (current, f, data);
- }
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+ for (; current; current = TREE_CHAIN (current))
+ result |= walk_namespaces_r (current, f, data);
+/* APPLE LOCAL end cp_binding_level dpatel */
return result;
}
@@ -1806,12 +1891,6 @@
return walk_namespaces_r (global_namespace, f, data);
}
-struct walk_globals_data {
- walk_globals_pred p;
- walk_globals_fn f;
- void *data;
-};
-
/* Walk the global declarations in NAMESPACE. Whenever one is found
for which P returns non-zero, call F with its address. If any call
to F returns a non-zero value, return a non-zero value. */
@@ -1874,7 +1953,10 @@
void *data;
{
tree globals = cp_namespace_decls (namespace);
- int len = list_length (globals);
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+ int len = NAMESPACE_LEVEL (namespace)->names_size;
+/* APPLE LOCAL end cp_binding_level dpatel */
tree *vec = (tree *) alloca (sizeof (tree) * len);
int i;
int result;
@@ -1896,27 +1978,19 @@
return 0;
}
- /* Temporarily mark vtables as external. That prevents
- wrapup_global_declarations from writing them out; we must process
- them ourselves in finish_vtable_vardecl. */
- for (i = 0; i < len; ++i)
- if (vtable_decl_p (vec[i], /*data=*/0) && !DECL_EXTERNAL (vec[i]))
- {
- DECL_NOT_REALLY_EXTERN (vec[i]) = 1;
- DECL_EXTERNAL (vec[i]) = 1;
- }
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+ /* Remove 'for' loop to mark vtables as external. */
+/* APPLE LOCAL end cp_binding_level dpatel */
/* Write out any globals that need to be output. */
result = wrapup_global_declarations (vec, len);
- /* Undo the hack to DECL_EXTERNAL above. */
- for (i = 0; i < len; ++i)
- if (vtable_decl_p (vec[i], /*data=*/0)
- && DECL_NOT_REALLY_EXTERN (vec[i]))
- {
- DECL_NOT_REALLY_EXTERN (vec[i]) = 0;
- DECL_EXTERNAL (vec[i]) = 0;
- }
+/* APPLE LOCAL begin cp_binding_level dpatel */
+/* FSF Candidate */
+ /* Remove for loop to to undo vtable marking as external. */
+/* APPLE LOCAL end cp_binding_level dpatel */
+
return result;
}
1.90 +10 -7 gcc3/gcc/cp/decl2.c
Index: decl2.c
===================================================================
RCS file: /cvs/Darwin/gcc3/gcc/cp/decl2.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- decl2.c 2002/09/02 03:50:02 1.89
+++ decl2.c 2002/09/06 01:15:20 1.90
@@ -2846,9 +2846,13 @@
/* Write out virtual tables as required. Note that writing out
the virtual table for a template class may cause the
instantiation of members of that class. */
- if (walk_globals (vtable_decl_p,
+ /* APPLE LOCAL begin cp_binding_level dpatel */
+ /* FSF Candidate */
+ /* Use walk_vtables() instead of walk_globals. */
+ if (walk_vtables (vtable_decl_p,
finish_vtable_vardecl,
/*data=*/0))
+ /* APPLE LOCAL end cp_binding_level dpatel */
reconsider = 1;
/* Write out needed type info variables. Writing out one variable
@@ -3043,12 +3047,11 @@
linkage now. */
pop_lang_context ();
- /* Now delete from the chain of variables all virtual function tables.
- We output them all ourselves, because each will be treated
- specially. We don't do this if we're just doing semantic
- analysis, and not code-generation. */
- if (!flag_syntax_only)
- walk_globals (vtable_decl_p, prune_vtable_vardecl, /*data=*/0);
+ /* APPLE LOCAL begin cp_binding_level dpatel */
+ /* FSF Candidate */
+ /* Remove walk_globals() call to delete vtables from chain of
+ all variables. */
+ /* APPLE LOCAL end cp_binding_level dpatel */
/* Now, issue warnings about static, but not defined, functions,
etc., and emit debugging information. */