Commit 3bd11fa5 authored by Skylot's avatar Skylot

Improve loops parsing

parent 772c664d
...@@ -92,6 +92,9 @@ public class MarkTryCatchRegions extends AbstractRegionVisitor { ...@@ -92,6 +92,9 @@ public class MarkTryCatchRegions extends AbstractRegionVisitor {
if (tryBlocksMap.isEmpty()) if (tryBlocksMap.isEmpty())
return; return;
if (!(region instanceof Region))
return;
// search dominator blocks in this region (don't need to go deeper) // search dominator blocks in this region (don't need to go deeper)
for (BlockNode dominator : tryBlocksMap.keySet()) { for (BlockNode dominator : tryBlocksMap.keySet()) {
if (region.getSubBlocks().contains(dominator)) { if (region.getSubBlocks().contains(dominator)) {
......
...@@ -147,21 +147,31 @@ public class RegionMaker { ...@@ -147,21 +147,31 @@ public class RegionMaker {
InsnNode insn = exit.getInstructions().get(0); InsnNode insn = exit.getInstructions().get(0);
if (insn.getType() == InsnType.IF) { if (insn.getType() == InsnType.IF) {
boolean found = true;
ifnode = (IfNode) insn; ifnode = (IfNode) insn;
condBlock = exit; condBlock = exit;
loopRegion = new LoopRegion(curRegion, condBlock, condBlock == loop.getEnd()); loopRegion = new LoopRegion(curRegion, condBlock, condBlock == loop.getEnd());
if (!loopRegion.isConditionAtEnd() && condBlock != loop.getStart()
&& condBlock.getPredecessors().contains(loopStart)) { if (loopRegion.isConditionAtEnd()) {
loopRegion.setPreCondition(loopStart); // TODO: add some checks
// if we can't merge pre-condition this is not correct header } else {
if (!loopRegion.checkPreCondition()) { if (condBlock != loop.getStart()) {
ifnode = null; if (condBlock.getPredecessors().contains(loopStart)) {
loopRegion = null; loopRegion.setPreCondition(loopStart);
// try another exit // if we can't merge pre-condition this is not correct header
continue; 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