use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class BasicArrayCopyNode method checkEntryTypes.
private static boolean checkEntryTypes(int srcPos, int length, VirtualObjectNode src, ResolvedJavaType destComponentType, VirtualizerTool tool) {
if (destComponentType.getJavaKind() == JavaKind.Object && !destComponentType.isJavaLangObject()) {
for (int i = 0; i < length; i++) {
ValueNode entry = tool.getEntry(src, srcPos + i);
ResolvedJavaType type = StampTool.typeOrNull(entry);
if (type == null || !destComponentType.isAssignableFrom(type)) {
return false;
}
}
}
return true;
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class BasicArrayCopyNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode sourcePosition = tool.getAlias(getSourcePosition());
ValueNode destinationPosition = tool.getAlias(getDestinationPosition());
ValueNode replacedLength = tool.getAlias(getLength());
if (sourcePosition.isConstant() && destinationPosition.isConstant() && replacedLength.isConstant()) {
int srcPosInt = sourcePosition.asJavaConstant().asInt();
int destPosInt = destinationPosition.asJavaConstant().asInt();
int len = replacedLength.asJavaConstant().asInt();
ValueNode destAlias = tool.getAlias(getDestination());
if (destAlias instanceof VirtualArrayNode) {
VirtualArrayNode destVirtual = (VirtualArrayNode) destAlias;
if (len < 0 || !checkBounds(destPosInt, len, destVirtual)) {
return;
}
ValueNode srcAlias = tool.getAlias(getSource());
if (srcAlias instanceof VirtualObjectNode) {
if (!(srcAlias instanceof VirtualArrayNode)) {
return;
}
VirtualArrayNode srcVirtual = (VirtualArrayNode) srcAlias;
if (destVirtual.componentType().getJavaKind() != srcVirtual.componentType().getJavaKind()) {
return;
}
if (!checkBounds(srcPosInt, len, srcVirtual)) {
return;
}
if (!checkEntryTypes(srcPosInt, len, srcVirtual, destVirtual.type().getComponentType(), tool)) {
return;
}
for (int i = 0; i < len; i++) {
tool.setVirtualEntry(destVirtual, destPosInt + i, tool.getEntry(srcVirtual, srcPosInt + i));
}
tool.delete();
DebugContext debug = getDebug();
if (debug.isLogEnabled()) {
debug.log("virtualized arraycopy(%s, %d, %s, %d, %d)", getSource(), srcPosInt, getDestination(), destPosInt, len);
}
} else {
ResolvedJavaType sourceType = StampTool.typeOrNull(srcAlias);
if (sourceType == null || !sourceType.isArray()) {
return;
}
ResolvedJavaType sourceComponentType = sourceType.getComponentType();
ResolvedJavaType destComponentType = destVirtual.type().getComponentType();
if (!sourceComponentType.equals(destComponentType)) {
return;
}
for (int i = 0; i < len; i++) {
LoadIndexedNode load = new LoadIndexedNode(graph().getAssumptions(), srcAlias, ConstantNode.forInt(i + srcPosInt, graph()), destComponentType.getJavaKind());
tool.addNode(load);
tool.setVirtualEntry(destVirtual, destPosInt + i, load);
}
tool.delete();
}
}
}
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class BasicObjectCloneNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode originalAlias = tool.getAlias(getObject());
if (originalAlias instanceof VirtualObjectNode) {
VirtualObjectNode originalVirtual = (VirtualObjectNode) originalAlias;
if (originalVirtual.type().isCloneableWithAllocation()) {
ValueNode[] newEntryState = new ValueNode[originalVirtual.entryCount()];
for (int i = 0; i < newEntryState.length; i++) {
newEntryState[i] = tool.getEntry(originalVirtual, i);
}
VirtualObjectNode newVirtual = originalVirtual.duplicate();
tool.createVirtualObject(newVirtual, newEntryState, Collections.<MonitorIdNode>emptyList(), false);
tool.replaceWithVirtual(newVirtual);
}
} else {
ResolvedJavaType type = getConcreteType(originalAlias.stamp(NodeView.DEFAULT));
if (type != null && !type.isArray()) {
VirtualInstanceNode newVirtual = createVirtualInstanceNode(type, true);
ResolvedJavaField[] fields = newVirtual.getFields();
ValueNode[] state = new ValueNode[fields.length];
final LoadFieldNode[] loads = new LoadFieldNode[fields.length];
for (int i = 0; i < fields.length; i++) {
state[i] = loads[i] = genLoadFieldNode(graph().getAssumptions(), originalAlias, fields[i]);
tool.addNode(loads[i]);
}
tool.createVirtualObject(newVirtual, state, Collections.<MonitorIdNode>emptyList(), false);
tool.replaceWithVirtual(newVirtual);
}
}
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class BinaryMathIntrinsicNode method canonical.
@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
NodeView view = NodeView.from(tool);
ValueNode c = tryConstantFold(forX, forY, getOperation());
if (c != null) {
return c;
}
if (forY.isConstant()) {
double yValue = forY.asJavaConstant().asDouble();
// If the second argument is positive or negative zero, then the result is 1.0.
if (yValue == 0.0D) {
return ConstantNode.forDouble(1);
}
// If the second argument is 1.0, then the result is the same as the first argument.
if (yValue == 1.0D) {
return x;
}
// If the second argument is NaN, then the result is NaN.
if (Double.isNaN(yValue)) {
return ConstantNode.forDouble(Double.NaN);
}
// x**-1 = 1/x
if (yValue == -1.0D) {
return new FloatDivNode(ConstantNode.forDouble(1), x);
}
// x**2 = x*x
if (yValue == 2.0D) {
return new MulNode(x, x);
}
// x**0.5 = sqrt(x)
if (yValue == 0.5D && x.stamp(view) instanceof FloatStamp && ((FloatStamp) x.stamp(view)).lowerBound() >= 0.0D) {
return SqrtNode.create(x, view);
}
}
return this;
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class AMD64NodeMatchRules method emitIntegerTestBranchMemory.
private ComplexMatchResult emitIntegerTestBranchMemory(IfNode x, ValueNode value, LIRLowerableAccess access) {
LabelRef trueLabel = getLIRBlock(x.trueSuccessor());
LabelRef falseLabel = getLIRBlock(x.falseSuccessor());
double trueLabelProbability = x.probability(x.trueSuccessor());
AMD64Kind kind = getMemoryKind(access);
OperandSize size = kind == AMD64Kind.QWORD ? QWORD : DWORD;
if (value.isConstant()) {
JavaConstant constant = value.asJavaConstant();
if (constant != null && kind == AMD64Kind.QWORD && !NumUtil.isInt(constant.asLong())) {
// Only imm32 as long
return null;
}
return builder -> {
AMD64AddressValue address = (AMD64AddressValue) operand(access.getAddress());
gen.append(new AMD64BinaryConsumer.MemoryConstOp(AMD64MIOp.TEST, size, address, (int) constant.asLong(), getState(access)));
gen.append(new BranchOp(Condition.EQ, trueLabel, falseLabel, trueLabelProbability));
return null;
};
} else {
return builder -> {
AMD64AddressValue address = (AMD64AddressValue) operand(access.getAddress());
gen.append(new AMD64BinaryConsumer.MemoryRMOp(AMD64RMOp.TEST, size, gen.asAllocatable(operand(value)), address, getState(access)));
gen.append(new BranchOp(Condition.EQ, trueLabel, falseLabel, trueLabelProbability));
return null;
};
}
}
Aggregations