43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.nodes;
|
|
24 |
|
47798
|
25 |
import java.util.Map;
|
|
26 |
|
43972
|
27 |
import org.graalvm.compiler.core.common.type.Stamp;
|
|
28 |
import org.graalvm.compiler.core.common.type.StampFactory;
|
|
29 |
import org.graalvm.compiler.graph.NodeClass;
|
|
30 |
import org.graalvm.compiler.graph.NodeInputList;
|
|
31 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
32 |
import org.graalvm.compiler.nodes.type.StampTool;
|
46344
|
33 |
import org.graalvm.util.CollectionsUtil;
|
43972
|
34 |
|
|
35 |
/**
|
|
36 |
* Value {@link PhiNode}s merge data flow values at control flow merges.
|
|
37 |
*/
|
47798
|
38 |
@NodeInfo(nameTemplate = "Phi({i#values}, {p#valueDescription})")
|
50330
|
39 |
public class ValuePhiNode extends PhiNode {
|
43972
|
40 |
|
|
41 |
public static final NodeClass<ValuePhiNode> TYPE = NodeClass.create(ValuePhiNode.class);
|
|
42 |
@Input protected NodeInputList<ValueNode> values;
|
|
43 |
|
|
44 |
public ValuePhiNode(Stamp stamp, AbstractMergeNode merge) {
|
|
45 |
this(TYPE, stamp, merge);
|
|
46 |
}
|
|
47 |
|
|
48 |
protected ValuePhiNode(NodeClass<? extends ValuePhiNode> c, Stamp stamp, AbstractMergeNode merge) {
|
|
49 |
super(c, stamp, merge);
|
|
50 |
assert stamp != StampFactory.forVoid();
|
|
51 |
values = new NodeInputList<>(this);
|
|
52 |
}
|
|
53 |
|
|
54 |
public ValuePhiNode(Stamp stamp, AbstractMergeNode merge, ValueNode[] values) {
|
|
55 |
super(TYPE, stamp, merge);
|
|
56 |
assert stamp != StampFactory.forVoid();
|
|
57 |
this.values = new NodeInputList<>(this, values);
|
|
58 |
}
|
|
59 |
|
|
60 |
@Override
|
|
61 |
public NodeInputList<ValueNode> values() {
|
|
62 |
return values;
|
|
63 |
}
|
|
64 |
|
|
65 |
@Override
|
|
66 |
public boolean inferStamp() {
|
|
67 |
/*
|
|
68 |
* Meet all the values feeding this Phi but don't use the stamp of this Phi since that's
|
|
69 |
* what's being computed.
|
|
70 |
*/
|
|
71 |
Stamp valuesStamp = StampTool.meetOrNull(values(), this);
|
|
72 |
if (valuesStamp == null) {
|
|
73 |
valuesStamp = stamp;
|
|
74 |
} else if (stamp.isCompatible(valuesStamp)) {
|
|
75 |
valuesStamp = stamp.join(valuesStamp);
|
|
76 |
}
|
|
77 |
return updateStamp(valuesStamp);
|
|
78 |
}
|
|
79 |
|
|
80 |
@Override
|
|
81 |
public boolean verify() {
|
|
82 |
Stamp s = null;
|
|
83 |
for (ValueNode input : values()) {
|
46344
|
84 |
assert input != null;
|
43972
|
85 |
if (s == null) {
|
48190
|
86 |
s = input.stamp(NodeView.DEFAULT);
|
43972
|
87 |
} else {
|
48190
|
88 |
if (!s.isCompatible(input.stamp(NodeView.DEFAULT))) {
|
46344
|
89 |
fail("Phi Input Stamps are not compatible. Phi:%s inputs:%s", this,
|
48190
|
90 |
CollectionsUtil.mapAndJoin(values(), x -> x.toString() + ":" + x.stamp(NodeView.DEFAULT), ", "));
|
43972
|
91 |
}
|
|
92 |
}
|
|
93 |
}
|
|
94 |
return super.verify();
|
|
95 |
}
|
47798
|
96 |
|
|
97 |
@Override
|
|
98 |
protected String valueDescription() {
|
48190
|
99 |
return stamp(NodeView.DEFAULT).unrestricted().toString();
|
47798
|
100 |
}
|
|
101 |
|
|
102 |
@Override
|
|
103 |
public Map<Object, Object> getDebugProperties(Map<Object, Object> map) {
|
|
104 |
Map<Object, Object> properties = super.getDebugProperties(map);
|
|
105 |
properties.put("valueDescription", valueDescription());
|
|
106 |
return properties;
|
|
107 |
}
|
43972
|
108 |
}
|