private void CoalesceFrom(BasicBlock origHead, Set <BasicBlock> group, BasicBlock newBlock, Set <BasicBlock> visited) { if (!visited.Contains(this)) { visited.Add(this); FixupTargets(origHead, newBlock); if (Equals(newBlock)) { foreach (var s in origHead.Sources) { if (!group.Contains(s)) { newBlock.Sources.Add(s); } } } else { for (var i = 0; i < Sources.Count; i++) { if (group.Contains(Sources[i])) { Sources.RemoveAt(i--); } } } if (newBlock.Targets.Contains(this)) { Sources.Add(newBlock); } foreach (var t in Targets) { if (group.Contains(t)) { throw new InvalidOperationException ("existing basic block has target strictly within group being removed"); } t.CoalesceFrom(origHead, group, newBlock, visited); } } }