Mercurial > hg > truffle
annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java @ 17341:e3f3233ec6cd
refactor BailoutException to include information about non-permanent errors
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Mon, 06 Oct 2014 09:39:42 +0200 |
parents | d9de8f5197e1 |
children | 0f4813e0b4a9 |
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 |
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
|
25 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
|
26 |
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
|
27 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
|
28 import com.oracle.graal.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
|
29 import com.oracle.graal.graph.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; |
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 public IterativeConditionalEliminationPhase(CanonicalizerPhase canonicalizer) { |
50577f991923
Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11437
diff
changeset
|
43 this.canonicalizer = canonicalizer; |
50577f991923
Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11437
diff
changeset
|
44 } |
50577f991923
Pass canonicalizer into IterativeConditionalEliminationPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11437
diff
changeset
|
45 |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
46 @Override |
9136
2cfdde003076
Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
47 protected void run(StructuredGraph graph, PhaseContext context) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11881
diff
changeset
|
48 ConditionalEliminationPhase eliminate = new ConditionalEliminationPhase(context.getMetaAccess()); |
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
|
49 HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NODE_ADDED); |
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
|
50 int count = 0; |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
51 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
|
52 try (NodeEventScope nes = graph.trackNodeEvents(listener)) { |
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 eliminate.apply(graph); |
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
|
54 } |
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 if (listener.getNodes().isEmpty()) { |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
56 break; |
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
57 } |
11437
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
11304
diff
changeset
|
58 for (Node node : graph.getNodes()) { |
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
11304
diff
changeset
|
59 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
|
60 listener.getNodes().add(node); |
11437
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
11304
diff
changeset
|
61 } |
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
11304
diff
changeset
|
62 } |
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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 } |
5859
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 } |
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
70 } |