|
|
@ -31,10 +31,10 @@ public class CombineIfGotoExpressions { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
SequentialBlock sequBlock = (SequentialBlock) cb.outer; |
|
|
|
SequentialBlock sequBlock = (SequentialBlock) cb.outer; |
|
|
|
Expression[] e = new Expression[2]; |
|
|
|
Expression firstCond, secondCond; |
|
|
|
|
|
|
|
|
|
|
|
e[1] = cb.getInstruction(); |
|
|
|
secondCond = cb.getInstruction(); |
|
|
|
Expression lastCombined = e[1]; |
|
|
|
Expression lastCombined = secondCond; |
|
|
|
|
|
|
|
|
|
|
|
while (sequBlock.subBlocks[0] instanceof InstructionBlock) { |
|
|
|
while (sequBlock.subBlocks[0] instanceof InstructionBlock) { |
|
|
|
InstructionBlock ib = |
|
|
|
InstructionBlock ib = |
|
|
@ -44,8 +44,9 @@ public class CombineIfGotoExpressions { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
Expression expr = ib.getInstruction(); |
|
|
|
Expression expr = ib.getInstruction(); |
|
|
|
if (!(expr.getOperator() instanceof CombineableOperator) |
|
|
|
if (!(expr instanceof CombineableOperator) |
|
|
|
|| lastCombined.canCombine(expr) + e[1].canCombine(expr) <= 0) |
|
|
|
|| (lastCombined.canCombine((CombineableOperator)expr) |
|
|
|
|
|
|
|
+ secondCond.canCombine((CombineableOperator)expr) <= 0)) |
|
|
|
/* Tricky, the above is true, iff one of the two |
|
|
|
/* Tricky, the above is true, iff one of the two |
|
|
|
* Expressions conflict, or both fail. */ |
|
|
|
* Expressions conflict, or both fail. */ |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -65,12 +66,12 @@ public class CombineIfGotoExpressions { |
|
|
|
int operator; |
|
|
|
int operator; |
|
|
|
if (prevJump.destination == cb.jump.destination) { |
|
|
|
if (prevJump.destination == cb.jump.destination) { |
|
|
|
operator = BinaryOperator.LOG_AND_OP; |
|
|
|
operator = BinaryOperator.LOG_AND_OP; |
|
|
|
e[0] = cbprev.getInstruction().negate(); |
|
|
|
firstCond = cbprev.getInstruction().negate(); |
|
|
|
cb.jump.gen.unionExact(prevJump.gen); |
|
|
|
cb.jump.gen.unionExact(prevJump.gen); |
|
|
|
cb.jump.kill.intersect(prevJump.kill); |
|
|
|
cb.jump.kill.intersect(prevJump.kill); |
|
|
|
} else if (prevJump.destination == cb.trueBlock.jump.destination) { |
|
|
|
} else if (prevJump.destination == cb.trueBlock.jump.destination) { |
|
|
|
operator = BinaryOperator.LOG_OR_OP; |
|
|
|
operator = BinaryOperator.LOG_OR_OP; |
|
|
|
e[0] = cbprev.getInstruction(); |
|
|
|
firstCond = cbprev.getInstruction(); |
|
|
|
cb.trueBlock.jump.gen.unionExact(prevJump.gen); |
|
|
|
cb.trueBlock.jump.gen.unionExact(prevJump.gen); |
|
|
|
cb.trueBlock.jump.kill.intersect(prevJump.kill); |
|
|
|
cb.trueBlock.jump.kill.intersect(prevJump.kill); |
|
|
|
} else |
|
|
|
} else |
|
|
@ -89,15 +90,14 @@ public class CombineIfGotoExpressions { |
|
|
|
|
|
|
|
|
|
|
|
Expression expr = ib.getInstruction(); |
|
|
|
Expression expr = ib.getInstruction(); |
|
|
|
|
|
|
|
|
|
|
|
e[1] = e[1].combine(expr); |
|
|
|
secondCond = secondCond.combine((CombineableOperator) expr); |
|
|
|
sequBlock = (SequentialBlock) sequBlock.outer; |
|
|
|
sequBlock = (SequentialBlock) sequBlock.outer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cb.flowBlock.removeSuccessor(prevJump); |
|
|
|
cb.flowBlock.removeSuccessor(prevJump); |
|
|
|
prevJump.prev.removeJump(); |
|
|
|
prevJump.prev.removeJump(); |
|
|
|
Expression cond = |
|
|
|
Expression cond = new BinaryOperator(Type.tBoolean, operator) |
|
|
|
new ComplexExpression |
|
|
|
.addOperand(secondCond).addOperand(firstCond); |
|
|
|
(new BinaryOperator(Type.tBoolean, operator), e); |
|
|
|
|
|
|
|
cb.setInstruction(cond); |
|
|
|
cb.setInstruction(cond); |
|
|
|
cb.moveDefinitions(sequBlock, last); |
|
|
|
cb.moveDefinitions(sequBlock, last); |
|
|
|
last.replace(sequBlock); |
|
|
|
last.replace(sequBlock); |
|
|
|