use of org.graalvm.compiler.nodes.memory.MemoryAccess in project graal by oracle.
the class ReferenceGetLoopTest method checkMidTierGraph.
@Override
protected void checkMidTierGraph(StructuredGraph graph) {
final LoopsData loops = getDefaultMidTierContext().getLoopsDataProvider().getLoopsData(graph);
boolean found = false;
for (LoopEx loop : loops.loops()) {
for (Node node : loop.inside().nodes()) {
if (node instanceof MemoryAccess) {
MemoryAccess access = (MemoryAccess) node;
LocationIdentity location = access.getLocationIdentity();
if (location instanceof FieldLocationIdentity) {
ResolvedJavaField field = ((FieldLocationIdentity) location).getField();
if (field.getName().equals("referent") && field.getDeclaringClass().equals(getMetaAccess().lookupJavaType(Reference.class))) {
found = true;
}
}
}
}
}
if (!found) {
assertTrue(false, "Reference.referent not found in loop: " + getCanonicalGraphString(graph, true, false));
}
}
use of org.graalvm.compiler.nodes.memory.MemoryAccess in project graal by oracle.
the class ScheduleVerification method processBlock.
@Override
protected EconomicSet<FloatingReadNode> processBlock(Block block, EconomicSet<FloatingReadNode> currentState) {
AbstractBeginNode beginNode = block.getBeginNode();
if (beginNode instanceof AbstractMergeNode) {
AbstractMergeNode abstractMergeNode = (AbstractMergeNode) beginNode;
for (PhiNode phi : abstractMergeNode.phis()) {
if (phi instanceof MemoryPhiNode) {
MemoryPhiNode memoryPhiNode = (MemoryPhiNode) phi;
addFloatingReadUsages(currentState, memoryPhiNode);
}
}
}
if (beginNode instanceof LoopExitNode) {
LoopExitNode loopExitNode = (LoopExitNode) beginNode;
for (ProxyNode proxy : loopExitNode.proxies()) {
if (proxy instanceof MemoryProxyNode) {
MemoryProxyNode memoryProxyNode = (MemoryProxyNode) proxy;
addFloatingReadUsages(currentState, memoryProxyNode);
}
}
}
for (Node n : blockToNodesMap.get(block)) {
if (n instanceof MemoryKill) {
if (n instanceof SingleMemoryKill) {
SingleMemoryKill single = (SingleMemoryKill) n;
processLocation(n, single.getKilledLocationIdentity(), currentState);
} else if (n instanceof MultiMemoryKill) {
MultiMemoryKill multi = (MultiMemoryKill) n;
for (LocationIdentity location : multi.getKilledLocationIdentities()) {
processLocation(n, location, currentState);
}
}
addFloatingReadUsages(currentState, n);
} else if (n instanceof MemoryAccess) {
addFloatingReadUsages(currentState, n);
} else if (n instanceof FloatingReadNode) {
FloatingReadNode floatingReadNode = (FloatingReadNode) n;
if (floatingReadNode.getLastLocationAccess() != null && floatingReadNode.getLocationIdentity().isMutable()) {
if (currentState.contains(floatingReadNode)) {
// Floating read was found in the state.
currentState.remove(floatingReadNode);
} else {
throw new RuntimeException("Floating read node " + n + " was not found in the state, i.e., it was killed by a memory check point before its place in the schedule. Block=" + block + ", block begin: " + block.getBeginNode() + " block loop: " + block.getLoop() + ", " + blockToNodesMap.get(block).get(0));
}
}
}
assert nodeMap.get(n) == block;
if (graph.isBeforeStage(StageFlag.VALUE_PROXY_REMOVAL) && block.getLoop() != null && !(n instanceof VirtualState)) {
for (Node usage : n.usages()) {
Node usageNode = usage;
if (usageNode instanceof PhiNode) {
PhiNode phiNode = (PhiNode) usage;
usageNode = phiNode.merge();
}
if (usageNode instanceof LoopExitNode) {
LoopExitNode loopExitNode = (LoopExitNode) usageNode;
if (loopExitNode.loopBegin() == n || loopExitNode.stateAfter() == n) {
continue;
}
}
Block usageBlock = nodeMap.get(usageNode);
if (usageBlock == null) {
if (usage instanceof FloatingNode || usage instanceof VirtualState || usage instanceof CallTargetNode) {
if (!(usage instanceof GuardNode)) {
/*
* We do not want to run the schedule behind the verification with
* dead code elimination, i.e., floating nodes without usages are
* not removed, thus we must handle the case that a floating node
* without a usage occurs here.
*/
if (nonFixedNodeTreeWithoutUsages(usage)) {
continue;
}
}
}
}
assert usageBlock != null || usage instanceof ProxyNode : "Usage " + usageNode + " of node " + n + " has no block";
Loop<Block> usageLoop = null;
if (usageNode instanceof ProxyNode) {
ProxyNode proxyNode = (ProxyNode) usageNode;
usageLoop = nodeMap.get(proxyNode.proxyPoint().loopBegin()).getLoop();
} else {
if (usageBlock.getBeginNode() instanceof LoopExitNode) {
// For nodes in the loop exit node block, we don't know for sure
// whether they are "in the loop" or not. It depends on whether
// one of their transient usages is a loop proxy node.
// For now, let's just assume those nodes are OK, i.e., "in the loop".
LoopExitNode loopExitNode = (LoopExitNode) usageBlock.getBeginNode();
usageLoop = nodeMap.get(loopExitNode.loopBegin()).getLoop();
} else {
usageLoop = usageBlock.getLoop();
}
}
assert usageLoop != null : n + ", " + nodeMap.get(n) + " / " + usageNode + ", " + nodeMap.get(usageNode);
while (usageLoop != block.getLoop() && usageLoop != null) {
usageLoop = usageLoop.getParent();
}
assert usageLoop != null : n + ", " + usageNode + ", " + usageBlock + ", " + usageBlock.getLoop() + ", " + block + ", " + block.getLoop();
}
}
}
return currentState;
}
use of org.graalvm.compiler.nodes.memory.MemoryAccess in project graal by oracle.
the class InsertGuardFencesPhase method isBoundsCheckGuard.
private static boolean isBoundsCheckGuard(AbstractBeginNode beginNode) {
if (!(beginNode.predecessor() instanceof IfNode)) {
return false;
}
IfNode ifNode = (IfNode) beginNode.predecessor();
AbstractBeginNode otherBegin;
if (ifNode.trueSuccessor() == beginNode) {
otherBegin = ifNode.falseSuccessor();
} else {
assert ifNode.falseSuccessor() == beginNode;
otherBegin = ifNode.trueSuccessor();
}
if (otherBegin.next() instanceof DeoptimizeNode) {
DeoptimizeNode deopt = (DeoptimizeNode) otherBegin.next();
if (deopt.getReason() == DeoptimizationReason.BoundsCheckException && !hasMultipleGuardUsages(beginNode)) {
return true;
}
} else if (otherBegin instanceof LoopExitNode && beginNode.usages().filter(MultiGuardNode.class).isNotEmpty() && !hasMultipleGuardUsages(beginNode)) {
return true;
}
for (Node usage : beginNode.usages()) {
for (Position pos : usage.inputPositions()) {
if (pos.getInputType() == InputType.Guard && pos.get(usage) == beginNode) {
if (usage instanceof PiNode) {
if (!((PiNode) usage).piStamp().equals(POSITIVE_ARRAY_INDEX_STAMP)) {
return false;
}
} else if (usage instanceof MemoryAccess) {
if (!NamedLocationIdentity.isArrayLocation(((MemoryAccess) usage).getLocationIdentity())) {
return false;
}
} else {
return false;
}
break;
}
}
}
return true;
}
Aggregations