Search in sources :

Example 1 with UnsafeLoadCacheEntry

use of org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.UnsafeLoadCacheEntry 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)

Aggregations

ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 RawLoadNode (org.graalvm.compiler.nodes.extended.RawLoadNode)1 RawStoreNode (org.graalvm.compiler.nodes.extended.RawStoreNode)1 UnsafeAccessNode (org.graalvm.compiler.nodes.extended.UnsafeAccessNode)1 AccessFieldNode (org.graalvm.compiler.nodes.java.AccessFieldNode)1 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)1 StoreFieldNode (org.graalvm.compiler.nodes.java.StoreFieldNode)1 MemoryCheckpoint (org.graalvm.compiler.nodes.memory.MemoryCheckpoint)1 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)1 WriteNode (org.graalvm.compiler.nodes.memory.WriteNode)1 LoadCacheEntry (org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.LoadCacheEntry)1 UnsafeLoadCacheEntry (org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.UnsafeLoadCacheEntry)1 LocationIdentity (org.graalvm.word.LocationIdentity)1