|
24 | 24 | */
|
25 | 25 | package jdk.graal.compiler.phases.common;
|
26 | 26 |
|
| 27 | +import java.util.ArrayDeque; |
| 28 | +import java.util.Deque; |
27 | 29 | import java.util.ListIterator;
|
28 | 30 | import java.util.Optional;
|
29 | 31 |
|
|
67 | 69 | import jdk.graal.compiler.nodes.StructuredGraph.ScheduleResult;
|
68 | 70 | import jdk.graal.compiler.nodes.UnaryOpLogicNode;
|
69 | 71 | import jdk.graal.compiler.nodes.ValueNode;
|
| 72 | +import jdk.graal.compiler.nodes.ValueNodeInterface; |
70 | 73 | import jdk.graal.compiler.nodes.ValuePhiNode;
|
71 | 74 | import jdk.graal.compiler.nodes.calc.BinaryNode;
|
72 | 75 | import jdk.graal.compiler.nodes.calc.ConditionalNode;
|
|
76 | 79 | import jdk.graal.compiler.nodes.cfg.HIRBlock;
|
77 | 80 | import jdk.graal.compiler.nodes.extended.GuardingNode;
|
78 | 81 | import jdk.graal.compiler.nodes.extended.IntegerSwitchNode;
|
| 82 | +import jdk.graal.compiler.nodes.extended.MultiGuardNode; |
79 | 83 | import jdk.graal.compiler.nodes.memory.FixedAccessNode;
|
80 | 84 | import jdk.graal.compiler.nodes.memory.FloatingAccessNode;
|
81 | 85 | import jdk.graal.compiler.nodes.memory.FloatingReadNode;
|
@@ -706,17 +710,39 @@ public static boolean verifyPiRemovalInvariants(StructuredGraph graph) {
|
706 | 710 | // floating guarded nodes without a guard are "universally" true meaning they
|
707 | 711 | // can be executed everywhere
|
708 | 712 | final GuardingNode guard = ((FloatingGuardedNode) n).getGuard();
|
709 |
| - final boolean isUniversallyTrue = guard == null; |
710 |
| - if (!isUniversallyTrue) { |
711 |
| - assert guard instanceof FixedNode : Assertions.errorMessage( |
712 |
| - "Should not have floating guarded nodes without fixed guards left after removing pis, they could float uncontrolled now", n); |
713 |
| - } |
| 713 | + assert verifyOnlyFixedGuards(guard); |
714 | 714 | }
|
715 | 715 | }
|
716 | 716 | }
|
717 | 717 | return true;
|
718 | 718 | }
|
719 | 719 |
|
| 720 | + private static boolean verifyOnlyFixedGuards(ValueNodeInterface guardingRoot) { |
| 721 | + final boolean isUniversallyTrue = guardingRoot == null; |
| 722 | + if (isUniversallyTrue) { |
| 723 | + return true; |
| 724 | + } |
| 725 | + final StructuredGraph graph = guardingRoot.asNode().graph(); |
| 726 | + NodeBitMap visited = graph.createNodeBitMap(); |
| 727 | + Deque<ValueNodeInterface> toVisit = new ArrayDeque<>(); |
| 728 | + toVisit.add(guardingRoot); |
| 729 | + |
| 730 | + while (!toVisit.isEmpty()) { |
| 731 | + ValueNodeInterface currentGuard = toVisit.pop(); |
| 732 | + if (visited.isMarked(currentGuard.asNode())) { |
| 733 | + continue; |
| 734 | + } |
| 735 | + visited.mark(currentGuard.asNode()); |
| 736 | + if (currentGuard instanceof MultiGuardNode mg) { |
| 737 | + toVisit.addAll(mg.getGuards()); |
| 738 | + } else { |
| 739 | + assert currentGuard instanceof FixedNode : Assertions.errorMessage( |
| 740 | + "Should not have floating guarded nodes without fixed guards left after removing pis, they could float uncontrolled now", currentGuard); |
| 741 | + } |
| 742 | + } |
| 743 | + return true; |
| 744 | + } |
| 745 | + |
720 | 746 | @Override
|
721 | 747 | public void updateGraphState(GraphState graphState) {
|
722 | 748 | super.updateGraphState(graphState);
|
|
0 commit comments