This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Inliner for Java
- From: Jeff Sturm <jsturm at one-point dot com>
- To: Andrew Haley <aph at cambridge dot redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 10 Aug 2002 11:46:10 -0400 (EDT)
- Subject: Re: Inliner for Java
On Fri, 9 Aug 2002, Andrew Haley wrote:
> > a) no inlining of constructors, because they don't have DECL_INLINE set
> > b) no inlining from bytecode, since the jcf frontend doesn't produce
> > trees
> > c) inlining takes place in declaration order only, i.e. only preceding
> > methods are inlined
> > d) no inlining across translation units
> >
> > a) and c) seem easy to fix; I patched my own tree to do just that.
>
> Excellent. Will you post that patch?
Here's a diff from your inliner patch to my tree. I haven't regtested
yet.
2002-08-10 Jeff Sturm <jsturm@one-point.com>
* class.c (add_method_1): Set DECL_INLINE on constructors.
* parse.y (craft_constructor): Set DECL_INLINE on constructors.
(finish_method_declaration): Save method body for inlining here...
(end_artifical_method_body): ...and here...
(java_expand_method_bodies): ...but not here.
diff -rup java-orig/class.c java/class.c
--- java-orig/class.c Sun Aug 4 18:45:30 2002
+++ java/class.c Sat Aug 10 11:17:28 2002
@@ -639,6 +639,10 @@ add_method_1 (this_class, access_flags,
&& TREE_VALUE (TYPE_ARG_TYPES (function_type)) == void_type_node)
HAS_FINALIZER_P (this_class) = 1;
+ /* Constructors are inlining candidates. */
+ if (ID_INIT_P (name))
+ DECL_INLINE (fndecl) = 1;
+
if (access_flags & ACC_PUBLIC) METHOD_PUBLIC (fndecl) = 1;
if (access_flags & ACC_PROTECTED) METHOD_PROTECTED (fndecl) = 1;
if (access_flags & ACC_PRIVATE)
diff -rup java-orig/lang.c java/lang.c
--- java-orig/lang.c Sat Aug 10 11:18:22 2002
+++ java/lang.c Sat Aug 10 11:24:39 2002
@@ -811,6 +811,8 @@ java_post_options ()
}
}
+ /* Initialize the compiler back end. */
+ return false;
}
/* Return either DECL or its known constant value (if it has one). */
@@ -881,9 +883,6 @@ java_tree_inlining_walk_subtrees (tp,sub
default:
return NULL_TREE;
}
-
- /* Initialize the compiler back end. */
- return false;
}
/* Called from unsafe_for_reeval. */
diff -rup java-orig/parse.y java/parse.y
--- java-orig/parse.y Sat Aug 10 11:18:22 2002
+++ java/parse.y Sat Aug 10 11:16:23 2002
@@ -4825,6 +4825,12 @@ finish_method_declaration (method_body)
method_body = build1 (RETURN_EXPR, void_type_node, NULL);
BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)) = method_body;
+
+ /* Save the function for inlining. */
+ if (DECL_FUNCTION_BODY (current_function_decl) && flag_inline_trees)
+ DECL_SAVED_TREE (current_function_decl) =
+ BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl));
+
maybe_absorb_scoping_blocks ();
/* Exit function's body */
exit_block ();
@@ -5493,7 +5499,7 @@ craft_constructor (class_decl, args)
fix_method_argument_names (parm, decl);
/* Now, mark the artificial parameters. */
DECL_FUNCTION_NAP (decl) = artificial;
- DECL_FUNCTION_SYNTHETIC_CTOR (decl) = DECL_CONSTRUCTOR_P (decl) = 1;
+ DECL_INLINE (decl) = DECL_FUNCTION_SYNTHETIC_CTOR (decl) = DECL_CONSTRUCTOR_P (decl) = 1;
return decl;
}
@@ -7435,6 +7441,12 @@ end_artificial_method_body (mdecl)
we have an undefined behavior if no temporary variable is used.) */
tree b = exit_block ();
BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = b;
+
+ /* Save the function for inlining. */
+ if (DECL_FUNCTION_BODY (mdecl) && flag_inline_trees)
+ DECL_SAVED_TREE (mdecl) =
+ BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl));
+
exit_block ();
}
@@ -8135,11 +8147,6 @@ java_expand_method_bodies (class)
current_function_decl = decl;
- /* Save the function for inlining. */
- if (flag_inline_trees)
- DECL_SAVED_TREE (decl) =
- BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (decl));
-
/* It's time to assign the variable flagging static class
initialization based on which classes invoked static methods
are definitely initializing. This should be flagged. */