Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java @ 21556:48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 27 May 2015 00:36:16 +0200 |
parents | 93c50cefb9e8 |
children | 0e095e2c24e2 |
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 |
21556
48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21543
diff
changeset
|
25 import com.oracle.jvmci.code.BailoutException; |
16295
d9de8f5197e1
simplified NodeEventListener implementations by having all events routed to a single method by default
Doug Simon <doug.simon@oracle.com>
parents:
16241
diff
changeset
|
26 import static com.oracle.graal.graph.Graph.NodeEvent.*; |
d9de8f5197e1
simplified NodeEventListener implementations by having all events routed to a single method by default
Doug Simon <doug.simon@oracle.com>
parents:
16241
diff
changeset
|
27 |
21543
93c50cefb9e8
moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
19721
diff
changeset
|
28 import com.oracle.graal.graph.Graph.NodeEventScope; |
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
|
29 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
|
30 import com.oracle.graal.graph.spi.*; |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
31 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
|
32 import com.oracle.graal.phases.*; |
11437
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
11304
diff
changeset
|
33 import com.oracle.graal.phases.common.util.*; |
9136
2cfdde003076
Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
34 import com.oracle.graal.phases.tiers.*; |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
35 |
9136
2cfdde003076
Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
36 public class IterativeConditionalEliminationPhase extends BasePhase<PhaseContext> { |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
37 |
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
|
38 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
|
39 |
11574
50577f991923
Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11437
diff
changeset
|
40 private final CanonicalizerPhase canonicalizer; |
19721
b503dd4e723c
Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19719
diff
changeset
|
41 private final boolean fullSchedule; |
11574
50577f991923
Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11437
diff
changeset
|
42 |
19721
b503dd4e723c
Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19719
diff
changeset
|
43 public IterativeConditionalEliminationPhase(CanonicalizerPhase canonicalizer, boolean fullSchedule) { |
11574
50577f991923
Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11437
diff
changeset
|
44 this.canonicalizer = canonicalizer; |
19721
b503dd4e723c
Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19719
diff
changeset
|
45 this.fullSchedule = fullSchedule; |
11574
50577f991923
Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11437
diff
changeset
|
46 } |
50577f991923
Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11437
diff
changeset
|
47 |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
48 @Override |
9136
2cfdde003076
Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
49 protected void run(StructuredGraph graph, PhaseContext context) { |
19719
055a095424a7
Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19716
diff
changeset
|
50 HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NODE_ADDED).exclude(ZERO_USAGES); |
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
|
51 int count = 0; |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
52 while (true) { |
16241
c6ebc1997a55
added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents:
15388
diff
changeset
|
53 try (NodeEventScope nes = graph.trackNodeEvents(listener)) { |
19721
b503dd4e723c
Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19719
diff
changeset
|
54 new DominatorConditionalEliminationPhase(fullSchedule).apply(graph); |
16241
c6ebc1997a55
added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents:
15388
diff
changeset
|
55 } |
c6ebc1997a55
added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents:
15388
diff
changeset
|
56 if (listener.getNodes().isEmpty()) { |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
57 break; |
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
58 } |
11437
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
11304
diff
changeset
|
59 for (Node node : graph.getNodes()) { |
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
11304
diff
changeset
|
60 if (node instanceof Simplifiable) { |
16241
c6ebc1997a55
added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents:
15388
diff
changeset
|
61 listener.getNodes().add(node); |
11437
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
11304
diff
changeset
|
62 } |
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
11304
diff
changeset
|
63 } |
16241
c6ebc1997a55
added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents:
15388
diff
changeset
|
64 canonicalizer.applyIncremental(graph, context, listener.getNodes()); |
c6ebc1997a55
added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents:
15388
diff
changeset
|
65 listener.getNodes().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
|
66 if (++count > MAX_ITERATIONS) { |
17341
e3f3233ec6cd
refactor BailoutException to include information about non-permanent errors
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16295
diff
changeset
|
67 throw new BailoutException("Number of iterations in ConditionalEliminationPhase phase exceeds %d", MAX_ITERATIONS); |
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
|
68 } |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
69 } |
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
70 } |
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
71 } |