use of org.graalvm.compiler.nodes.CanonicalizableLocation in project graal by oracle.
the class ReadNode method canonicalizeRead.
public static ValueNode canonicalizeRead(ValueNode read, AddressNode address, LocationIdentity locationIdentity, CanonicalizerTool tool) {
NodeView view = NodeView.from(tool);
MetaAccessProvider metaAccess = tool.getMetaAccess();
if (tool.canonicalizeReads() && address instanceof OffsetAddressNode) {
OffsetAddressNode objAddress = (OffsetAddressNode) address;
ValueNode object = objAddress.getBase();
if (metaAccess != null && object.isConstant() && !object.isNullConstant() && objAddress.getOffset().isConstant()) {
long displacement = objAddress.getOffset().asJavaConstant().asLong();
int stableDimension = ((ConstantNode) object).getStableDimension();
if (locationIdentity.isImmutable() || stableDimension > 0) {
Constant constant = read.stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), object.asConstant(), displacement);
boolean isDefaultStable = locationIdentity.isImmutable() || ((ConstantNode) object).isDefaultStable();
if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
return ConstantNode.forConstant(read.stamp(view), constant, Math.max(stableDimension - 1, 0), isDefaultStable, metaAccess);
}
}
}
if (locationIdentity.equals(ARRAY_LENGTH_LOCATION)) {
ValueNode length = GraphUtil.arrayLength(object);
if (length != null) {
return length;
}
}
if (locationIdentity instanceof CanonicalizableLocation) {
CanonicalizableLocation canonicalize = (CanonicalizableLocation) locationIdentity;
ValueNode result = canonicalize.canonicalizeRead(read, address, object, tool);
assert result != null && result.stamp(view).isCompatible(read.stamp(view));
return result;
}
}
return read;
}
Aggregations