use of org.graalvm.compiler.nodes.FixedNode in project graal by oracle.
the class ControlFlowGraph method identifyBlocks.
/**
* Identify and connect blocks (including loop backward edges). Predecessors need to be in the
* order expected when iterating phi inputs.
*/
private void identifyBlocks() {
// Find all block headers.
int numBlocks = 0;
for (AbstractBeginNode begin : graph.getNodes(AbstractBeginNode.TYPE)) {
Block block = new Block(begin);
identifyBlock(block);
numBlocks++;
}
// Compute reverse post order.
int count = 0;
NodeMap<Block> nodeMap = this.nodeToBlock;
Block[] stack = new Block[numBlocks];
int tos = 0;
Block startBlock = blockFor(graph.start());
stack[0] = startBlock;
startBlock.setPredecessors(Block.EMPTY_ARRAY);
do {
Block block = stack[tos];
int id = block.getId();
if (id == BLOCK_ID_INITIAL) {
// First time we see this block: push all successors.
FixedNode last = block.getEndNode();
if (last instanceof EndNode) {
EndNode endNode = (EndNode) last;
Block suxBlock = nodeMap.get(endNode.merge());
if (suxBlock.getId() == BLOCK_ID_INITIAL) {
stack[++tos] = suxBlock;
}
block.setSuccessors(new Block[] { suxBlock });
} else if (last instanceof IfNode) {
IfNode ifNode = (IfNode) last;
Block trueSucc = nodeMap.get(ifNode.trueSuccessor());
stack[++tos] = trueSucc;
Block falseSucc = nodeMap.get(ifNode.falseSuccessor());
stack[++tos] = falseSucc;
block.setSuccessors(new Block[] { trueSucc, falseSucc });
Block[] ifPred = new Block[] { block };
trueSucc.setPredecessors(ifPred);
falseSucc.setPredecessors(ifPred);
} else if (last instanceof LoopEndNode) {
LoopEndNode loopEndNode = (LoopEndNode) last;
block.setSuccessors(new Block[] { nodeMap.get(loopEndNode.loopBegin()) });
// Nothing to do push onto the stack.
} else if (last instanceof ControlSinkNode) {
block.setSuccessors(Block.EMPTY_ARRAY);
} else {
assert !(last instanceof AbstractEndNode) : "Algorithm only supports EndNode and LoopEndNode.";
int startTos = tos;
Block[] ifPred = new Block[] { block };
for (Node suxNode : last.successors()) {
Block sux = nodeMap.get(suxNode);
stack[++tos] = sux;
sux.setPredecessors(ifPred);
}
int suxCount = tos - startTos;
Block[] successors = new Block[suxCount];
System.arraycopy(stack, startTos + 1, successors, 0, suxCount);
block.setSuccessors(successors);
}
block.setId(BLOCK_ID_VISITED);
AbstractBeginNode beginNode = block.getBeginNode();
if (beginNode instanceof LoopBeginNode) {
computeLoopPredecessors(nodeMap, block, (LoopBeginNode) beginNode);
} else if (beginNode instanceof MergeNode) {
MergeNode mergeNode = (MergeNode) beginNode;
int forwardEndCount = mergeNode.forwardEndCount();
Block[] predecessors = new Block[forwardEndCount];
for (int i = 0; i < forwardEndCount; ++i) {
predecessors[i] = nodeMap.get(mergeNode.forwardEndAt(i));
}
block.setPredecessors(predecessors);
}
} else if (id == BLOCK_ID_VISITED) {
// Second time we see this block: All successors have been processed, so add block
// to result list. Can safely reuse the stack for this.
--tos;
count++;
int index = numBlocks - count;
stack[index] = block;
block.setId(index);
} else {
throw GraalError.shouldNotReachHere();
}
} while (tos >= 0);
// Compute reverse postorder and number blocks.
assert count == numBlocks : "all blocks must be reachable";
this.reversePostOrder = stack;
}
use of org.graalvm.compiler.nodes.FixedNode in project graal by oracle.
the class ControlFlowGraph method identifyBlock.
private void identifyBlock(Block block) {
FixedWithNextNode cur = block.getBeginNode();
while (true) {
assert !cur.isDeleted();
assert nodeToBlock.get(cur) == null;
nodeToBlock.set(cur, block);
FixedNode next = cur.next();
if (next instanceof AbstractBeginNode) {
block.endNode = cur;
return;
} else if (next instanceof FixedWithNextNode) {
cur = (FixedWithNextNode) next;
} else {
nodeToBlock.set(next, block);
block.endNode = next;
return;
}
}
}
use of org.graalvm.compiler.nodes.FixedNode in project graal by oracle.
the class ValueAnchorNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
while (next() instanceof ValueAnchorNode) {
ValueAnchorNode nextAnchor = (ValueAnchorNode) next();
if (nextAnchor.anchored == anchored || nextAnchor.anchored == null) {
// two anchors for the same anchored -> coalesce
// nothing anchored on the next anchor -> coalesce
nextAnchor.replaceAtUsages(this);
GraphUtil.removeFixedWithUnusedInputs(nextAnchor);
} else {
break;
}
}
if (tool.allUsagesAvailable() && hasNoUsages() && next() instanceof FixedAccessNode) {
FixedAccessNode currentNext = (FixedAccessNode) next();
if (currentNext.getGuard() == anchored) {
GraphUtil.removeFixedWithUnusedInputs(this);
return;
}
}
if (anchored != null && (anchored.isConstant() || anchored instanceof FixedNode)) {
// anchoring fixed nodes and constants is useless
removeAnchoredNode();
}
if (anchored == null && hasNoUsages()) {
// anchor is not necessary any more => remove.
GraphUtil.removeFixedWithUnusedInputs(this);
}
}
use of org.graalvm.compiler.nodes.FixedNode in project graal by oracle.
the class FarReturnLoweredNode method lower.
@Override
public void lower(LoweringTool tool) {
FixedNode originalNext = next();
replaceFirstSuccessor(originalNext, null);
GraphUtil.killCFG(originalNext);
replaceAtPredecessor(graph().add(new FarReturnLoweredNode(result, sp, ip)));
safeDelete();
}
use of org.graalvm.compiler.nodes.FixedNode in project graal by oracle.
the class DefaultHotSpotLoweringProvider method lowerComputeObjectAddressNode.
private static void lowerComputeObjectAddressNode(ComputeObjectAddressNode n) {
/*
* Lower the node into a ComputeObjectAddress node and an Add but ensure that it's below any
* potential safepoints and above it's uses.
*/
for (Node use : n.usages().snapshot()) {
if (use instanceof FixedNode) {
FixedNode fixed = (FixedNode) use;
StructuredGraph graph = n.graph();
GetObjectAddressNode address = graph.add(new GetObjectAddressNode(n.getObject()));
graph.addBeforeFixed(fixed, address);
AddNode add = graph.addOrUnique(new AddNode(address, n.getOffset()));
use.replaceFirstInput(n, add);
} else {
throw GraalError.shouldNotReachHere("Unexpected floating use of ComputeObjectAddressNode " + n);
}
}
GraphUtil.unlinkFixedNode(n);
n.safeDelete();
}
Aggregations