Search in sources :

Example 1 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class IntegerSwitchNode method doReplace.

private void doReplace(ValueNode newValue, List<KeyData> newKeyDatas, ArrayList<AbstractBeginNode> newSuccessors, int newDefaultSuccessor, double newDefaultProbability) {
    /* Sort the new keys (invariant of the IntegerSwitchNode). */
    newKeyDatas.sort(Comparator.comparingInt(k -> k.key));
    /* Create the final data arrays. */
    int newKeyCount = newKeyDatas.size();
    int[] newKeys = new int[newKeyCount];
    double[] newKeyProbabilities = new double[newKeyCount + 1];
    int[] newKeySuccessors = new int[newKeyCount + 1];
    for (int i = 0; i < newKeyCount; i++) {
        KeyData keyData = newKeyDatas.get(i);
        newKeys[i] = keyData.key;
        newKeyProbabilities[i] = keyData.keyProbability;
        newKeySuccessors[i] = keyData.keySuccessor;
    }
    newKeySuccessors[newKeyCount] = newDefaultSuccessor;
    newKeyProbabilities[newKeyCount] = newDefaultProbability;
    /* Normalize new probabilities so that they sum up to 1. */
    double totalProbability = 0;
    for (double probability : newKeyProbabilities) {
        totalProbability += probability;
    }
    if (totalProbability > 0) {
        for (int i = 0; i < newKeyProbabilities.length; i++) {
            newKeyProbabilities[i] /= totalProbability;
        }
    } else {
        for (int i = 0; i < newKeyProbabilities.length; i++) {
            newKeyProbabilities[i] = 1.0 / newKeyProbabilities.length;
        }
    }
    /*
         * Collect dead successors. Successors have to be cleaned before adding the new node to the
         * graph.
         */
    List<AbstractBeginNode> deadSuccessors = successors.filter(s -> !newSuccessors.contains(s)).snapshot();
    successors.clear();
    /*
         * Create the new switch node. This is done before removing dead successors as `killCFG`
         * could edit some of the inputs (e.g., if `newValue` is a loop-phi of the loop that dies
         * while removing successors).
         */
    AbstractBeginNode[] successorsArray = newSuccessors.toArray(new AbstractBeginNode[newSuccessors.size()]);
    SwitchNode newSwitch = graph().add(new IntegerSwitchNode(newValue, successorsArray, newKeys, newKeyProbabilities, newKeySuccessors));
    /* Remove dead successors. */
    for (AbstractBeginNode successor : deadSuccessors) {
        GraphUtil.killCFG(successor);
    }
    /* Replace ourselves with the new switch */
    ((FixedWithNextNode) predecessor()).setNext(newSwitch);
    GraphUtil.killWithUnusedFloatingInputs(this);
}
Also used : DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) Arrays(java.util.Arrays) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NodeLIRBuilderTool(org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool) SimplifierTool(org.graalvm.compiler.graph.spi.SimplifierTool) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) JavaKind(jdk.vm.ci.meta.JavaKind) NodeClass(org.graalvm.compiler.graph.NodeClass) Map(java.util.Map) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) NodeInfo(org.graalvm.compiler.nodeinfo.NodeInfo) GraphUtil(org.graalvm.compiler.nodes.util.GraphUtil) NodeView(org.graalvm.compiler.nodes.NodeView) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PrimitiveStamp(org.graalvm.compiler.core.common.type.PrimitiveStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) LIRLowerable(org.graalvm.compiler.nodes.spi.LIRLowerable) JavaConstant(jdk.vm.ci.meta.JavaConstant) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider) Simplifiable(org.graalvm.compiler.graph.spi.Simplifiable) Comparator(java.util.Comparator) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 2 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class WriteBarrierVerificationPhase method hasAttachedBarrier.

private boolean hasAttachedBarrier(FixedWithNextNode node) {
    final Node next = node.next();
    final Node previous = node.predecessor();
    boolean validatePreBarrier = useG1GC() && (isObjectWrite(node) || !((ArrayRangeWrite) node).isInitialization());
    if (node instanceof WriteNode) {
        WriteNode writeNode = (WriteNode) node;
        if (writeNode.getLocationIdentity().isInit()) {
            validatePreBarrier = false;
        }
    }
    if (isObjectWrite(node)) {
        return (isObjectBarrier(node, next) || StampTool.isPointerAlwaysNull(getValueWritten(node))) && (!validatePreBarrier || isObjectBarrier(node, previous));
    } else if (isObjectArrayRangeWrite(node)) {
        return (isArrayBarrier(node, next) || StampTool.isPointerAlwaysNull(getValueWritten(node))) && (!validatePreBarrier || isArrayBarrier(node, previous));
    } else {
        return true;
    }
}
Also used : ArrayRangeWrite(org.graalvm.compiler.nodes.extended.ArrayRangeWrite) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode)

Example 3 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class ArrayCopyCallNode method computeBase.

private ValueNode computeBase(ValueNode base, ValueNode pos) {
    FixedWithNextNode basePtr = graph().add(new GetObjectAddressNode(base));
    graph().addBeforeFixed(this, basePtr);
    Stamp wordStamp = StampFactory.forKind(runtime.getTarget().wordJavaKind);
    ValueNode wordPos = IntegerConvertNode.convert(pos, wordStamp, graph(), NodeView.DEFAULT);
    int shift = CodeUtil.log2(getArrayIndexScale(elementKind));
    ValueNode scaledIndex = graph().unique(new LeftShiftNode(wordPos, ConstantNode.forInt(shift, graph())));
    ValueNode offset = graph().unique(new AddNode(scaledIndex, ConstantNode.forIntegerStamp(wordStamp, getArrayBaseOffset(elementKind), graph())));
    return graph().unique(new OffsetAddressNode(basePtr, offset));
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) GetObjectAddressNode(org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode) AbstractMemoryCheckpoint(org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint)

Example 4 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class ReplaceConstantNodesPhase method insertReplacement.

/**
 * Insert the replacement node into the graph. We may need to insert it into a place different
 * than the original {@link FloatingNode} since we need to make sure that replacement will have
 * a valid state assigned.
 *
 * @param graph
 * @param stateMapper
 * @param node
 * @param replacement
 */
private static void insertReplacement(StructuredGraph graph, FrameStateMapperClosure stateMapper, FloatingNode node, FixedWithNextNode replacement) {
    FixedWithNextNode insertionPoint = findInsertionPoint(graph, stateMapper, node);
    graph.addAfterFixed(insertionPoint, replacement);
    stateMapper.addState(replacement, stateMapper.getState(insertionPoint));
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode)

Example 5 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class ReplaceConstantNodesPhase method handleHotSpotObjectConstant.

/**
 * Replace an object constant with an indirect load {@link ResolveConstantNode}. Currently we
 * support only strings.
 *
 * @param graph
 * @param stateMapper
 * @param node {@link ConstantNode} containing a {@link HotSpotObjectConstant} that needs
 *            resolution.
 */
private static void handleHotSpotObjectConstant(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
    HotSpotObjectConstant constant = (HotSpotObjectConstant) node.asJavaConstant();
    HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) constant.getType();
    if (type.mirror().equals(String.class)) {
        assert !constant.isCompressed() : "No support for replacing compressed oop constants";
        FixedWithNextNode replacement = graph.add(new ResolveConstantNode(node));
        insertReplacement(graph, stateMapper, node, replacement);
        node.replaceAtUsages(replacement, n -> !(n instanceof ResolveConstantNode));
    } else {
        throw new GraalError("Unsupported object constant type: " + type);
    }
}
Also used : ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) GraalError(org.graalvm.compiler.debug.GraalError) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant)

Aggregations

FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)57 FixedNode (org.graalvm.compiler.nodes.FixedNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)29 Node (org.graalvm.compiler.graph.Node)26 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)22 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)21 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)20 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)13 EndNode (org.graalvm.compiler.nodes.EndNode)12 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)12 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)10 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)9 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)9 Invoke (org.graalvm.compiler.nodes.Invoke)9 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)9 PhiNode (org.graalvm.compiler.nodes.PhiNode)9 IfNode (org.graalvm.compiler.nodes.IfNode)8 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)7 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7