exit block refactored
@@ -27,11 +27,12 @@ package tornado.drivers.opencl.graal.compiler;
import java.util.HashSet;
import java.util.Set;
-import org.graalvm.compiler.nodes.AbstractBeginNode;
+
import org.graalvm.compiler.nodes.IfNode;
import org.graalvm.compiler.nodes.MergeNode;
import org.graalvm.compiler.nodes.cfg.Block;
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
+
import tornado.drivers.opencl.graal.asm.OCLAssembler;
public class OCLBlockVisitor implements ControlFlowGraph.RecursiveVisitor<Block> {
@@ -65,8 +66,8 @@ public class OCLBlockVisitor implements ControlFlowGraph.RecursiveVisitor<Block>
&& !isMerge
&& !dom.isLoopHeader()
&& isIfBlock(dom)) {
- final IfNode condition = (IfNode) dom.getEndNode();
- if (condition.falseSuccessor() == b.getBeginNode()) {
+ final IfNode ifNode = (IfNode) dom.getEndNode();
+ if (ifNode.falseSuccessor() == b.getBeginNode()) {
asm.indent();
asm.elseStmt();
asm.eol();
@@ -98,15 +99,17 @@ public class OCLBlockVisitor implements ControlFlowGraph.RecursiveVisitor<Block>
asm.endScope();
}
} else {
- final Block dom = b.getDominator();
- boolean isMerge = b.getBeginNode() instanceof MergeNode;
+ closeIfBlock(b);
+ }
+ }
+
+ private void closeIfBlock(Block block) {
+ final Block dom = block.getDominator();
+ boolean isMerge = block.getBeginNode() instanceof MergeNode;
if (dom != null && !isMerge && !dom.isLoopHeader() && isIfBlock(dom)) {
- final IfNode condition = (IfNode) dom.getEndNode();
- if (condition.falseSuccessor() == b.getBeginNode()) {
+ final IfNode ifNode = (IfNode) dom.getEndNode();
+ if ((ifNode.falseSuccessor() == block.getBeginNode()) || (ifNode.trueSuccessor() == block.getBeginNode())) {
asm.endScope();
- } else if (condition.trueSuccessor() == b.getBeginNode()) {
- asm.endScope();
- }
}
}
}
