annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Phi.java @ 3227:8793d44991fd

Added Verify option to be able to diable graph verification, ideal graph printing now also print string value for colors, removed redundant DCE/Canon phases
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Wed, 20 Jul 2011 18:49:19 +0200
parents cb6e4d82ef3a
children d95db56f8deb a64b615ba630
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
1 /*
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
2874
d90bf514d647 Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2872
diff changeset
23 package com.oracle.max.graal.compiler.ir;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
24
3081
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
25 import java.util.*;
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
26
2874
d90bf514d647 Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2872
diff changeset
27 import com.oracle.max.graal.compiler.debug.*;
3081
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
28 import com.oracle.max.graal.compiler.ir.StateSplit.*;
3180
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
29 import com.oracle.max.graal.compiler.phases.CanonicalizerPhase.*;
2874
d90bf514d647 Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2872
diff changeset
30 import com.oracle.max.graal.graph.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
31 import com.sun.cri.ci.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
32
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
33 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
34 * The {@code Phi} instruction represents the merging of dataflow
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
35 * in the instruction graph. It refers to a join block and a variable.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
36 */
2945
41318fcb6b56 Added two algorithms for identifying Java-level blocks.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2913
diff changeset
37 public final class Phi extends FloatingNode {
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
38
2769
dd6419f4bfe2 Fixed several issues with incorrect predecessor count/order. One known issue around exception dispatch remaining in fop.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2768
diff changeset
39 private static final int DEFAULT_MAX_VALUES = 2;
2764
99912abb3ff7 Phi clean up. Phis no longer save their local/stack index.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2763
diff changeset
40
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
41 private static final int INPUT_COUNT = 1;
2913
81dab15b45e5 fixes to Phi.removeInput and DCE
Lukas Stadler <lukas.stadler@jku.at>
parents: 2874
diff changeset
42 private static final int INPUT_MERGE = 0;
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
43
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
44 private static final int SUCCESSOR_COUNT = 0;
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
45
3164
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
46 private final PhiType type;
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
47
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
48 @Override
2827
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2821
diff changeset
49 protected int inputCount() {
2961
0966a5a904ad Created variable part in NodeArray.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
50 return super.inputCount() + INPUT_COUNT;
2827
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2821
diff changeset
51 }
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2821
diff changeset
52
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2821
diff changeset
53 @Override
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
54 protected int successorCount() {
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
55 return super.successorCount() + SUCCESSOR_COUNT;
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
56 }
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
57
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
58 /**
2913
81dab15b45e5 fixes to Phi.removeInput and DCE
Lukas Stadler <lukas.stadler@jku.at>
parents: 2874
diff changeset
59 * The merge node for this phi.
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
60 */
2913
81dab15b45e5 fixes to Phi.removeInput and DCE
Lukas Stadler <lukas.stadler@jku.at>
parents: 2874
diff changeset
61 public Merge merge() {
81dab15b45e5 fixes to Phi.removeInput and DCE
Lukas Stadler <lukas.stadler@jku.at>
parents: 2874
diff changeset
62 return (Merge) inputs().get(super.inputCount() + INPUT_MERGE);
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
63 }
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
64
3050
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3016 3046
diff changeset
65 public void setMerge(Merge n) {
3081
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
66 assert n != null;
2961
0966a5a904ad Created variable part in NodeArray.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
67 inputs().set(super.inputCount() + INPUT_MERGE, n);
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
68 }
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2582
diff changeset
69
3164
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
70 public static enum PhiType {
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
71 Value, // normal value phis
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
72 Memory, // memory phis
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
73 Virtual // phis used for VirtualObjectField merges
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
74 }
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
75
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
76 public Phi(CiKind kind, Merge merge, PhiType type, Graph graph) {
2961
0966a5a904ad Created variable part in NodeArray.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
77 super(kind, INPUT_COUNT, SUCCESSOR_COUNT, graph);
3164
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
78 this.type = type;
2913
81dab15b45e5 fixes to Phi.removeInput and DCE
Lukas Stadler <lukas.stadler@jku.at>
parents: 2874
diff changeset
79 setMerge(merge);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
80 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
81
3164
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
82 private Phi(CiKind kind, PhiType type, Graph graph) {
3046
f9e045cd2c23 Merge, add some edge spliting around loopbegin when necessary
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3044
diff changeset
83 super(kind, INPUT_COUNT, SUCCESSOR_COUNT, graph);
3164
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
84 this.type = type;
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
85 }
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
86
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
87 public PhiType type() {
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
88 return type;
3046
f9e045cd2c23 Merge, add some edge spliting around loopbegin when necessary
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3044
diff changeset
89 }
f9e045cd2c23 Merge, add some edge spliting around loopbegin when necessary
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3044
diff changeset
90
3016
2f5f6ffbafa0 Fixed a bug in the dead code eliminator when removing inputs from dead phis.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2984
diff changeset
91 @Override
2f5f6ffbafa0 Fixed a bug in the dead code eliminator when removing inputs from dead phis.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2984
diff changeset
92 public boolean verify() {
2f5f6ffbafa0 Fixed a bug in the dead code eliminator when removing inputs from dead phis.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2984
diff changeset
93 assertTrue(merge() != null);
3164
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
94 assertTrue(merge().phiPredecessorCount() == valueCount(), merge().phiPredecessorCount() + "==" + valueCount());
3016
2f5f6ffbafa0 Fixed a bug in the dead code eliminator when removing inputs from dead phis.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2984
diff changeset
95 return true;
2f5f6ffbafa0 Fixed a bug in the dead code eliminator when removing inputs from dead phis.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2984
diff changeset
96 }
2f5f6ffbafa0 Fixed a bug in the dead code eliminator when removing inputs from dead phis.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2984
diff changeset
97
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
98 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
99 * Get the instruction that produces the value associated with the i'th predecessor
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
100 * of the join block.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
101 * @param i the index of the predecessor
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
102 * @return the instruction that produced the value in the i'th predecessor
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
103 */
2764
99912abb3ff7 Phi clean up. Phis no longer save their local/stack index.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2763
diff changeset
104 public Value valueAt(int i) {
3179
b9439feeec65 NodeArray uses modCount to assert in Iterators, variableInputs is now protected so that each Node class using it needs to export it explicitly (and thus give it a name)
Lukas Stadler <lukas.stadler@jku.at>
parents: 3164
diff changeset
105 return (Value) variableInputs().get(i);
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
106 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
107
2963
fc66984c2f31 Added declaration of EndNode.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2962
diff changeset
108 public void setValueAt(int i, Value x) {
fc66984c2f31 Added declaration of EndNode.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2962
diff changeset
109 inputs().set(INPUT_COUNT + i, x);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
110 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
111
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
112 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
113 * Get the number of inputs to this phi (i.e. the number of predecessors to the join block).
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
114 * @return the number of inputs in this phi
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
115 */
2764
99912abb3ff7 Phi clean up. Phis no longer save their local/stack index.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2763
diff changeset
116 public int valueCount() {
3179
b9439feeec65 NodeArray uses modCount to assert in Iterators, variableInputs is now protected so that each Node class using it needs to export it explicitly (and thus give it a name)
Lukas Stadler <lukas.stadler@jku.at>
parents: 3164
diff changeset
117 return variableInputs().size();
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
118 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
119
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
120 @Override
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
121 public void accept(ValueVisitor v) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
122 v.visitPhi(this);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
123 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
124
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
125 @Override
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
126 public void print(LogStream out) {
2768
43ffa0e47a46 Towards removing stateAfter on BlockEnd.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2764
diff changeset
127 out.print("phi function (");
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
128 for (int i = 0; i < valueCount(); ++i) {
2768
43ffa0e47a46 Towards removing stateAfter on BlockEnd.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2764
diff changeset
129 if (i != 0) {
43ffa0e47a46 Towards removing stateAfter on BlockEnd.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2764
diff changeset
130 out.print(' ');
43ffa0e47a46 Towards removing stateAfter on BlockEnd.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2764
diff changeset
131 }
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
132 out.print(valueAt(i));
2768
43ffa0e47a46 Towards removing stateAfter on BlockEnd.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2764
diff changeset
133 }
43ffa0e47a46 Towards removing stateAfter on BlockEnd.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2764
diff changeset
134 out.print(')');
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
135 }
2616
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2603
diff changeset
136
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2603
diff changeset
137 @Override
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2603
diff changeset
138 public String shortName() {
2799
e1dad0edd57a first part of loop reworking
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
139 StringBuilder str = new StringBuilder();
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
140 for (int i = 0; i < valueCount(); ++i) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
141 if (i != 0) {
2799
e1dad0edd57a first part of loop reworking
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
142 str.append(' ');
e1dad0edd57a first part of loop reworking
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
143 }
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
144 str.append(valueAt(i) == null ? "-" : valueAt(i).id());
2799
e1dad0edd57a first part of loop reworking
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
145 }
3164
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
146 if (type == PhiType.Value) {
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
147 return "Phi: (" + str + ")";
3098
2fb14099d069 fix for unresolved exception bug, exactType and declaredType logic for inlining, more on escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents: 3081
diff changeset
148 } else {
3164
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
149 return type + "Phi: (" + str + ")";
3098
2fb14099d069 fix for unresolved exception bug, exactType and declaredType logic for inlining, more on escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents: 3081
diff changeset
150 }
2616
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2603
diff changeset
151 }
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2603
diff changeset
152
2962
ef7ceaf48b6f Phi addInput clean up.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2961
diff changeset
153 public void addInput(Node y) {
3179
b9439feeec65 NodeArray uses modCount to assert in Iterators, variableInputs is now protected so that each Node class using it needs to export it explicitly (and thus give it a name)
Lukas Stadler <lukas.stadler@jku.at>
parents: 3164
diff changeset
154 variableInputs().add(y);
2763
5e8a69041cd7 Model phi inputs as direct inputs in the graph instead of referring to the framestates of the predecessors.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2707
diff changeset
155 }
2769
dd6419f4bfe2 Fixed several issues with incorrect predecessor count/order. One known issue around exception dispatch remaining in fop.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2768
diff changeset
156
dd6419f4bfe2 Fixed several issues with incorrect predecessor count/order. One known issue around exception dispatch remaining in fop.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2768
diff changeset
157 public void removeInput(int index) {
3179
b9439feeec65 NodeArray uses modCount to assert in Iterators, variableInputs is now protected so that each Node class using it needs to export it explicitly (and thus give it a name)
Lukas Stadler <lukas.stadler@jku.at>
parents: 3164
diff changeset
158 variableInputs().remove(index);
2769
dd6419f4bfe2 Fixed several issues with incorrect predecessor count/order. One known issue around exception dispatch remaining in fop.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2768
diff changeset
159 }
2827
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2821
diff changeset
160
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2821
diff changeset
161 @Override
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2821
diff changeset
162 public Node copy(Graph into) {
3164
2b1eace223b0 added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
Lukas Stadler <lukas.stadler@jku.at>
parents: 3163
diff changeset
163 Phi x = new Phi(kind, type, into);
2827
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2821
diff changeset
164 return x;
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2821
diff changeset
165 }
3081
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
166
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
167 @Override
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
168 public Iterable<? extends Node> dataInputs() {
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
169 final Iterator< ? extends Node> input = super.dataInputs().iterator();
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
170 return new Iterable<Node>() {
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
171 @Override
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
172 public Iterator<Node> iterator() {
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
173 return new FilteringIterator(input, Merge.class);
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
174 }
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
175 };
0a5776813ff0 Loop peeling work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 3050
diff changeset
176 }
3180
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
177
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
178
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
179 @SuppressWarnings("unchecked")
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
180 @Override
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
181 public <T extends Op> T lookup(Class<T> clazz) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
182 if (clazz == CanonicalizerOp.class) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
183 return (T) CANONICALIZER;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
184 }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
185 return super.lookup(clazz);
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
186 }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
187
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
188 private static CanonicalizerOp CANONICALIZER = new CanonicalizerOp() {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
189
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
190 @Override
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
191 public Node canonical(Node node) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
192 Phi phiNode = (Phi) node;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
193 // if (phiNode.valueCount() != 2 || phiNode.merge().endCount() != 2 || phiNode.merge().phis().size() != 1) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
194 // return phiNode;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
195 // }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
196 // if (!(phiNode.valueAt(0) instanceof Constant && phiNode.valueAt(1) instanceof Constant)) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
197 // return phiNode;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
198 // }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
199 // Merge merge = phiNode.merge();
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
200 // Node end0 = merge.endAt(0);
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
201 // Node end1 = merge.endAt(1);
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
202 // if (end0.predecessors().size() != 1 || end1.predecessors().size() != 1) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
203 // return phiNode;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
204 // }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
205 // Node endPred0 = end0.predecessors().get(0);
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
206 // Node endPred1 = end1.predecessors().get(0);
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
207 // if (endPred0 != endPred1 || !(endPred0 instanceof If)) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
208 // return phiNode;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
209 // }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
210 // If ifNode = (If) endPred0;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
211 // if (ifNode.predecessors().size() != 1) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
212 // return phiNode;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
213 // }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
214 // boolean inverted = ((If) endPred0).trueSuccessor() == end1;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
215 // CiConstant trueValue = phiNode.valueAt(inverted ? 1 : 0).asConstant();
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
216 // CiConstant falseValue = phiNode.valueAt(inverted ? 0 : 1).asConstant();
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
217 // if (trueValue.kind != CiKind.Int || falseValue.kind != CiKind.Int) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
218 // return phiNode;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
219 // }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
220 // if ((trueValue.asInt() == 0 || trueValue.asInt() == 1) && (falseValue.asInt() == 0 || falseValue.asInt() == 1) && (trueValue.asInt() != falseValue.asInt())) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
221 // MaterializeNode result;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
222 // if (trueValue.asInt() == 1) {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
223 // result = new MaterializeNode(ifNode.compare(), phiNode.graph());
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
224 // } else {
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
225 // result = new MaterializeNode(new NegateBooleanNode(ifNode.compare(), phiNode.graph()), phiNode.graph());
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
226 // }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
227 // Node next = merge.next();
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
228 // merge.setNext(null);
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
229 // ifNode.predecessors().get(0).successors().replace(ifNode, next);
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
230 // return result;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
231 // }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
232 return phiNode;
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
233 }
cb6e4d82ef3a canonicalize "if (x) return bool_constant; else return !bool_constant;" to MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 3179
diff changeset
234 };
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
235 }