use of org.graalvm.compiler.nodes.ValuePhiNode in project graal by oracle.
the class CFGPrinter method scheduleInputs.
private void scheduleInputs(Node node, Block nodeBlock) {
if (node instanceof ValuePhiNode) {
PhiNode phi = (PhiNode) node;
Block phiBlock = latestScheduling.get(phi.merge());
assert phiBlock != null;
for (Block pred : phiBlock.getPredecessors()) {
schedule(phi.valueAt((AbstractEndNode) pred.getEndNode()), pred);
}
} else {
for (Node input : node.inputs()) {
schedule(input, nodeBlock);
}
}
}
use of org.graalvm.compiler.nodes.ValuePhiNode in project graal by oracle.
the class CFGPrinter method printNode.
private void printNode(Node node, boolean unscheduled) {
assert !printedNodes.isMarked(node);
printedNodes.mark(node);
if (!(node instanceof ValuePhiNode)) {
for (Node input : node.inputs()) {
if (!inFixedSchedule(input) && !printedNodes.isMarked(input)) {
printNode(input, true);
}
}
}
if (unscheduled) {
assert lir == null && schedule == null : "unscheduled nodes can only be present before LIR generation";
out.print("f ").print(HOVER_START).print("u").print(HOVER_SEP).print("unscheduled").print(HOVER_END).println(COLUMN_END);
} else if (node instanceof FixedWithNextNode) {
out.print("f ").print(HOVER_START).print("#").print(HOVER_SEP).print("fixed with next").print(HOVER_END).println(COLUMN_END);
} else if (node instanceof FixedNode) {
out.print("f ").print(HOVER_START).print("*").print(HOVER_SEP).print("fixed").print(HOVER_END).println(COLUMN_END);
} else if (node instanceof FloatingNode) {
out.print("f ").print(HOVER_START).print("~").print(HOVER_SEP).print("floating").print(HOVER_END).println(COLUMN_END);
}
out.print("tid ").print(nodeToString(node)).println(COLUMN_END);
if (nodeLirGenerator != null) {
Value operand = nodeLirGenerator.hasOperand(node) ? nodeLirGenerator.operand(node) : null;
if (operand != null) {
out.print("result ").print(operand.toString()).println(COLUMN_END);
}
}
if (node instanceof StateSplit) {
StateSplit stateSplit = (StateSplit) node;
if (stateSplit.stateAfter() != null) {
String state = stateToString(stateSplit.stateAfter());
out.print("st ").print(HOVER_START).print("st").print(HOVER_SEP).print(state).print(HOVER_END).println(COLUMN_END);
}
}
Map<Object, Object> props = new TreeMap<>(node.getDebugProperties());
out.print("d ").print(HOVER_START).print("d").print(HOVER_SEP);
out.println("=== Debug Properties ===");
for (Map.Entry<Object, Object> entry : props.entrySet()) {
out.print(entry.getKey().toString()).print(": ").print(entry.getValue() == null ? "[null]" : entry.getValue().toString()).println();
}
out.println("=== Inputs ===");
printNamedNodes(node, node.inputPositions().iterator(), "", "\n", null);
out.println("=== Succesors ===");
printNamedNodes(node, node.successorPositions().iterator(), "", "\n", null);
out.println("=== Usages ===");
if (!node.hasNoUsages()) {
for (Node usage : node.usages()) {
out.print(nodeToString(usage)).print(" ");
}
out.println();
}
out.println("=== Predecessor ===");
out.print(nodeToString(node.predecessor())).print(" ");
out.print(HOVER_END).println(COLUMN_END);
out.print("instruction ");
out.print(HOVER_START).print(node.getNodeClass().shortName()).print(HOVER_SEP).print(node.getClass().getName()).print(HOVER_END).print(" ");
printNamedNodes(node, node.inputPositions().iterator(), "", "", "#NDF");
printNamedNodes(node, node.successorPositions().iterator(), "#", "", "#NDF");
for (Map.Entry<Object, Object> entry : props.entrySet()) {
String key = entry.getKey().toString();
if (key.startsWith("data.") && !key.equals("data.stamp")) {
out.print(key.substring("data.".length())).print(": ").print(entry.getValue() == null ? "[null]" : entry.getValue().toString()).print(" ");
}
}
out.print(COLUMN_END).print(' ').println(COLUMN_END);
}
use of org.graalvm.compiler.nodes.ValuePhiNode in project graal by oracle.
the class UseTrappingNullChecksPhase method tryUseTrappingNullCheck.
private static void tryUseTrappingNullCheck(MetaAccessProvider metaAccessProvider, DynamicDeoptimizeNode deopt, long implicitNullCheckLimit) {
Node predecessor = deopt.predecessor();
if (predecessor instanceof AbstractMergeNode) {
AbstractMergeNode merge = (AbstractMergeNode) predecessor;
// Process each predecessor at the merge, unpacking the reasons and speculations as
// needed.
ValueNode reason = deopt.getActionAndReason();
ValuePhiNode reasonPhi = null;
List<ValueNode> reasons = null;
int expectedPhis = 0;
if (reason instanceof ValuePhiNode) {
reasonPhi = (ValuePhiNode) reason;
if (reasonPhi.merge() != merge) {
return;
}
reasons = reasonPhi.values().snapshot();
expectedPhis++;
} else if (!reason.isConstant()) {
return;
}
ValueNode speculation = deopt.getSpeculation();
ValuePhiNode speculationPhi = null;
List<ValueNode> speculations = null;
if (speculation instanceof ValuePhiNode) {
speculationPhi = (ValuePhiNode) speculation;
if (speculationPhi.merge() != merge) {
return;
}
speculations = speculationPhi.values().snapshot();
expectedPhis++;
}
if (merge.phis().count() != expectedPhis) {
return;
}
int index = 0;
for (AbstractEndNode end : merge.cfgPredecessors().snapshot()) {
ValueNode thisReason = reasons != null ? reasons.get(index) : reason;
ValueNode thisSpeculation = speculations != null ? speculations.get(index++) : speculation;
if (!thisReason.isConstant() || !thisSpeculation.isConstant() || !thisSpeculation.asConstant().equals(JavaConstant.NULL_POINTER)) {
continue;
}
DeoptimizationReason deoptimizationReason = metaAccessProvider.decodeDeoptReason(thisReason.asJavaConstant());
tryUseTrappingNullCheck(deopt, end.predecessor(), deoptimizationReason, null, implicitNullCheckLimit);
}
}
}
use of org.graalvm.compiler.nodes.ValuePhiNode in project graal by oracle.
the class ValueMergeUtil method mergeValueProducers.
public static <T> ValueNode mergeValueProducers(AbstractMergeNode merge, List<? extends T> valueProducers, Function<T, FixedWithNextNode> lastInstrFunction, Function<T, ValueNode> valueFunction) {
ValueNode singleResult = null;
PhiNode phiResult = null;
for (T valueProducer : valueProducers) {
ValueNode result = valueFunction.apply(valueProducer);
if (result != null) {
if (phiResult == null && (singleResult == null || singleResult == result)) {
/* Only one result value, so no need yet for a phi node. */
singleResult = result;
} else if (phiResult == null) {
/* Found a second result value, so create phi node. */
phiResult = merge.graph().addWithoutUnique(new ValuePhiNode(result.stamp(NodeView.DEFAULT).unrestricted(), merge));
for (int i = 0; i < merge.forwardEndCount(); i++) {
phiResult.addInput(singleResult);
}
phiResult.addInput(result);
} else {
/* Multiple return values, just add to existing phi node. */
phiResult.addInput(result);
}
}
// create and wire up a new EndNode
EndNode endNode = merge.graph().add(new EndNode());
merge.addForwardEnd(endNode);
if (lastInstrFunction == null) {
assert valueProducer instanceof ReturnNode || valueProducer instanceof UnwindNode;
((ControlSinkNode) valueProducer).replaceAndDelete(endNode);
} else {
FixedWithNextNode lastInstr = lastInstrFunction.apply(valueProducer);
lastInstr.setNext(endNode);
}
}
if (phiResult != null) {
assert phiResult.verify();
phiResult.inferStamp();
return phiResult;
} else {
return singleResult;
}
}
Aggregations