annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java @ 11881:da9db8331658

moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
author Doug Simon <doug.simon@oracle.com>
date Tue, 01 Oct 2013 20:38:25 +0200
parents 50577f991923
children 23ccaa863eda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
1 /*
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
4 *
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
8 *
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
14 *
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
18 *
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
21 * questions.
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
22 */
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
23 package com.oracle.graal.phases.common;
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
24
11304
74ccfb4d39ec Bailout of iterative conditional elimination phase in case the number of iterations exceeds specific threshold.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10009
diff changeset
25 import com.oracle.graal.api.code.*;
5864
59f209dd356b Be more precise on the set of node that are canonicalized in IterativeCheckCastElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5860
diff changeset
26 import com.oracle.graal.graph.*;
11881
da9db8331658 moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11574
diff changeset
27 import com.oracle.graal.graph.spi.*;
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
28 import com.oracle.graal.nodes.*;
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
29 import com.oracle.graal.phases.*;
11437
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
30 import com.oracle.graal.phases.common.util.*;
9136
2cfdde003076 Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9049
diff changeset
31 import com.oracle.graal.phases.tiers.*;
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
32
9136
2cfdde003076 Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9049
diff changeset
33 public class IterativeConditionalEliminationPhase extends BasePhase<PhaseContext> {
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
34
11304
74ccfb4d39ec Bailout of iterative conditional elimination phase in case the number of iterations exceeds specific threshold.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10009
diff changeset
35 private static final int MAX_ITERATIONS = 256;
74ccfb4d39ec Bailout of iterative conditional elimination phase in case the number of iterations exceeds specific threshold.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10009
diff changeset
36
11574
50577f991923 Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents: 11437
diff changeset
37 private final CanonicalizerPhase canonicalizer;
50577f991923 Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents: 11437
diff changeset
38
50577f991923 Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents: 11437
diff changeset
39 public IterativeConditionalEliminationPhase(CanonicalizerPhase canonicalizer) {
50577f991923 Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents: 11437
diff changeset
40 this.canonicalizer = canonicalizer;
50577f991923 Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents: 11437
diff changeset
41 }
50577f991923 Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents: 11437
diff changeset
42
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
43 @Override
9136
2cfdde003076 Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9049
diff changeset
44 protected void run(StructuredGraph graph, PhaseContext context) {
2cfdde003076 Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9049
diff changeset
45 ConditionalEliminationPhase eliminate = new ConditionalEliminationPhase(context.getRuntime());
11437
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
46 HashSetNodeChangeListener listener = new HashSetNodeChangeListener();
11304
74ccfb4d39ec Bailout of iterative conditional elimination phase in case the number of iterations exceeds specific threshold.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10009
diff changeset
47 int count = 0;
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
48 while (true) {
5864
59f209dd356b Be more precise on the set of node that are canonicalized in IterativeCheckCastElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5860
diff changeset
49 graph.trackInputChange(listener);
11437
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
50 graph.trackUsagesDroppedZero(listener);
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
51 eliminate.apply(graph);
5864
59f209dd356b Be more precise on the set of node that are canonicalized in IterativeCheckCastElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5860
diff changeset
52 graph.stopTrackingInputChange();
11437
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
53 graph.stopTrackingUsagesDroppedZero();
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
54 if (listener.getChangedNodes().isEmpty()) {
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
55 break;
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
56 }
11437
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
57 for (Node node : graph.getNodes()) {
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
58 if (node instanceof Simplifiable) {
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
59 listener.getChangedNodes().add(node);
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
60 }
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
61 }
11574
50577f991923 Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents: 11437
diff changeset
62 canonicalizer.applyIncremental(graph, context, listener.getChangedNodes());
11437
58b72cc17109 incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 11304
diff changeset
63 listener.getChangedNodes().clear();
11304
74ccfb4d39ec Bailout of iterative conditional elimination phase in case the number of iterations exceeds specific threshold.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10009
diff changeset
64 if (++count > MAX_ITERATIONS) {
74ccfb4d39ec Bailout of iterative conditional elimination phase in case the number of iterations exceeds specific threshold.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10009
diff changeset
65 throw new BailoutException("Number of iterations in conditional elimination phase exceeds " + MAX_ITERATIONS);
74ccfb4d39ec Bailout of iterative conditional elimination phase in case the number of iterations exceeds specific threshold.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10009
diff changeset
66 }
5859
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
67 }
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
68 }
16c3284c94cd Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
69 }