Search in sources :

Example 81 with ConstantNode

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

the class ReplaceConstantNodesPhase method handleLoadMethodCounters.

/**
 * Replace {@link LoadMethodCountersNode} with indirect load
 * {@link ResolveMethodAndLoadCountersNode}, expose a klass constant of the holder.
 *
 * @param graph
 * @param stateMapper
 * @param node
 * @param context
 */
private static void handleLoadMethodCounters(StructuredGraph graph, FrameStateMapperClosure stateMapper, LoadMethodCountersNode node, PhaseContext context) {
    ResolvedJavaType type = node.getMethod().getDeclaringClass();
    Stamp hubStamp = context.getStampProvider().createHubStamp((ObjectStamp) StampFactory.objectNonNull());
    ConstantReflectionProvider constantReflection = context.getConstantReflection();
    ConstantNode klassHint = ConstantNode.forConstant(hubStamp, constantReflection.asObjectHub(type), context.getMetaAccess(), graph);
    FixedWithNextNode replacement = graph.add(new ResolveMethodAndLoadCountersNode(node.getMethod(), klassHint));
    insertReplacement(graph, stateMapper, node, replacement);
    node.replaceAtUsages(replacement, n -> !(n instanceof ResolveMethodAndLoadCountersNode));
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType)

Example 82 with ConstantNode

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

the class ReplaceConstantNodesPhase method tryToReplaceWithExisting.

/**
 * Try to find dominating node doing the resolution that can be reused.
 *
 * @param graph
 * @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
 *            resolution.
 */
private static void tryToReplaceWithExisting(StructuredGraph graph, ConstantNode node) {
    ScheduleResult schedule = graph.getLastSchedule();
    NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
    BlockMap<List<Node>> blockToNodes = schedule.getBlockToNodesMap();
    EconomicMap<Block, Node> blockToExisting = EconomicMap.create();
    for (Node n : node.usages().filter(n -> isReplacementNode(n))) {
        blockToExisting.put(nodeToBlock.get(n), n);
    }
    for (Node use : node.usages().filter(n -> !isReplacementNode(n)).snapshot()) {
        boolean replaced = false;
        Block b = nodeToBlock.get(use);
        Node e = blockToExisting.get(b);
        if (e != null) {
            // the use is scheduled after it.
            for (Node n : blockToNodes.get(b)) {
                if (n.equals(use)) {
                    // Usage is before initialization, can't use it
                    break;
                }
                if (n.equals(e)) {
                    use.replaceFirstInput(node, e);
                    replaced = true;
                    break;
                }
            }
        }
        if (!replaced) {
            // Look for dominating blocks that have existing nodes
            for (Block d : blockToExisting.getKeys()) {
                if (strictlyDominates(d, b)) {
                    use.replaceFirstInput(node, blockToExisting.get(d));
                    break;
                }
            }
        }
    }
}
Also used : LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) Constant(jdk.vm.ci.meta.Constant) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) EconomicMap(org.graalvm.collections.EconomicMap) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) HotSpotConstantLoadAction(org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ReentrantNodeIterator(org.graalvm.compiler.phases.graph.ReentrantNodeIterator) NodeIteratorClosure(org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) BasePhase(org.graalvm.compiler.phases.BasePhase) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) SchedulingStrategy(org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) FrameState(org.graalvm.compiler.nodes.FrameState) ConstantNode.getConstantNodes(org.graalvm.compiler.nodes.ConstantNode.getConstantNodes) GraalError(org.graalvm.compiler.debug.GraalError) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) StateSplit(org.graalvm.compiler.nodes.StateSplit) LoadMethodCountersNode.getLoadMethodCountersNodes(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode.getLoadMethodCountersNodes) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) HashSet(java.util.HashSet) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) NodeMap(org.graalvm.compiler.graph.NodeMap) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) AbstractControlFlowGraph.strictlyDominates(org.graalvm.compiler.core.common.cfg.AbstractControlFlowGraph.strictlyDominates) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) BlockMap(org.graalvm.compiler.core.common.cfg.BlockMap) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Block(org.graalvm.compiler.nodes.cfg.Block) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Block(org.graalvm.compiler.nodes.cfg.Block) List(java.util.List)

Example 83 with ConstantNode

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

the class LoadJavaMirrorWithKlassPhase method run.

@Override
protected void run(StructuredGraph graph, PhaseContext context) {
    for (ConstantNode node : getConstantNodes(graph)) {
        JavaConstant constant = node.asJavaConstant();
        ValueNode freadNode = getClassConstantReplacement(graph, context, constant);
        if (freadNode != null) {
            node.replace(graph, freadNode);
        }
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 84 with ConstantNode

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

the class IdentityHashCodeNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (object.isConstant()) {
        assert object.stamp(NodeView.DEFAULT) instanceof AbstractObjectStamp;
        JavaConstant c = (JavaConstant) object.asConstant();
        if (ImmutableCode.getValue(tool.getOptions())) {
            return this;
        }
        JavaConstant identityHashCode = null;
        if (c.isNull()) {
            identityHashCode = JavaConstant.forInt(0);
        } else {
            identityHashCode = JavaConstant.forInt(((HotSpotObjectConstant) c).getIdentityHashCode());
        }
        return new ConstantNode(identityHashCode, StampFactory.forConstant(identityHashCode));
    }
    return this;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) JavaConstant(jdk.vm.ci.meta.JavaConstant) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant)

Example 85 with ConstantNode

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

the class LoadFieldNode method asPhi.

private static PhiNode asPhi(ConstantFieldProvider constantFields, ConstantReflectionProvider constantReflection, MetaAccessProvider metaAcccess, OptionValues options, ValueNode forObject, ResolvedJavaField field, Stamp stamp) {
    if (!field.isStatic() && field.isFinal() && forObject instanceof ValuePhiNode && ((ValuePhiNode) forObject).values().filter(isNotA(ConstantNode.class)).isEmpty()) {
        PhiNode phi = (PhiNode) forObject;
        ConstantNode[] constantNodes = new ConstantNode[phi.valueCount()];
        for (int i = 0; i < phi.valueCount(); i++) {
            ConstantNode constant = ConstantFoldUtil.tryConstantFold(constantFields, constantReflection, metaAcccess, field, phi.valueAt(i).asJavaConstant(), options);
            if (constant == null) {
                return null;
            }
            constantNodes[i] = constant;
        }
        return new ValuePhiNode(stamp, phi.merge(), constantNodes);
    }
    return null;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode)

Aggregations

ConstantNode (org.graalvm.compiler.nodes.ConstantNode)100 ValueNode (org.graalvm.compiler.nodes.ValueNode)46 JavaConstant (jdk.vm.ci.meta.JavaConstant)32 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)28 Stamp (org.graalvm.compiler.core.common.type.Stamp)23 Test (org.junit.Test)15 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)14 Node (org.graalvm.compiler.graph.Node)14 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)13 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)13 PhiNode (org.graalvm.compiler.nodes.PhiNode)12 LogicNode (org.graalvm.compiler.nodes.LogicNode)11 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)10 ArrayList (java.util.ArrayList)9 JavaKind (jdk.vm.ci.meta.JavaKind)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 Constant (jdk.vm.ci.meta.Constant)8 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)8 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)7