# HG changeset patch # User Lukas Stadler # Date 1309371073 -7200 # Node ID c49c893c3d27938961d0cfda26a4e6ef9bc32721 # Parent 28484c5f00d70dbfdbeac8b7f67b41859c863ff1 small inlining simplification diff -r 28484c5f00d7 -r c49c893c3d27 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java --- 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 invokes = new ArrayDeque(); - private final Queue methods = new ArrayDeque(); - private int inliningSize; private final Collection 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 newInvokes = new ArrayDeque(); private Graph graph; @@ -85,37 +76,36 @@ newInvokes = new ArrayDeque(); 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; } }