Search in sources :

Example 6 with FullInfopointNode

use of org.graalvm.compiler.nodes.FullInfopointNode in project graal by oracle.

the class LoopEx method detectCounted.

public boolean detectCounted() {
    LoopBeginNode loopBegin = loopBegin();
    FixedNode next = loopBegin.next();
    while (next instanceof FixedGuardNode || next instanceof ValueAnchorNode || next instanceof FullInfopointNode) {
        next = ((FixedWithNextNode) next).next();
    }
    if (next instanceof IfNode) {
        IfNode ifNode = (IfNode) next;
        boolean negated = false;
        if (!loopBegin.isLoopExit(ifNode.falseSuccessor())) {
            if (!loopBegin.isLoopExit(ifNode.trueSuccessor())) {
                return false;
            }
            negated = true;
        }
        LogicNode ifTest = ifNode.condition();
        if (!(ifTest instanceof IntegerLessThanNode) && !(ifTest instanceof IntegerEqualsNode)) {
            if (ifTest instanceof IntegerBelowNode) {
                ifTest.getDebug().log("Ignored potential Counted loop at %s with |<|", loopBegin);
            }
            return false;
        }
        CompareNode lessThan = (CompareNode) ifTest;
        Condition condition = null;
        InductionVariable iv = null;
        ValueNode limit = null;
        if (isOutsideLoop(lessThan.getX())) {
            iv = getInductionVariables().get(lessThan.getY());
            if (iv != null) {
                condition = lessThan.condition().asCondition().mirror();
                limit = lessThan.getX();
            }
        } else if (isOutsideLoop(lessThan.getY())) {
            iv = getInductionVariables().get(lessThan.getX());
            if (iv != null) {
                condition = lessThan.condition().asCondition();
                limit = lessThan.getY();
            }
        }
        if (condition == null) {
            return false;
        }
        if (negated) {
            condition = condition.negate();
        }
        boolean oneOff = false;
        switch(condition) {
            case EQ:
                return false;
            case NE:
                {
                    if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1) {
                        return false;
                    }
                    IntegerStamp initStamp = (IntegerStamp) iv.initNode().stamp(NodeView.DEFAULT);
                    IntegerStamp limitStamp = (IntegerStamp) limit.stamp(NodeView.DEFAULT);
                    if (iv.direction() == Direction.Up) {
                        if (initStamp.upperBound() > limitStamp.lowerBound()) {
                            return false;
                        }
                    } else if (iv.direction() == Direction.Down) {
                        if (initStamp.lowerBound() < limitStamp.upperBound()) {
                            return false;
                        }
                    } else {
                        return false;
                    }
                    break;
                }
            case LE:
                oneOff = true;
                if (iv.direction() != Direction.Up) {
                    return false;
                }
                break;
            case LT:
                if (iv.direction() != Direction.Up) {
                    return false;
                }
                break;
            case GE:
                oneOff = true;
                if (iv.direction() != Direction.Down) {
                    return false;
                }
                break;
            case GT:
                if (iv.direction() != Direction.Down) {
                    return false;
                }
                break;
            default:
                throw GraalError.shouldNotReachHere();
        }
        counted = new CountedLoopInfo(this, iv, ifNode, limit, oneOff, negated ? ifNode.falseSuccessor() : ifNode.trueSuccessor());
        return true;
    }
    return false;
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Example 7 with FullInfopointNode

use of org.graalvm.compiler.nodes.FullInfopointNode in project graal by oracle.

the class GraalCompilerTest method getCanonicalGraphString.

protected static String getCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants) {
    SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.EARLIEST);
    schedule.apply(graph);
    ScheduleResult scheduleResult = graph.getLastSchedule();
    NodeMap<Integer> canonicalId = graph.createNodeMap();
    int nextId = 0;
    List<String> constantsLines = new ArrayList<>();
    StringBuilder result = new StringBuilder();
    for (Block block : scheduleResult.getCFG().getBlocks()) {
        result.append("Block ").append(block).append(' ');
        if (block == scheduleResult.getCFG().getStartBlock()) {
            result.append("* ");
        }
        result.append("-> ");
        for (Block succ : block.getSuccessors()) {
            result.append(succ).append(' ');
        }
        result.append('\n');
        for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
            if (node instanceof ValueNode && node.isAlive()) {
                if (!excludeVirtual || !(node instanceof VirtualObjectNode || node instanceof ProxyNode || node instanceof FullInfopointNode || node instanceof ParameterNode)) {
                    if (node instanceof ConstantNode) {
                        String name = checkConstants ? node.toString(Verbosity.Name) : node.getClass().getSimpleName();
                        if (excludeVirtual) {
                            constantsLines.add(name);
                        } else {
                            constantsLines.add(name + "    (" + filteredUsageCount(node) + ")");
                        }
                    } else {
                        int id;
                        if (canonicalId.get(node) != null) {
                            id = canonicalId.get(node);
                        } else {
                            id = nextId++;
                            canonicalId.set(node, id);
                        }
                        String name = node.getClass().getSimpleName();
                        result.append("  ").append(id).append('|').append(name);
                        if (node instanceof AccessFieldNode) {
                            result.append('#');
                            result.append(((AccessFieldNode) node).field());
                        }
                        if (!excludeVirtual) {
                            result.append("    (");
                            result.append(filteredUsageCount(node));
                            result.append(')');
                        }
                        result.append('\n');
                    }
                }
            }
        }
    }
    StringBuilder constantsLinesResult = new StringBuilder();
    constantsLinesResult.append(constantsLines.size()).append(" constants:\n");
    Collections.sort(constantsLines);
    for (String s : constantsLines) {
        constantsLinesResult.append(s);
        constantsLinesResult.append('\n');
    }
    return constantsLinesResult.toString() + result.toString();
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) BreakpointNode(org.graalvm.compiler.nodes.BreakpointNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) AccessFieldNode(org.graalvm.compiler.nodes.java.AccessFieldNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ArrayList(java.util.ArrayList) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AccessFieldNode(org.graalvm.compiler.nodes.java.AccessFieldNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Block(org.graalvm.compiler.nodes.cfg.Block)

Aggregations

FullInfopointNode (org.graalvm.compiler.nodes.FullInfopointNode)7 Node (org.graalvm.compiler.graph.Node)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 FixedNode (org.graalvm.compiler.nodes.FixedNode)3 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)3 Block (org.graalvm.compiler.nodes.cfg.Block)3 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)3 ArrayList (java.util.ArrayList)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)2 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)2 PhiNode (org.graalvm.compiler.nodes.PhiNode)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 ScheduleResult (org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)2 SchedulePhase (org.graalvm.compiler.phases.schedule.SchedulePhase)2 AssertValueNode (com.oracle.svm.hosted.nodes.AssertValueNode)1 List (java.util.List)1 Infopoint (jdk.vm.ci.code.site.Infopoint)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1