changeset 3100:c49c893c3d27

small inlining simplification
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 29 Jun 2011 20:11:13 +0200
parents 28484c5f00d7
children 6ccb95c97e6d 9ef0777a61d5
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java
diffstat 1 files changed, 33 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Wed Jun 29 19:53:00 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Wed Jun 29 20:11:13 2011 +0200
@@ -44,9 +44,6 @@
     private final GraalCompilation compilation;
     private final IR ir;
 
-    private final Queue<Invoke> invokes = new ArrayDeque<Invoke>();
-    private final Queue<RiMethod> methods = new ArrayDeque<RiMethod>();
-
     private int inliningSize;
     private final Collection<Invoke> hints;
 
@@ -56,12 +53,6 @@
         this.hints = hints;
     }
 
-    private void addToQueue(Invoke invoke, RiMethod method) {
-        invokes.add(invoke);
-        methods.add(method);
-        inliningSize += method.codeSize();
-    }
-
     private Queue<Invoke> newInvokes = new ArrayDeque<Invoke>();
     private Graph graph;
 
@@ -85,37 +76,36 @@
             newInvokes = new ArrayDeque<Invoke>();
             for (Invoke invoke : queue) {
                 if (!invoke.isDeleted()) {
-                    inlineInvoke(invoke, iterations, ratio);
-                    if (inliningSize > GraalOptions.MaximumInstructionCount) {
-                        break;
+                    RiMethod code = inlineInvoke(invoke, iterations, ratio);
+                    if (code != null) {
+                        inliningSize += code.codeSize();
+                        if (inliningSize > GraalOptions.MaximumInstructionCount) {
+                            break;
+                        }
+
+                        inlineMethod(invoke, code);
+                        if (GraalOptions.TraceInlining) {
+                            if (methodCount.get(code) == null) {
+                                methodCount.put(code, 1);
+                            } else {
+                                methodCount.put(code, methodCount.get(code) + 1);
+                            }
+                        }
                     }
                 }
             }
-
-            assert invokes.size() == methods.size();
-            if (invokes.isEmpty()) {
-                break;
-            }
-
-            Invoke invoke;
-            while ((invoke = invokes.poll()) != null) {
-                RiMethod method = methods.remove();
-                inlineMethod(invoke, method);
-
-                if (methodCount.get(method) == null) {
-                    methodCount.put(method, 1);
-                } else {
-                    methodCount.put(method, methodCount.get(method) + 1);
-                }
-            }
-            new DeadCodeEliminationPhase().apply(graph);
-
             if (inliningSize > GraalOptions.MaximumInstructionCount) {
                 if (GraalOptions.TraceInlining) {
                     TTY.println("inlining stopped: MaximumInstructionCount reached");
                 }
                 break;
             }
+            if (newInvokes.isEmpty()) {
+                break;
+            }
+
+//            new DeadCodeEliminationPhase().apply(graph);
+
             ratio *= GraalOptions.MaximumInlineRatio;
         }
 
@@ -132,28 +122,26 @@
         }
     }
 
-    private boolean inlineInvoke(Invoke invoke, int iterations, float ratio) {
+    private RiMethod inlineInvoke(Invoke invoke, int iterations, float ratio) {
         RiMethod parent = invoke.stateAfter().method();
         RiTypeProfile profile = parent.typeProfile(invoke.bci);
         if (!checkInvokeConditions(invoke)) {
-            return false;
+            return null;
         }
         if (invoke.opcode() == Bytecodes.INVOKESPECIAL || invoke.target.canBeStaticallyBound()) {
             if (checkTargetConditions(invoke.target, iterations) && checkSizeConditions(invoke.target, invoke, profile, ratio)) {
-                addToQueue(invoke, invoke.target);
-                return true;
+                return invoke.target;
             }
-            return false;
+            return null;
         }
         if (invoke.receiver().exactType() != null) {
             RiType exact = invoke.receiver().exactType();
             assert exact.isSubtypeOf(invoke.target().holder()) : exact + " subtype of " + invoke.target().holder();
             RiMethod resolved = exact.resolveMethodImpl(invoke.target());
             if (checkTargetConditions(resolved, iterations) && checkSizeConditions(resolved, invoke, profile, ratio)) {
-                addToQueue(invoke, resolved);
-                return true;
+                return resolved;
             }
-            return false;
+            return null;
         }
         RiType holder = invoke.target().holder();
 
@@ -175,10 +163,9 @@
                     TTY.println("recording concrete method assumption: %s -> %s", targetName, concreteName);
                 }
                 compilation.assumptions.recordConcreteMethod(invoke.target, concrete);
-                addToQueue(invoke, concrete);
-                return true;
+                return concrete;
             }
-            return false;
+            return null;
         }
         if (profile != null && profile.probabilities != null && profile.probabilities.length > 0 && profile.morphism == 1) {
             if (GraalOptions.InlineWithTypeCheck) {
@@ -195,21 +182,20 @@
                     if (GraalOptions.TraceInlining) {
                         TTY.println("inlining with type check, type probability: %5.3f", profile.probabilities[0]);
                     }
-                    addToQueue(invoke, concrete);
-                    return true;
+                    return concrete;
                 }
-                return false;
+                return null;
             } else {
                 if (GraalOptions.TraceInlining) {
                     TTY.println("not inlining %s because GraalOptions.InlineWithTypeCheck == false", methodName(invoke.target, invoke));
                 }
-                return false;
+                return null;
             }
         } else {
             if (GraalOptions.TraceInlining) {
                 TTY.println("not inlining %s because no monomorphic receiver could be found", methodName(invoke.target, invoke));
             }
-            return false;
+            return null;
         }
     }