Search in sources :

Example 1 with SwitchNode

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

the class LoopTransformations method findUnswitchable.

public static List<ControlSplitNode> findUnswitchable(LoopEx loop) {
    List<ControlSplitNode> controls = null;
    ValueNode invariantValue = null;
    for (IfNode ifNode : loop.whole().nodes().filter(IfNode.class)) {
        if (loop.isOutsideLoop(ifNode.condition())) {
            if (controls == null) {
                invariantValue = ifNode.condition();
                controls = new ArrayList<>();
                controls.add(ifNode);
            } else if (ifNode.condition() == invariantValue) {
                controls.add(ifNode);
            }
        }
    }
    if (controls == null) {
        SwitchNode firstSwitch = null;
        for (SwitchNode switchNode : loop.whole().nodes().filter(SwitchNode.class)) {
            if (switchNode.successors().count() > 1 && loop.isOutsideLoop(switchNode.value())) {
                if (controls == null) {
                    firstSwitch = switchNode;
                    invariantValue = switchNode.value();
                    controls = new ArrayList<>();
                    controls.add(switchNode);
                } else if (switchNode.value() == invariantValue && firstSwitch.structureEquals(switchNode)) {
                    // Only collect switches which test the same values in the same order
                    controls.add(switchNode);
                }
            }
        }
    }
    return controls;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) IfNode(org.graalvm.compiler.nodes.IfNode) SwitchNode(org.graalvm.compiler.nodes.extended.SwitchNode)

Aggregations

ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)1 IfNode (org.graalvm.compiler.nodes.IfNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 SwitchNode (org.graalvm.compiler.nodes.extended.SwitchNode)1