Search in sources :

Example 1 with UnsafeAccessNode

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

the class ReadEliminationClosure method processNode.

@Override
protected boolean processNode(Node node, ReadEliminationBlockState state, GraphEffectList effects, FixedWithNextNode lastFixedNode) {
    boolean deleted = false;
    if (node instanceof AccessFieldNode) {
        AccessFieldNode access = (AccessFieldNode) node;
        if (access.isVolatile()) {
            processIdentity(state, any());
        } else {
            ValueNode object = GraphUtil.unproxify(access.object());
            LoadCacheEntry identifier = new LoadCacheEntry(object, new FieldLocationIdentity(access.field()));
            ValueNode cachedValue = state.getCacheEntry(identifier);
            if (node instanceof LoadFieldNode) {
                if (cachedValue != null && access.stamp(NodeView.DEFAULT).isCompatible(cachedValue.stamp(NodeView.DEFAULT))) {
                    effects.replaceAtUsages(access, cachedValue, access);
                    addScalarAlias(access, cachedValue);
                    deleted = true;
                } else {
                    state.addCacheEntry(identifier, access);
                }
            } else {
                assert node instanceof StoreFieldNode;
                StoreFieldNode store = (StoreFieldNode) node;
                ValueNode value = getScalarAlias(store.value());
                if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
                    effects.deleteNode(store);
                    deleted = true;
                }
                state.killReadCache(identifier.identity);
                state.addCacheEntry(identifier, value);
            }
        }
    } else if (node instanceof ReadNode) {
        ReadNode read = (ReadNode) node;
        if (read.getLocationIdentity().isSingle()) {
            ValueNode object = GraphUtil.unproxify(read.getAddress());
            LoadCacheEntry identifier = new LoadCacheEntry(object, read.getLocationIdentity());
            ValueNode cachedValue = state.getCacheEntry(identifier);
            if (cachedValue != null && areValuesReplaceable(read, cachedValue, considerGuards)) {
                effects.replaceAtUsages(read, cachedValue, read);
                addScalarAlias(read, cachedValue);
                deleted = true;
            } else {
                state.addCacheEntry(identifier, read);
            }
        }
    } else if (node instanceof WriteNode) {
        WriteNode write = (WriteNode) node;
        if (write.getLocationIdentity().isSingle()) {
            ValueNode object = GraphUtil.unproxify(write.getAddress());
            LoadCacheEntry identifier = new LoadCacheEntry(object, write.getLocationIdentity());
            ValueNode cachedValue = state.getCacheEntry(identifier);
            ValueNode value = getScalarAlias(write.value());
            if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
                effects.deleteNode(write);
                deleted = true;
            }
            processIdentity(state, write.getLocationIdentity());
            state.addCacheEntry(identifier, value);
        } else {
            processIdentity(state, write.getLocationIdentity());
        }
    } else if (node instanceof UnsafeAccessNode) {
        ResolvedJavaType type = StampTool.typeOrNull(((UnsafeAccessNode) node).object());
        if (type != null && !type.isArray()) {
            if (node instanceof RawLoadNode) {
                RawLoadNode load = (RawLoadNode) node;
                if (load.getLocationIdentity().isSingle()) {
                    ValueNode object = GraphUtil.unproxify(load.object());
                    UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, load.offset(), load.getLocationIdentity());
                    ValueNode cachedValue = state.getCacheEntry(identifier);
                    if (cachedValue != null && areValuesReplaceable(load, cachedValue, considerGuards)) {
                        effects.replaceAtUsages(load, cachedValue, load);
                        addScalarAlias(load, cachedValue);
                        deleted = true;
                    } else {
                        state.addCacheEntry(identifier, load);
                    }
                }
            } else {
                assert node instanceof RawStoreNode;
                RawStoreNode write = (RawStoreNode) node;
                if (write.getLocationIdentity().isSingle()) {
                    ValueNode object = GraphUtil.unproxify(write.object());
                    UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, write.offset(), write.getLocationIdentity());
                    ValueNode cachedValue = state.getCacheEntry(identifier);
                    ValueNode value = getScalarAlias(write.value());
                    if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
                        effects.deleteNode(write);
                        deleted = true;
                    }
                    processIdentity(state, write.getLocationIdentity());
                    state.addCacheEntry(identifier, value);
                } else {
                    processIdentity(state, write.getLocationIdentity());
                }
            }
        }
    } else if (node instanceof MemoryCheckpoint.Single) {
        LocationIdentity identity = ((MemoryCheckpoint.Single) node).getLocationIdentity();
        processIdentity(state, identity);
    } else if (node instanceof MemoryCheckpoint.Multi) {
        for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getLocationIdentities()) {
            processIdentity(state, identity);
        }
    }
    return deleted;
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) UnsafeLoadCacheEntry(org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.UnsafeLoadCacheEntry) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) UnsafeAccessNode(org.graalvm.compiler.nodes.extended.UnsafeAccessNode) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) AccessFieldNode(org.graalvm.compiler.nodes.java.AccessFieldNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LoadCacheEntry(org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.LoadCacheEntry) UnsafeLoadCacheEntry(org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.UnsafeLoadCacheEntry)

Example 2 with UnsafeAccessNode

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

the class UnsafeEATest method canonicalizeGraph.

@Override
protected void canonicalizeGraph() {
    if (testingUnsafe) {
        // transformation into field access nodes.
        for (Node node : graph.getNodes().filter(x -> x instanceof UnsafeAccessNode).snapshot()) {
            if (node instanceof RawStoreNode) {
                RawStoreNode store = (RawStoreNode) node;
                RawStoreNode newStore = graph.add(new RawStoreNode(store.object(), store.offset(), store.value(), store.accessKind(), NamedLocationIdentity.any(), store.needsBarrier(), store.stateAfter(), true));
                graph.replaceFixedWithFixed(store, newStore);
            } else if (node instanceof RawLoadNode) {
                RawLoadNode load = (RawLoadNode) node;
                RawLoadNode newLoad = graph.add(new RawLoadNode(load.object(), load.offset(), load.accessKind(), NamedLocationIdentity.any(), true));
                graph.replaceFixedWithFixed(load, newLoad);
            }
        }
    }
    super.canonicalizeGraph();
}
Also used : RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) UnsafeAccessNode(org.graalvm.compiler.nodes.extended.UnsafeAccessNode) UnpackEndianHalfNode(org.graalvm.compiler.nodes.calc.UnpackEndianHalfNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) Test(org.junit.Test) ByteBuffer(java.nio.ByteBuffer) Graph(org.graalvm.compiler.graph.Graph) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) JavaConstant(jdk.vm.ci.meta.JavaConstant) GraalDirectives(org.graalvm.compiler.api.directives.GraalDirectives) JavaKind(jdk.vm.ci.meta.JavaKind) Node(org.graalvm.compiler.graph.Node) Assert(org.junit.Assert) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) PhiNode(org.graalvm.compiler.nodes.PhiNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) UnsafeAccessNode(org.graalvm.compiler.nodes.extended.UnsafeAccessNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) UnsafeAccessNode(org.graalvm.compiler.nodes.extended.UnsafeAccessNode) UnpackEndianHalfNode(org.graalvm.compiler.nodes.calc.UnpackEndianHalfNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) Node(org.graalvm.compiler.graph.Node) PhiNode(org.graalvm.compiler.nodes.PhiNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode)

Aggregations

RawLoadNode (org.graalvm.compiler.nodes.extended.RawLoadNode)2 RawStoreNode (org.graalvm.compiler.nodes.extended.RawStoreNode)2 UnsafeAccessNode (org.graalvm.compiler.nodes.extended.UnsafeAccessNode)2 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)2 ByteBuffer (java.nio.ByteBuffer)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 GraalDirectives (org.graalvm.compiler.api.directives.GraalDirectives)1 Graph (org.graalvm.compiler.graph.Graph)1 Node (org.graalvm.compiler.graph.Node)1 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)1 NamedLocationIdentity (org.graalvm.compiler.nodes.NamedLocationIdentity)1 PhiNode (org.graalvm.compiler.nodes.PhiNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)1 UnpackEndianHalfNode (org.graalvm.compiler.nodes.calc.UnpackEndianHalfNode)1 AccessFieldNode (org.graalvm.compiler.nodes.java.AccessFieldNode)1 StoreFieldNode (org.graalvm.compiler.nodes.java.StoreFieldNode)1