46344
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, 2016, 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.extended;
|
|
24 |
|
|
25 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_2;
|
|
26 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1;
|
|
27 |
|
|
28 |
import org.graalvm.compiler.core.common.type.PrimitiveStamp;
|
46371
|
29 |
import org.graalvm.compiler.core.common.type.Stamp;
|
46344
|
30 |
import org.graalvm.compiler.core.common.type.StampFactory;
|
|
31 |
import org.graalvm.compiler.graph.Node;
|
|
32 |
import org.graalvm.compiler.graph.NodeClass;
|
47667
|
33 |
import org.graalvm.compiler.graph.spi.Canonicalizable;
|
|
34 |
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
|
46344
|
35 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
47667
|
36 |
import org.graalvm.compiler.nodes.ConstantNode;
|
48190
|
37 |
import org.graalvm.compiler.nodes.NodeView;
|
46344
|
38 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
39 |
import org.graalvm.compiler.nodes.calc.ReinterpretNode;
|
|
40 |
import org.graalvm.compiler.nodes.java.LoadFieldNode;
|
|
41 |
import org.graalvm.compiler.nodes.spi.Lowerable;
|
|
42 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
|
43 |
import org.graalvm.compiler.nodes.spi.Virtualizable;
|
|
44 |
import org.graalvm.compiler.nodes.spi.VirtualizerTool;
|
47667
|
45 |
import org.graalvm.compiler.nodes.type.StampTool;
|
46344
|
46 |
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
|
46551
|
47 |
import org.graalvm.word.LocationIdentity;
|
46344
|
48 |
|
|
49 |
import jdk.vm.ci.meta.Assumptions;
|
47667
|
50 |
import jdk.vm.ci.meta.Constant;
|
|
51 |
import jdk.vm.ci.meta.JavaConstant;
|
46344
|
52 |
import jdk.vm.ci.meta.JavaKind;
|
|
53 |
import jdk.vm.ci.meta.ResolvedJavaField;
|
47667
|
54 |
import jdk.vm.ci.meta.ResolvedJavaType;
|
46344
|
55 |
|
|
56 |
/**
|
|
57 |
* Load of a value from a location specified as an offset relative to an object. No null check is
|
|
58 |
* performed before the load.
|
|
59 |
*/
|
|
60 |
@NodeInfo(cycles = CYCLES_2, size = SIZE_1)
|
47667
|
61 |
public class RawLoadNode extends UnsafeAccessNode implements Lowerable, Virtualizable, Canonicalizable {
|
46344
|
62 |
public static final NodeClass<RawLoadNode> TYPE = NodeClass.create(RawLoadNode.class);
|
|
63 |
|
46371
|
64 |
/**
|
|
65 |
* This constructor exists for node intrinsics that need a stamp based on {@code accessKind}.
|
|
66 |
*/
|
46344
|
67 |
public RawLoadNode(ValueNode object, ValueNode offset, JavaKind accessKind, LocationIdentity locationIdentity) {
|
46536
|
68 |
this(object, offset, accessKind, locationIdentity, false);
|
|
69 |
}
|
|
70 |
|
|
71 |
public RawLoadNode(ValueNode object, ValueNode offset, JavaKind accessKind, LocationIdentity locationIdentity, boolean forceAnyLocation) {
|
|
72 |
super(TYPE, StampFactory.forKind(accessKind.getStackKind()), object, offset, accessKind, locationIdentity, forceAnyLocation);
|
46344
|
73 |
}
|
|
74 |
|
46371
|
75 |
/**
|
|
76 |
* This constructor exists for node intrinsics that need a stamp based on the return type of the
|
|
77 |
* {@link org.graalvm.compiler.graph.Node.NodeIntrinsic} annotated method.
|
|
78 |
*/
|
|
79 |
public RawLoadNode(@InjectedNodeParameter Stamp stamp, ValueNode object, ValueNode offset, LocationIdentity locationIdentity, JavaKind accessKind) {
|
|
80 |
super(TYPE, stamp, object, offset, accessKind, locationIdentity, false);
|
|
81 |
}
|
|
82 |
|
47798
|
83 |
protected RawLoadNode(NodeClass<? extends RawLoadNode> c, ValueNode object, ValueNode offset, JavaKind accessKind, LocationIdentity locationIdentity) {
|
46344
|
84 |
super(c, StampFactory.forKind(accessKind.getStackKind()), object, offset, accessKind, locationIdentity, false);
|
|
85 |
}
|
|
86 |
|
|
87 |
@Override
|
|
88 |
public void lower(LoweringTool tool) {
|
|
89 |
tool.getLowerer().lower(this, tool);
|
|
90 |
}
|
|
91 |
|
|
92 |
@Override
|
|
93 |
public void virtualize(VirtualizerTool tool) {
|
|
94 |
ValueNode alias = tool.getAlias(object());
|
|
95 |
if (alias instanceof VirtualObjectNode) {
|
|
96 |
VirtualObjectNode virtual = (VirtualObjectNode) alias;
|
|
97 |
ValueNode offsetValue = tool.getAlias(offset());
|
|
98 |
if (offsetValue.isConstant()) {
|
|
99 |
long off = offsetValue.asJavaConstant().asLong();
|
48861
|
100 |
int entryIndex = virtual.entryIndexForOffset(tool.getArrayOffsetProvider(), off, accessKind());
|
46344
|
101 |
|
|
102 |
if (entryIndex != -1) {
|
|
103 |
ValueNode entry = tool.getEntry(virtual, entryIndex);
|
|
104 |
JavaKind entryKind = virtual.entryKind(entryIndex);
|
|
105 |
if (entry.getStackKind() == getStackKind() || entryKind == accessKind()) {
|
|
106 |
|
48190
|
107 |
if (!(entry.stamp(NodeView.DEFAULT).isCompatible(stamp(NodeView.DEFAULT)))) {
|
|
108 |
if (entry.stamp(NodeView.DEFAULT) instanceof PrimitiveStamp && stamp instanceof PrimitiveStamp) {
|
46344
|
109 |
PrimitiveStamp p1 = (PrimitiveStamp) stamp;
|
48190
|
110 |
PrimitiveStamp p2 = (PrimitiveStamp) entry.stamp(NodeView.DEFAULT);
|
46344
|
111 |
int width1 = p1.getBits();
|
|
112 |
int width2 = p2.getBits();
|
|
113 |
if (width1 == width2) {
|
48190
|
114 |
Node replacement = ReinterpretNode.create(p2, entry, NodeView.DEFAULT);
|
46344
|
115 |
tool.replaceWith((ValueNode) replacement);
|
|
116 |
return;
|
|
117 |
} else {
|
|
118 |
// different bit width
|
|
119 |
return;
|
|
120 |
}
|
|
121 |
} else {
|
|
122 |
// cannot reinterpret for arbitrary objects
|
|
123 |
return;
|
|
124 |
}
|
|
125 |
}
|
|
126 |
tool.replaceWith(entry);
|
|
127 |
}
|
|
128 |
}
|
|
129 |
}
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
@Override
|
47667
|
134 |
public Node canonical(CanonicalizerTool tool) {
|
|
135 |
if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
|
|
136 |
ValueNode targetObject = object();
|
|
137 |
if (offset().isConstant() && targetObject.isConstant() && !targetObject.isNullConstant()) {
|
|
138 |
ConstantNode objectConstant = (ConstantNode) targetObject;
|
|
139 |
ResolvedJavaType type = StampTool.typeOrNull(objectConstant);
|
|
140 |
if (type != null && type.isArray()) {
|
|
141 |
JavaConstant arrayConstant = objectConstant.asJavaConstant();
|
|
142 |
if (arrayConstant != null) {
|
|
143 |
int stableDimension = objectConstant.getStableDimension();
|
|
144 |
if (stableDimension > 0) {
|
48190
|
145 |
NodeView view = NodeView.from(tool);
|
47667
|
146 |
long constantOffset = offset().asJavaConstant().asLong();
|
48190
|
147 |
Constant constant = stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), arrayConstant, constantOffset);
|
47667
|
148 |
boolean isDefaultStable = objectConstant.isDefaultStable();
|
|
149 |
if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
|
48190
|
150 |
return ConstantNode.forConstant(stamp(view), constant, stableDimension - 1, isDefaultStable, tool.getMetaAccess());
|
47667
|
151 |
}
|
|
152 |
}
|
|
153 |
}
|
|
154 |
}
|
|
155 |
}
|
|
156 |
}
|
|
157 |
return super.canonical(tool);
|
|
158 |
}
|
|
159 |
|
|
160 |
@Override
|
46344
|
161 |
protected ValueNode cloneAsFieldAccess(Assumptions assumptions, ResolvedJavaField field) {
|
|
162 |
return LoadFieldNode.create(assumptions, object(), field);
|
|
163 |
}
|
|
164 |
|
|
165 |
@Override
|
|
166 |
protected ValueNode cloneAsArrayAccess(ValueNode location, LocationIdentity identity) {
|
|
167 |
return new RawLoadNode(object(), location, accessKind(), identity);
|
|
168 |
}
|
|
169 |
|
|
170 |
@NodeIntrinsic
|
|
171 |
public static native Object load(Object object, long offset, @ConstantNodeParameter JavaKind kind, @ConstantNodeParameter LocationIdentity locationIdentity);
|
|
172 |
}
|