This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: inlining methods



Per Bothner writes:

> (2) Set DECL_INLINE on all methods that are final, private, or
> static.  (Look for where METHOD_FINAL, METHOD_STATIC, or
> METHOD_PRIVATE are set in *.[cy].)

I believe they're all in class.c:

Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/class.c,v
retrieving revision 1.45
diff -u -p -r1.45 class.c
--- class.c     1999/09/11 22:22:57     1.45
+++ class.c     1999/10/27 01:50:17
@@ -427,10 +427,13 @@ add_method_1 (handle_class, access_flags
 
   if (access_flags & ACC_PUBLIC) METHOD_PUBLIC (fndecl) = 1;
   if (access_flags & ACC_PROTECTED) METHOD_PROTECTED (fndecl) = 1;
-  if (access_flags & ACC_PRIVATE) METHOD_PRIVATE (fndecl) = 1;
+  if (access_flags & ACC_PRIVATE)
+    METHOD_PRIVATE (fndecl) = DECL_INLINE (fndecl) = 1;
   if (access_flags & ACC_NATIVE) METHOD_NATIVE (fndecl) = 1;
-  if (access_flags & ACC_STATIC) METHOD_STATIC (fndecl) = 1;
-  if (access_flags & ACC_FINAL) METHOD_FINAL (fndecl) = 1;
+  if (access_flags & ACC_STATIC) 
+    METHOD_STATIC (fndecl) = DECL_INLINE (fndecl) = 1;
+  if (access_flags & ACC_FINAL) 
+    METHOD_FINAL (fndecl) = DECL_INLINE (fndecl) = 1;
   if (access_flags & ACC_SYNCHRONIZED) METHOD_SYNCHRONIZED (fndecl) = 1;
   if (access_flags & ACC_ABSTRACT) METHOD_ABSTRACT (fndecl) = 1;
   if (access_flags & ACC_TRANSIENT) METHOD_TRANSIENT (fndecl) = 1;

But this actually won't help (I remember trying a while back and
witnessing it not working, without having much time or momentum to
work on it.)

gcj doesn't do inlining because it gcc fails detecting the candidates,
something with is done at some point in expand_call. It fails because
the way function calls are originally formed, like in
expr.c:expand_invoke():

  func = build1 (NOP_EXPR, build_pointer_type (method_type), func);

Or similarly in parse.y:patch_invoke(). I verified that the following
patch to gcc/calls.c fixes the problem, but I haven't yet furthered
the tests:

Index: calls.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/calls.c,v
retrieving revision 1.63
diff -u -p -r1.63 calls.c
--- calls.c     1999/09/20 09:59:37     1.63
+++ calls.c     1999/10/27 01:57:04
@@ -1648,9 +1648,13 @@ expand_call (exp, target, ignore)
      As a result, decide whether this is a call to an integrable function.  */
 
   p = TREE_OPERAND (exp, 0);
-  if (TREE_CODE (p) == ADDR_EXPR)
+  if (TREE_CODE (p) == ADDR_EXPR 
+      || (TREE_CODE (p) == NOP_EXPR 
+         && TREE_CODE (TREE_OPERAND (p, 0)) == ADDR_EXPR))
     {
       fndecl = TREE_OPERAND (p, 0);
+      if (TREE_CODE (fndecl) == ADDR_EXPR)
+         fndecl = TREE_OPERAND (fndecl, 0);
       if (TREE_CODE (fndecl) != FUNCTION_DECL)
        fndecl = 0;
       else

With this patch, I verified that at least `static int foo (int a, int
b){ return a+b; }', provided that it is declared before it is used,
gets inlined.

> I believe this is a function of the Gcc backend, and nothing that
> gcj needs to do specifically.

Since `rest_of_compilation', at first glance, does the actual trick
of saving insns and marking relevant things up, some more work might
be required in the front-end in order to reorder the invocation of
`rest_of_compilation' on candidates to inlining.

./A

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]