43972
|
1 |
/*
|
52910
|
2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.nodes;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_0;
|
|
28 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_0;
|
|
29 |
|
|
30 |
import org.graalvm.compiler.graph.Node;
|
|
31 |
import org.graalvm.compiler.graph.NodeClass;
|
|
32 |
import org.graalvm.compiler.graph.spi.Canonicalizable;
|
|
33 |
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
|
|
34 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
35 |
import org.graalvm.compiler.nodes.extended.GuardingNode;
|
|
36 |
import org.graalvm.compiler.nodes.spi.LIRLowerable;
|
|
37 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
|
38 |
import org.graalvm.compiler.nodes.spi.ValueProxy;
|
|
39 |
import org.graalvm.compiler.nodes.spi.Virtualizable;
|
|
40 |
import org.graalvm.compiler.nodes.spi.VirtualizerTool;
|
|
41 |
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
|
|
42 |
|
|
43 |
import jdk.vm.ci.meta.JavaKind;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* A node that changes the type of its input, usually narrowing it. For example, a GuardedValueNode
|
|
47 |
* is used to keep the nodes depending on guards inside a loop during speculative guard movement.
|
|
48 |
*
|
|
49 |
* A GuardedValueNode will only go away if its guard is null or {@link StructuredGraph#start()}.
|
|
50 |
*/
|
|
51 |
@NodeInfo(cycles = CYCLES_0, size = SIZE_0)
|
46344
|
52 |
public final class GuardedValueNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, Canonicalizable, ValueProxy {
|
43972
|
53 |
|
|
54 |
public static final NodeClass<GuardedValueNode> TYPE = NodeClass.create(GuardedValueNode.class);
|
|
55 |
@Input ValueNode object;
|
|
56 |
|
|
57 |
public GuardedValueNode(ValueNode object, GuardingNode guard) {
|
48190
|
58 |
super(TYPE, object.stamp(NodeView.DEFAULT), guard);
|
46344
|
59 |
this.object = object;
|
43972
|
60 |
}
|
|
61 |
|
|
62 |
public ValueNode object() {
|
|
63 |
return object;
|
|
64 |
}
|
|
65 |
|
|
66 |
@Override
|
|
67 |
public void generate(NodeLIRBuilderTool generator) {
|
|
68 |
if (object.getStackKind() != JavaKind.Void && object.getStackKind() != JavaKind.Illegal) {
|
|
69 |
generator.setResult(this, generator.operand(object));
|
|
70 |
}
|
|
71 |
}
|
|
72 |
|
|
73 |
@Override
|
|
74 |
public boolean inferStamp() {
|
48190
|
75 |
return updateStamp(object().stamp(NodeView.DEFAULT));
|
43972
|
76 |
}
|
|
77 |
|
|
78 |
@Override
|
|
79 |
public void virtualize(VirtualizerTool tool) {
|
|
80 |
ValueNode alias = tool.getAlias(object());
|
|
81 |
if (alias instanceof VirtualObjectNode) {
|
|
82 |
tool.replaceWithVirtual((VirtualObjectNode) alias);
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
@Override
|
|
87 |
public Node canonical(CanonicalizerTool tool) {
|
|
88 |
if (getGuard() == null) {
|
48190
|
89 |
if (stamp(NodeView.DEFAULT).equals(object().stamp(NodeView.DEFAULT))) {
|
43972
|
90 |
return object();
|
|
91 |
} else {
|
48190
|
92 |
return PiNode.create(object(), stamp(NodeView.DEFAULT));
|
43972
|
93 |
}
|
|
94 |
}
|
|
95 |
return this;
|
|
96 |
}
|
|
97 |
|
|
98 |
@Override
|
|
99 |
public ValueNode getOriginalNode() {
|
|
100 |
return object;
|
|
101 |
}
|
|
102 |
}
|