Search in sources :

Example 1 with ReadCacheEntry

use of org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry in project graal by oracle.

the class PEReadEliminationClosure method processLoopExit.

@Override
protected void processLoopExit(LoopExitNode exitNode, PEReadEliminationBlockState initialState, PEReadEliminationBlockState exitState, GraphEffectList effects) {
    super.processLoopExit(exitNode, initialState, exitState, effects);
    if (exitNode.graph().hasValueProxies()) {
        MapCursor<ReadCacheEntry, ValueNode> entry = exitState.getReadCache().getEntries();
        while (entry.advance()) {
            if (initialState.getReadCache().get(entry.getKey()) != entry.getValue()) {
                ValueNode value = exitState.getReadCache(entry.getKey().object, entry.getKey().identity, entry.getKey().index, entry.getKey().kind, this);
                assert value != null : "Got null from read cache, entry's value:" + entry.getValue();
                if (!(value instanceof ProxyNode) || ((ProxyNode) value).proxyPoint() != exitNode) {
                    ProxyNode proxy = new ValueProxyNode(value, exitNode);
                    effects.addFloatingNode(proxy, "readCacheProxy");
                    exitState.getReadCache().put(entry.getKey(), proxy);
                }
            }
        }
    }
}
Also used : ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ReadCacheEntry(org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 2 with ReadCacheEntry

use of org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry in project graal by oracle.

the class PEReadEliminationClosure method processInitialLoopState.

@SuppressWarnings("unchecked")
@Override
protected void processInitialLoopState(Loop<Block> loop, PEReadEliminationBlockState initialState) {
    super.processInitialLoopState(loop, initialState);
    if (!initialState.getReadCache().isEmpty()) {
        EconomicMap<ValueNode, Pair<ValueNode, Object>> firstValueSet = null;
        for (PhiNode phi : ((LoopBeginNode) loop.getHeader().getBeginNode()).phis()) {
            ValueNode firstValue = phi.valueAt(0);
            if (firstValue != null && phi.getStackKind().isObject()) {
                ValueNode unproxified = GraphUtil.unproxify(firstValue);
                if (firstValueSet == null) {
                    firstValueSet = EconomicMap.create(Equivalence.IDENTITY_WITH_SYSTEM_HASHCODE);
                }
                Pair<ValueNode, Object> pair = Pair.create(unproxified, firstValueSet.get(unproxified));
                firstValueSet.put(unproxified, pair);
            }
        }
        if (firstValueSet != null) {
            ReadCacheEntry[] entries = new ReadCacheEntry[initialState.getReadCache().size()];
            int z = 0;
            for (ReadCacheEntry entry : initialState.getReadCache().getKeys()) {
                entries[z++] = entry;
            }
            for (ReadCacheEntry entry : entries) {
                ValueNode object = entry.object;
                if (object != null) {
                    Pair<ValueNode, Object> pair = firstValueSet.get(object);
                    while (pair != null) {
                        initialState.addReadCache(pair.getLeft(), entry.identity, entry.index, entry.kind, entry.overflowAccess, initialState.getReadCache().get(entry), this);
                        pair = (Pair<ValueNode, Object>) pair.getRight();
                    }
                }
            }
        }
    }
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ReadCacheEntry(org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) Pair(org.graalvm.collections.Pair)

Example 3 with ReadCacheEntry

use of org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry in project graal by oracle.

the class PEReadEliminationClosure method stripKilledLoopLocations.

@Override
protected PEReadEliminationBlockState stripKilledLoopLocations(Loop<Block> loop, PEReadEliminationBlockState originalInitialState) {
    PEReadEliminationBlockState initialState = super.stripKilledLoopLocations(loop, originalInitialState);
    LoopKillCache loopKilledLocations = loopLocationKillCache.get(loop);
    if (loopKilledLocations != null && loopKilledLocations.loopKillsLocations()) {
        Iterator<ReadCacheEntry> it = initialState.readCache.getKeys().iterator();
        while (it.hasNext()) {
            ReadCacheEntry entry = it.next();
            if (loopKilledLocations.containsLocation(entry.identity)) {
                it.remove();
            }
        }
    }
    return initialState;
}
Also used : ReadCacheEntry(org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry)

Example 4 with ReadCacheEntry

use of org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry in project graal by oracle.

the class PEReadEliminationClosure method processKilledLoopLocations.

@Override
protected void processKilledLoopLocations(Loop<Block> loop, PEReadEliminationBlockState initialState, PEReadEliminationBlockState mergedStates) {
    assert initialState != null;
    assert mergedStates != null;
    if (initialState.readCache.size() > 0) {
        LoopKillCache loopKilledLocations = loopLocationKillCache.get(loop);
        // it is visited
        if (loopKilledLocations == null) {
            loopKilledLocations = new LoopKillCache(1);
            loopLocationKillCache.put(loop, loopKilledLocations);
        } else {
            AbstractBeginNode beginNode = loop.getHeader().getBeginNode();
            OptionValues options = beginNode.getOptions();
            if (loopKilledLocations.visits() > ReadEliminationMaxLoopVisits.getValue(options)) {
                // we have processed the loop too many times, kill all locations so the inner
                // loop will never be processed more than once again on visit
                loopKilledLocations.setKillsAll();
            } else {
                // we have fully processed this loop >1 times, update the killed locations
                EconomicSet<LocationIdentity> forwardEndLiveLocations = EconomicSet.create(Equivalence.DEFAULT);
                for (ReadCacheEntry entry : initialState.readCache.getKeys()) {
                    forwardEndLiveLocations.add(entry.identity);
                }
                for (ReadCacheEntry entry : mergedStates.readCache.getKeys()) {
                    forwardEndLiveLocations.remove(entry.identity);
                }
                // loop
                for (LocationIdentity location : forwardEndLiveLocations) {
                    loopKilledLocations.rememberLoopKilledLocation(location);
                }
                if (debug.isLogEnabled() && loopKilledLocations != null) {
                    debug.log("[Early Read Elimination] Setting loop killed locations of loop at node %s with %s", beginNode, forwardEndLiveLocations);
                }
            }
            // remember the loop visit
            loopKilledLocations.visited();
        }
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) ReadCacheEntry(org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

ReadCacheEntry (org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 Pair (org.graalvm.collections.Pair)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)1 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)1 NamedLocationIdentity (org.graalvm.compiler.nodes.NamedLocationIdentity)1 PhiNode (org.graalvm.compiler.nodes.PhiNode)1 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)1 ValueProxyNode (org.graalvm.compiler.nodes.ValueProxyNode)1 MemoryCheckpoint (org.graalvm.compiler.nodes.memory.MemoryCheckpoint)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 LocationIdentity (org.graalvm.word.LocationIdentity)1