This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: re-enable static initializer optimization
- From: Per Bothner <per at bothner dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: java at gcc dot gnu dot org
- Date: Thu, 06 Dec 2001 13:37:45 -0800
- Subject: PATCH: re-enable static initializer optimization
Here is my patch to re-enable the static initialier optimizaton.
The critical change is in the code that checks whether
one of the initilier variables is always set. I moved
this to check_init instead of java_complete_expand_method,
the old code would return a bitset, but that was not safe.
I made some other tweaks, te most inportant was to get
rid of DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND
as a hashtable, and just use a list. I didn't see any
reason why we actully needed a hashtable.
I also think it might be reasonable to combine the
remaining two per-method hashtables, given that they
have the same key and that all value stored in
DECL_FUNCTION_INITIALIZED_CLASS_TABLE is just a single
bit indocating its existence. It should be straight-forward
to replace that hashtable and just use init_test_table.
However, I did not do that.
I'll let Alex take a look before I check this in.
I've done a bootstrap and the testsuite has no regressions.
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/
2001-12-05 Per Bothner <per@bothner.com>
Restore support for static class initialization optimization.
* java-tree.h (STATIC_CLASS_INIT_OPT_P): Re-enable.
* check-init.c (check_int): At end of BLOCK handle initialization
blocks, which used to be done in java_complete_expand_method but did
not handle the case where check_for_initialization might allocate
more than a word of bits.
* decl.c (lang_make_tree): The smic field is now a tree.
* expr.c (build_class_init): Set DECL_FUNCTION_INIT_TEST_CLASS field.
* java-tree.h (DECL_FUNCTION_INIT_TEST_TABLE): New macro.
* parse.y (emit_test_initialization): Combine hash_lookup calls.
* java-tree.h (DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND):
Change from a hash table to a list.
(struct_lang_decl): Change field 'smic' to match.
* class.c (add_method_1): Initialize
DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND to null list.
* parse.y (adjust_init_test_initialization): Removed - inlined into -
(java_expand_method_bodies): -here, since 'smic' is now a list.
(patch_invoke): Add to 'smic' list, instead of hash_lookup.
* check-init.c (WORD_SIZE): Use BITS_PER_UNIT.
* class.c (java_hash_compare_tree_node): Fix casts.
Index: check-init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/check-init.c,v
retrieving revision 1.35
diff -u -p -r1.35 check-init.c
--- check-init.c 2001/12/04 19:30:13 1.35
+++ check-init.c 2001/12/06 21:32:24
@@ -96,7 +96,7 @@ static tree wfl;
#define INTERSECT(DST, SRC1, SRC2) \
INTERSECTN (DST, SRC1, SRC2, num_current_words)
-#define WORD_SIZE ((unsigned int)(sizeof(word) * 8))
+#define WORD_SIZE ((unsigned int)(sizeof(word) * BITS_PER_UNIT))
static void check_bool_init PARAMS ((tree, words, words, words));
static void check_init PARAMS ((tree, words));
@@ -595,6 +595,24 @@ check_init (exp, before)
SET_UNASSIGNED (tmp, i);
}
check_init (BLOCK_EXPR_BODY (exp), tmp);
+
+ /* Re-set DECL_BIT_INDEX since it is also DECL_POINTER_ALIAS_SET. */
+ for (decl = BLOCK_EXPR_DECLS (exp);
+ decl != NULL_TREE; decl = TREE_CHAIN (decl))
+ {
+ if (LOCAL_CLASS_INITIALIZATION_FLAG_P (decl))
+ {
+ int index = DECL_BIT_INDEX (decl);
+ tree fndecl = DECL_CONTEXT (decl);
+ if (fndecl && METHOD_STATIC (fndecl)
+ && (DECL_INITIAL (decl) == boolean_true_node
+ || (index >= 0 && ASSIGNED_P (tmp, index))))
+ hash_lookup (&DECL_FUNCTION_INITIALIZED_CLASS_TABLE (fndecl),
+ DECL_FUNCTION_INIT_TEST_CLASS(decl), TRUE, NULL);
+ }
+ DECL_BIT_INDEX (decl) = -1;
+ }
+
num_current_locals = start_current_locals;
start_current_locals = save_start_current_locals;
if (tmp != before)
@@ -602,13 +620,6 @@ check_init (exp, before)
num_current_words = save_num_current_words;
COPY (before, tmp);
FREE_WORDS (tmp);
- }
-
- /* Re-set DECL_BIT_INDEX since it is also DECL_POINTER_ALIAS_SET. */
- for (decl = BLOCK_EXPR_DECLS (exp);
- decl != NULL_TREE; decl = TREE_CHAIN (decl))
- {
- DECL_BIT_INDEX (decl) = -1;
}
}
break;
Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.116
diff -u -p -r1.116 class.c
--- class.c 2001/11/30 09:55:06 1.116
+++ class.c 2001/12/06 21:32:25
@@ -656,7 +656,7 @@ java_hash_compare_tree_node (k1, k2)
hash_table_key k1;
hash_table_key k2;
{
- return ((char*) k1 == (char*) k2);
+ return ((tree) k1 == (tree) k2);
}
tree
@@ -688,11 +688,8 @@ add_method_1 (handle_class, access_flags
init_test_hash_newfunc, java_hash_hash_tree_node,
java_hash_compare_tree_node);
- /* Initialize the static method invocation compound table */
- if (STATIC_CLASS_INIT_OPT_P ())
- hash_table_init (&DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl),
- init_test_hash_newfunc, java_hash_hash_tree_node,
- java_hash_compare_tree_node);
+ /* Initialize the static method invocation compound list */
+ DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl) = NULL_TREE;
TREE_CHAIN (fndecl) = TYPE_METHODS (handle_class);
TYPE_METHODS (handle_class) = fndecl;
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.111
diff -u -p -r1.111 decl.c
--- decl.c 2001/12/04 01:10:07 1.111
+++ decl.c 2001/12/06 21:32:27
@@ -1847,7 +1847,7 @@ lang_mark_tree (t)
ggc_mark_tree (ld->inner_access);
ggc_mark_tree_hash_table (&ld->init_test_table);
ggc_mark_tree_hash_table (&ld->ict);
- ggc_mark_tree_hash_table (&ld->smic);
+ ggc_mark_tree (ld->smic);
}
}
else if (TYPE_P (t))
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.122
diff -u -p -r1.122 expr.c
--- expr.c 2001/12/04 19:30:13 1.122
+++ expr.c 2001/12/06 21:32:29
@@ -1729,7 +1729,7 @@ build_class_init (clas, expr)
MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (ite->init_test_decl);
LOCAL_CLASS_INITIALIZATION_FLAG (ite->init_test_decl) = 1;
DECL_CONTEXT (ite->init_test_decl) = current_function_decl;
-
+ DECL_FUNCTION_INIT_TEST_CLASS (ite->init_test_decl) = clas;
/* Tell the check-init code to ignore this decl when not
optimizing class initialization. */
if (!STATIC_CLASS_INIT_OPT_P ())
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.126
diff -u -p -r1.126 java-tree.h
--- java-tree.h 2001/12/04 19:30:13 1.126
+++ java-tree.h 2001/12/06 21:32:30
@@ -726,14 +726,17 @@ struct lang_identifier
class has been initialized in this function, and FALSE otherwise. */
#define DECL_FUNCTION_INIT_TEST_TABLE(DECL) \
(DECL_LANG_SPECIFIC(DECL)->init_test_table)
+/* If LOCAL_CLASS_INITIALIZATION_FLAG_P(decl), give class it initializes. */
+#define DECL_FUNCTION_INIT_TEST_CLASS(DECL) \
+ (((struct lang_decl_var*)DECL_LANG_SPECIFIC(DECL))->slot_chain)
/* For each static function decl, itc contains a hash table whose
entries are keyed on class named that are definitively initialized
in DECL. */
#define DECL_FUNCTION_INITIALIZED_CLASS_TABLE(DECL) \
(DECL_LANG_SPECIFIC(DECL)->ict)
-/* For each static function call, smic contains contains a hash table
- whose entries are keyed on the compound statement that encapsulate
- the invocation. */
+/* A list of all the static method calls in the method DECL (if optimizing).
+ Actually each TREE_VALUE points to a COMPONT_EXPR that wraps the
+ invoation so we can later patch it. */
#define DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND(DECL) \
(DECL_LANG_SPECIFIC(DECL)->smic)
/* The Number of Artificial Parameters (NAP) DECL contains. this$<n>
@@ -888,7 +891,7 @@ struct lang_decl
struct hash_table init_test_table;
/* Class initialization test variables */
struct hash_table ict; /* Initialized (static) Class Table */
- struct hash_table smic; /* Static method invocation compound */
+ tree smic; /* Static method invocation compound */
tree inner_access; /* The identifier of the access method
used for invocation from inner classes */
int nap; /* Number of artificial parameters */
@@ -1604,8 +1607,7 @@ extern tree *type_map;
/* True when we can perform static class initialization optimization */
#define STATIC_CLASS_INIT_OPT_P() \
- 0 /* ??? Temporarily turn off this optimization -PB */
-/* (flag_optimize_sci && (optimize >= 2) && ! flag_emit_class_files)*/
+ (flag_optimize_sci && (optimize >= 2) && ! flag_emit_class_files)
extern int java_error_count;
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.330
diff -u -p -r1.330 parse.y
--- parse.y 2001/12/04 19:30:13 1.330
+++ parse.y 2001/12/06 21:32:39
@@ -335,8 +335,6 @@ static tree maybe_build_class_init_for_f
static bool attach_init_test_initialization_flags PARAMS ((struct hash_entry *,
PTR));
-static bool adjust_init_test_initialization PARAMS ((struct hash_entry *,
- PTR));
static bool emit_test_initialization PARAMS ((struct hash_entry *, PTR));
/* Number of error found so far. */
@@ -8017,21 +8015,16 @@ java_complete_expand_method (mdecl)
static variables and see whether they're definitively
assigned, in which case the type is remembered as
definitively initialized in MDECL. */
- /* FIXME this doesn't work state is too short.
if (STATIC_CLASS_INIT_OPT_P ())
{
- hash_traverse (&DECL_FUNCTION_INIT_TEST_TABLE (mdecl),
- attach_initialized_static_class, (PTR)&state);
-
- / * Always register the context as properly initialized in
+ /* Always register the context as properly initialized in
MDECL. This used with caution helps removing extra
- initialization of self. * /
+ initialization of self. */
if (METHOD_STATIC (mdecl))
hash_lookup (&DECL_FUNCTION_INITIALIZED_CLASS_TABLE (mdecl),
(hash_table_key) DECL_CONTEXT (mdecl),
TRUE, NULL);
}
- */
}
ctxp->explicit_constructor_p = 0;
}
@@ -8081,8 +8074,32 @@ java_expand_method_bodies (class)
initialization based on which classes invoked static methods
are definitely initializing. This should be flagged. */
if (STATIC_CLASS_INIT_OPT_P ())
- hash_traverse (&DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (decl),
- adjust_init_test_initialization, NULL);
+ {
+ tree list = DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (decl);
+ for (; list != NULL_TREE; list = TREE_CHAIN (list))
+ {
+ /* Executed for each statement calling a static function.
+ LIST is a TREE_LIST whose PURPOSE is the called function
+ and VALUE is a compound whose second operand can be patched
+ with static class initialization flag assignments. */
+
+ tree called_method = TREE_PURPOSE (list);
+ tree compound = TREE_VALUE (list);
+ tree assignment_compound_list
+ = build_tree_list (called_method, NULL);
+
+ /* For each class definitely initialized in
+ CALLED_METHOD, fill ASSIGNMENT_COMPOUND with
+ assignment to the class initialization flag. */
+ hash_traverse (&DECL_FUNCTION_INITIALIZED_CLASS_TABLE (called_method),
+ emit_test_initialization,
+ assignment_compound_list);
+
+ if (TREE_VALUE (assignment_compound_list))
+ TREE_OPERAND (compound, 1)
+ = TREE_VALUE (assignment_compound_list);
+ }
+ }
/* Prepare the function for RTL expansion */
start_complete_expand_method (decl);
@@ -10691,10 +10708,10 @@ patch_invoke (patch, method, args)
tree type = TREE_TYPE (patch);
patch = build (COMPOUND_EXPR, type, save, empty_stmt_node);
- list = build_tree_list (method, patch);
+ list = tree_cons (method, patch,
+ DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl));
- hash_lookup (&DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl),
- (const hash_table_key) list, TRUE, NULL);
+ DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl) = list;
patch = build (COMPOUND_EXPR, type, patch, save);
}
@@ -15974,32 +15991,6 @@ attach_init_test_initialization_flags (e
return true;
}
-/* This function is called for each statement calling a static
- function. ENTRY is a TREE_LIST whose PURPOSE is the called
- function and VALUE is a compound whose second operand can be
- patched with static class initialization flag assignments. */
-
-static bool
-adjust_init_test_initialization (entry, info)
- struct hash_entry *entry;
- PTR info ATTRIBUTE_UNUSED;
-{
- tree list = (tree)(entry->key);
- tree called_method = TREE_PURPOSE (list);
- tree compound = TREE_VALUE (list);
- tree assignment_compound_list = build_tree_list (called_method, NULL);
-
- /* For each class definitely initialized in CALLED_METHOD, fill
- ASSIGNMENT_COMPOUND with assignment to the class initialization flag. */
- hash_traverse (&DECL_FUNCTION_INITIALIZED_CLASS_TABLE (called_method),
- emit_test_initialization, assignment_compound_list);
-
- if (TREE_VALUE (assignment_compound_list))
- TREE_OPERAND (compound, 1) = TREE_VALUE (assignment_compound_list);
-
- return true;
-}
-
/* This function is called for each classes that is known definitely
assigned when a given static method was called. This function
augments a compound expression (INFO) storing all assignment to
@@ -16016,21 +16007,15 @@ emit_test_initialization (entry, info)
struct init_test_hash_entry *ite = (struct init_test_hash_entry *)
hash_lookup (&DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl),
- entry->key, FALSE, NULL);
+ entry->key,
+ current_function_decl != TREE_PURPOSE (l), NULL);
/* If we haven't found a flag and we're dealing with self registered
with current_function_decl, then don't do anything. Self is
always added as definitely initialized but this information is
valid only if used outside the current function. */
if (! ite)
- {
- if (current_function_decl != TREE_PURPOSE (l))
- ite = (struct init_test_hash_entry *)
- hash_lookup (&DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl),
- entry->key, TRUE, NULL);
- else
- return true;
- }
+ return true;
/* If we don't have a variable, create one and install it. */
if (! ite->init_test_decl)