15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.phases.common;
26
27 import static org.graalvm.compiler.graph.Graph.NodeEvent.NODE_ADDED;
28
29 import org.graalvm.compiler.core.common.RetryableBailoutException;
30 import org.graalvm.compiler.graph.Graph.NodeEventScope;
31 import org.graalvm.compiler.graph.Node;
32 import org.graalvm.compiler.graph.spi.Simplifiable;
33 import org.graalvm.compiler.nodes.StructuredGraph;
34 import org.graalvm.compiler.phases.BasePhase;
35 import org.graalvm.compiler.phases.common.util.HashSetNodeEventListener;
36 import org.graalvm.compiler.phases.tiers.PhaseContext;
37
38 public class IterativeConditionalEliminationPhase extends BasePhase<PhaseContext> {
39
40 private static final int MAX_ITERATIONS = 256;
41
42 private final CanonicalizerPhase canonicalizer;
43 private final boolean fullSchedule;
44
45 public IterativeConditionalEliminationPhase(CanonicalizerPhase canonicalizer, boolean fullSchedule) {
46 this.canonicalizer = canonicalizer;
47 this.fullSchedule = fullSchedule;
48 }
49
50 @Override
51 @SuppressWarnings("try")
52 protected void run(StructuredGraph graph, PhaseContext context) {
53 HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NODE_ADDED);
54 int count = 0;
55 while (true) {
56 try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
57 new ConditionalEliminationPhase(fullSchedule).apply(graph, context);
58 }
59 if (listener.getNodes().isEmpty()) {
60 break;
61 }
62 for (Node node : graph.getNodes()) {
63 if (node instanceof Simplifiable) {
64 listener.getNodes().add(node);
65 }
66 }
67 canonicalizer.applyIncremental(graph, context, listener.getNodes());
68 listener.getNodes().clear();
69 if (++count > MAX_ITERATIONS) {
70 throw new RetryableBailoutException("Number of iterations in ConditionalEliminationPhase phase exceeds %d", MAX_ITERATIONS);
71 }
72 }
73 }
|
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.phases.common;
26
27 import static org.graalvm.compiler.graph.Graph.NodeEvent.NODE_ADDED;
28
29 import org.graalvm.compiler.core.common.RetryableBailoutException;
30 import org.graalvm.compiler.graph.Graph.NodeEventScope;
31 import org.graalvm.compiler.graph.Node;
32 import org.graalvm.compiler.graph.spi.Simplifiable;
33 import org.graalvm.compiler.nodes.StructuredGraph;
34 import org.graalvm.compiler.phases.BasePhase;
35 import org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener;
36 import org.graalvm.compiler.phases.tiers.PhaseContext;
37
38 public class IterativeConditionalEliminationPhase extends BasePhase<PhaseContext> {
39
40 private static final int MAX_ITERATIONS = 256;
41
42 private final CanonicalizerPhase canonicalizer;
43 private final boolean fullSchedule;
44
45 public IterativeConditionalEliminationPhase(CanonicalizerPhase canonicalizer, boolean fullSchedule) {
46 this.canonicalizer = canonicalizer;
47 this.fullSchedule = fullSchedule;
48 }
49
50 @Override
51 @SuppressWarnings("try")
52 protected void run(StructuredGraph graph, PhaseContext context) {
53 EconomicSetNodeEventListener listener = new EconomicSetNodeEventListener().exclude(NODE_ADDED);
54 int count = 0;
55 while (true) {
56 try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
57 new ConditionalEliminationPhase(fullSchedule).apply(graph, context);
58 }
59 if (listener.getNodes().isEmpty()) {
60 break;
61 }
62 for (Node node : graph.getNodes()) {
63 if (node instanceof Simplifiable) {
64 listener.getNodes().add(node);
65 }
66 }
67 canonicalizer.applyIncremental(graph, context, listener.getNodes());
68 listener.getNodes().clear();
69 if (++count > MAX_ITERATIONS) {
70 throw new RetryableBailoutException("Number of iterations in ConditionalEliminationPhase phase exceeds %d", MAX_ITERATIONS);
71 }
72 }
73 }
|