# HG changeset patch # User Gilles Duboscq # Date 1415795747 -3600 # Node ID 05fde207f06ca92fcc424a5d0e8942abf4d3b7ce # Parent 1cd104505b611d9adf75a68f5c0b0eb4d900df9d ConditionalEliminaion: some refactorings and simplifications diff -r 1cd104505b61 -r 05fde207f06c graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Wed Nov 12 10:53:37 2014 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Wed Nov 12 13:35:47 2014 +0100 @@ -470,27 +470,9 @@ return null; } - private boolean eliminateTrivialGuard(GuardNode guard) { - LogicNode condition = guard.condition(); - - if (testExistingGuard(guard)) { + private boolean eliminateTrivialGuardOrRegisterStamp(GuardNode guard) { + if (tryReplaceWithExistingGuard(guard)) { return true; - } else { - GuardingNode anchor = state.trueConditions.get(condition); - if (anchor != null) { - if (!guard.negated()) { - eliminateGuard(guard, anchor); - return true; - } - } else { - anchor = state.falseConditions.get(condition); - if (anchor != null) { - if (guard.negated()) { - eliminateGuard(guard, anchor); - return true; - } - } - } } // Can't be eliminated so accumulate any type information from the guard registerConditionalStamp(guard); @@ -573,7 +555,7 @@ return false; } - private boolean testExistingGuard(GuardNode guard) { + private boolean tryReplaceWithExistingGuard(GuardNode guard) { GuardingNode existingGuard = guard.negated() ? state.falseConditions.get(guard.condition()) : state.trueConditions.get(guard.condition()); if (existingGuard != null && existingGuard != guard) { eliminateGuard(guard, existingGuard); @@ -672,20 +654,22 @@ // First eliminate any guards which can be trivially removed and register any // type constraints the guards produce. for (GuardNode guard : begin.guards().snapshot()) { - eliminateTrivialGuard(guard); + eliminateTrivialGuardOrRegisterStamp(guard); } // Collect the guards which have produced conditional stamps. + // XXX (gd) IdentityHashMap.values().contains performs a linear search + // so we prefer to build a set Set provers = Node.newSet(); - for (Map.Entry e : state.valueConstraints.entrySet()) { - provers.add(e.getValue().getGuard()); + for (GuardedStamp e : state.valueConstraints.values()) { + provers.add(e.getGuard()); } // Process the remaining guards. Guards which produced some type constraint should // just be registered since they aren't trivially deleteable. Test the other guards // to see if they can be deleted using type constraints. for (GuardNode guard : begin.guards().snapshot()) { - if (provers.contains(guard) || !(testExistingGuard(guard) || testImpliedGuard(guard))) { + if (provers.contains(guard) || !(tryReplaceWithExistingGuard(guard) || testImpliedGuard(guard))) { registerCondition(!guard.negated(), guard.condition(), guard); } }