Search in sources :

Example 61 with ValueNode

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;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) AbstractMemoryCheckpoint(org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 62 with ValueNode

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();
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugContext(org.graalvm.compiler.debug.DebugContext) AbstractMemoryCheckpoint(org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 63 with ValueNode

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);
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 64 with ValueNode

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;
}
Also used : FloatDivNode(org.graalvm.compiler.nodes.calc.FloatDivNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 65 with ValueNode

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;
        };
    }
}
Also used : OperandSize(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize) AMD64RMOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp) AVXOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AVXOp) AMD64BinaryConsumer(org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) LabelRef(org.graalvm.compiler.lir.LabelRef) UnsignedRightShiftNode(org.graalvm.compiler.nodes.calc.UnsignedRightShiftNode) SUB(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.SUB) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) NumUtil(org.graalvm.compiler.core.common.NumUtil) IfNode(org.graalvm.compiler.nodes.IfNode) GraphUtil(org.graalvm.compiler.nodes.util.GraphUtil) NodeView(org.graalvm.compiler.nodes.NodeView) LIRLowerableAccess(org.graalvm.compiler.nodes.memory.LIRLowerableAccess) BranchOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.BranchOp) MOVSX(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp.MOVSX) NodeLIRBuilder(org.graalvm.compiler.core.gen.NodeLIRBuilder) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) TargetDescription(jdk.vm.ci.code.TargetDescription) JavaConstant(jdk.vm.ci.meta.JavaConstant) PlatformKind(jdk.vm.ci.meta.PlatformKind) ValueNode(org.graalvm.compiler.nodes.ValueNode) Value(jdk.vm.ci.meta.Value) ComplexMatchResult(org.graalvm.compiler.core.match.ComplexMatchResult) Access(org.graalvm.compiler.nodes.memory.Access) ADD(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.ADD) SS(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SS) DWORD(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.DWORD) GraalError(org.graalvm.compiler.debug.GraalError) ValueKind(jdk.vm.ci.meta.ValueKind) MatchRule(org.graalvm.compiler.core.match.MatchRule) LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) MOVSXB(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp.MOVSXB) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) SD(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SD) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ReinterpretNode(org.graalvm.compiler.nodes.calc.ReinterpretNode) AMD64RRMOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RRMOp) AMD64(jdk.vm.ci.amd64.AMD64) AMD64MIOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp) ValueCompareAndSwapNode(org.graalvm.compiler.nodes.java.ValueCompareAndSwapNode) MOVSXD(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp.MOVSXD) Condition(org.graalvm.compiler.core.common.calc.Condition) CPUFeature(jdk.vm.ci.amd64.AMD64.CPUFeature) LIRKind(org.graalvm.compiler.core.common.LIRKind) CanonicalCondition(org.graalvm.compiler.core.common.calc.CanonicalCondition) SSEOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.SSEOp) OR(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.OR) LIRValueUtil(org.graalvm.compiler.lir.LIRValueUtil) NodeMatchRules(org.graalvm.compiler.core.gen.NodeMatchRules) XOR(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.XOR) LIRGeneratorTool(org.graalvm.compiler.lir.gen.LIRGeneratorTool) AND(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.AND) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) QWORD(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.QWORD) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) BranchOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.BranchOp) JavaConstant(jdk.vm.ci.meta.JavaConstant) LabelRef(org.graalvm.compiler.lir.LabelRef) OperandSize(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize)

Aggregations

ValueNode (org.graalvm.compiler.nodes.ValueNode)482 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)104 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)77 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)76 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)69 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)67 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)60 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)52 Node (org.graalvm.compiler.graph.Node)50 JavaKind (jdk.vm.ci.meta.JavaKind)48 Stamp (org.graalvm.compiler.core.common.type.Stamp)48 LogicNode (org.graalvm.compiler.nodes.LogicNode)48 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)42 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)38 FixedNode (org.graalvm.compiler.nodes.FixedNode)37 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)37 NodeView (org.graalvm.compiler.nodes.NodeView)36 PhiNode (org.graalvm.compiler.nodes.PhiNode)36 Test (org.junit.Test)36