private void BreakReduceLeaveCatch(BasicBlock root, BBLoop loop, BasicBlock breakTarget, LeaveCatchBasicBlock leavebb, Seq<BasicBlock> removed, Seq<BasicBlock> added) { if (leavebb.Target.Equals(breakTarget)) { var instructions = leavebb.Block.CopyContents(); var lci = new BreakContinueInstruction(NextInstructionId--, BreakContinueOp.Break, loop.Label) { BeforeState = leavebb.Block.AfterState, AfterState = leavebb.Block.AfterState }; instructions.Add(lci); var newbb = new NonReturningBasicBlock(nextBlockId++, new Instructions(leavebb.Block.BeforeState, instructions)); root.Coalesce(leavebb, new Set<BasicBlock> { leavebb }, newbb); removed.Add(leavebb); added.Add(newbb); } }
private void BreakReduceBranch(BasicBlock root, BBLoop loop, BasicBlock breakTarget, BranchBasicBlock branchbb, Seq<BasicBlock> removed, Seq<BasicBlock> added) { var beforeState = branchbb.Block.BeforeState; var afterState = branchbb.Block.AfterState; if (branchbb.Target.Equals(breakTarget) && !branchbb.Fallthrough.Equals(breakTarget)) { var instructions = branchbb.Block.CopyContents(); branchbb.Test.Eval(instructions, afterState, branchbb.Target.Block.BeforeState, BottomPT); var cond = SeparateCondition(beforeState, ref instructions); var lci = new BreakContinueInstruction(NextInstructionId--, BreakContinueOp.Break, loop.Label) { BeforeState = afterState, AfterState = afterState }; var itei = new IfThenElseInstruction(NextInstructionId--, cond, new Instructions(lci), null) { BeforeState = beforeState, AfterState = afterState }; instructions.Add(itei); var newbb = new JumpBasicBlock(nextBlockId++, new Instructions(beforeState, instructions), branchbb.Fallthrough); root.Coalesce(branchbb, new Set<BasicBlock> { branchbb }, newbb); removed.Add(branchbb); added.Add(newbb); } else if (branchbb.Fallthrough.Equals(breakTarget) && !branchbb.Target.Equals(breakTarget)) { var instructions = branchbb.Block.CopyContents(); branchbb.Test.Negate().Eval (instructions, afterState, branchbb.Fallthrough.Block.BeforeState, BottomPT); var cond = SeparateCondition(beforeState, ref instructions); var lci = new BreakContinueInstruction(NextInstructionId--, BreakContinueOp.Break, loop.Label) { BeforeState = afterState, AfterState = afterState }; var itei = new IfThenElseInstruction(NextInstructionId--, cond, new Instructions(lci), null) { BeforeState = beforeState, AfterState = afterState }; instructions.Add(itei); var newbb = new JumpBasicBlock(nextBlockId++, new Instructions(beforeState, instructions), branchbb.Target); root.Coalesce(branchbb, new Set<BasicBlock> { branchbb }, newbb); removed.Add(branchbb); added.Add(newbb); } }
private string ContinueReduceLeaveTry(BasicBlock root, BBLoop loop, LeaveTryBasicBlock leavebb) { if (leavebb.Target.Equals(loop.ContinueTarget) && leavebb.HandlerPopCount == 1) { var instructions = leavebb.Block.CopyContents(); var lci = new BreakContinueInstruction(NextInstructionId--, BreakContinueOp.Continue, loop.Label) { BeforeState = leavebb.Block.AfterState, AfterState = leavebb.Block.AfterState }; instructions.Add(lci); var newbb = new NonReturningBasicBlock(nextBlockId++, new Instructions(leavebb.Block.BeforeState, instructions)); root.Coalesce(leavebb, new Set<BasicBlock> { leavebb }, newbb); return String.Format ("continue from leave try at B{0} within loop from B{1}", leavebb.Id, loop.Head.Id); } return null; }
private string ContinueReduceBranch(BasicBlock root, BBLoop loop, BranchBasicBlock branchbb) { var beforeState = branchbb.Block.BeforeState; var afterState = branchbb.Block.AfterState; if (branchbb.Target.Equals(loop.ContinueTarget) && !branchbb.Fallthrough.Equals(loop.ContinueTarget) && loop.ContinueTarget.Sources.Count > 1) { var instructions = branchbb.Block.CopyContents(); branchbb.Test.Eval (instructions, afterState, branchbb.Target.Block.BeforeState, BottomPT); var cond = SeparateCondition(beforeState, ref instructions); var lci = new BreakContinueInstruction(NextInstructionId--, BreakContinueOp.Continue, loop.Label) { BeforeState = afterState, AfterState = afterState }; var ifei = new IfThenElseInstruction(-1, cond, new Instructions(lci), null) { BeforeState = beforeState, AfterState = afterState }; instructions.Add(ifei); var newbb = new JumpBasicBlock (nextBlockId++, new Instructions(beforeState, instructions), branchbb.Fallthrough); root.Coalesce(branchbb, new Set<BasicBlock> { branchbb }, newbb); return String.Format("continue from branch at B{0} within loop from B{1}", branchbb.Id, loop.Head.Id); } if (branchbb.Fallthrough.Equals(loop.ContinueTarget) && !branchbb.Target.Equals(loop.ContinueTarget) && loop.ContinueTarget.Sources.Count > 1) { var instructions = branchbb.Block.CopyContents(); branchbb.Test.Negate().Eval (instructions, afterState, branchbb.Fallthrough.Block.BeforeState, BottomPT); var cond = SeparateCondition(beforeState, ref instructions); var lci = new BreakContinueInstruction(NextInstructionId--, BreakContinueOp.Continue, loop.Label) { BeforeState = afterState, AfterState = afterState }; var ifei = new IfThenElseInstruction(NextInstructionId--, cond, new Instructions(lci), null) { BeforeState = beforeState, AfterState = afterState }; instructions.Add(ifei); var newbb = new JumpBasicBlock(nextBlockId++, new Instructions(beforeState, instructions), branchbb.Target); root.Coalesce(branchbb, new Set<BasicBlock> { branchbb }, newbb); return String.Format ("continue from branch (flipped) at B{0} within loop from B{1}", branchbb.Id, loop.Head.Id); } return null; }
private string ContinueReduceJump(BasicBlock root, BBLoop loop, JumpBasicBlock jumpbb) { if (jumpbb.Target.Equals(loop.ContinueTarget) && jumpbb.Block.AfterState.Depth == 0 && loop.ContinueTarget.Sources.Count > 1) { var instructions = jumpbb.Block.CopyContents(); var lci = new BreakContinueInstruction(NextInstructionId--, BreakContinueOp.Continue, loop.Label) { BeforeState = jumpbb.Block.AfterState, AfterState = jumpbb.Block.AfterState }; instructions.Add(lci); var newbb = new NonReturningBasicBlock (nextBlockId++, new Instructions(jumpbb.Block.BeforeState, instructions)); root.Coalesce(jumpbb, new Set<BasicBlock> { jumpbb }, newbb); return String.Format("continue from jump at B{0} within loop from B{1}", jumpbb.Id, loop.Head.Id); } return null; }