Mercurial > hg > truffle
annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java @ 10723:097a634b57b1
fix stamps for constants of boolean, byte, char and short type, add tests
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 12 Jul 2013 11:19:36 +0200 |
parents | b5c87b5c6e9c |
children | 74ccfb4d39ec |
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 |
9966
4158612eca60
GraalOptions: use static import
Bernhard Urban <bernhard.urban@jku.at>
parents:
9908
diff
changeset
|
25 import static com.oracle.graal.phases.GraalOptions.*; |
4158612eca60
GraalOptions: use static import
Bernhard Urban <bernhard.urban@jku.at>
parents:
9908
diff
changeset
|
26 |
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
|
27 import java.util.*; |
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 |
9331
199c77760850
Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9136
diff
changeset
|
29 import com.oracle.graal.graph.Graph.NodeChangedListener; |
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
|
30 import com.oracle.graal.graph.*; |
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.*; |
9136
2cfdde003076
Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
33 import com.oracle.graal.phases.tiers.*; |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
34 |
9136
2cfdde003076
Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
35 public class IterativeConditionalEliminationPhase extends BasePhase<PhaseContext> { |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
36 |
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
37 @Override |
9136
2cfdde003076
Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
38 protected void run(StructuredGraph graph, PhaseContext context) { |
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
|
39 Set<Node> canonicalizationRoots = new HashSet<>(); |
9136
2cfdde003076
Make IterativeConditionalEliminationPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
40 ConditionalEliminationPhase eliminate = new ConditionalEliminationPhase(context.getRuntime()); |
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
|
41 Listener listener = new Listener(canonicalizationRoots); |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
42 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
|
43 graph.trackInputChange(listener); |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
44 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
|
45 graph.stopTrackingInputChange(); |
59f209dd356b
Be more precise on the set of node that are canonicalized in IterativeCheckCastElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5860
diff
changeset
|
46 if (canonicalizationRoots.isEmpty()) { |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
47 break; |
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
48 } |
10009
b5c87b5c6e9c
add option to enable ahead of time compilation for hotspot (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents:
9966
diff
changeset
|
49 new CanonicalizerPhase.Instance(context.getRuntime(), context.getAssumptions(), !AOTCompilation.getValue(), canonicalizationRoots, null).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
|
50 canonicalizationRoots.clear(); |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
51 } |
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
52 } |
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
53 |
9331
199c77760850
Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9136
diff
changeset
|
54 private static class Listener implements NodeChangedListener { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7307
diff
changeset
|
55 |
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
|
56 private final Set<Node> canonicalizationRoots; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7307
diff
changeset
|
57 |
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
|
58 public Listener(Set<Node> canonicalizationRoots) { |
59f209dd356b
Be more precise on the set of node that are canonicalized in IterativeCheckCastElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5860
diff
changeset
|
59 this.canonicalizationRoots = canonicalizationRoots; |
59f209dd356b
Be more precise on the set of node that are canonicalized in IterativeCheckCastElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5860
diff
changeset
|
60 } |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7307
diff
changeset
|
61 |
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
|
62 @Override |
9331
199c77760850
Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9136
diff
changeset
|
63 public void nodeChanged(Node node) { |
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
|
64 canonicalizationRoots.add(node); |
59f209dd356b
Be more precise on the set of node that are canonicalized in IterativeCheckCastElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5860
diff
changeset
|
65 } |
59f209dd356b
Be more precise on the set of node that are canonicalized in IterativeCheckCastElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5860
diff
changeset
|
66 } |
5859
16c3284c94cd
Try an iterative version of CheckCastElimination + Canonicalization
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
67 } |