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);
}
}
}
}
}
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();
}
}
}
}
}
}
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;
}
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();
}
}
}
Aggregations