Commit 3bd11fa5 authored by Skylot's avatar Skylot

Improve loops parsing

parent 772c664d
......@@ -92,6 +92,9 @@ public class MarkTryCatchRegions extends AbstractRegionVisitor {
if (tryBlocksMap.isEmpty())
return;
if (!(region instanceof Region))
return;
// search dominator blocks in this region (don't need to go deeper)
for (BlockNode dominator : tryBlocksMap.keySet()) {
if (region.getSubBlocks().contains(dominator)) {
......
......@@ -147,21 +147,31 @@ public class RegionMaker {
InsnNode insn = exit.getInstructions().get(0);
if (insn.getType() == InsnType.IF) {
boolean found = true;
ifnode = (IfNode) insn;
condBlock = exit;
loopRegion = new LoopRegion(curRegion, condBlock, condBlock == loop.getEnd());
if (!loopRegion.isConditionAtEnd() && condBlock != loop.getStart()
&& condBlock.getPredecessors().contains(loopStart)) {
loopRegion.setPreCondition(loopStart);
// if we can't merge pre-condition this is not correct header
if (!loopRegion.checkPreCondition()) {
ifnode = null;
loopRegion = null;
// try another exit
continue;
if (loopRegion.isConditionAtEnd()) {
// TODO: add some checks
} else {
if (condBlock != loop.getStart()) {
if (condBlock.getPredecessors().contains(loopStart)) {
loopRegion.setPreCondition(loopStart);
// if we can't merge pre-condition this is not correct header
found = loopRegion.checkPreCondition();
} else {
found = false;
}
}
}
break;
if (!found) {
ifnode = null;
loopRegion = null;
condBlock = null;
// try another exit
} else
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment