示例#1
0
 public static void MergeBasicBlocks(ControlFlowGraph graph)
 {
     while (true)
     {
         bool merged = false;
         foreach (BasicBlock block in graph.GetBlocks())
         {
             InstructionSequence seq = block.GetSeq();
             if (block.GetSuccs().Count == 1)
             {
                 BasicBlock next = block.GetSuccs()[0];
                 if (next != graph.GetLast() && (seq.IsEmpty() || seq.GetLastInstr().group != ICodeConstants
                                                 .Group_Switch))
                 {
                     if (next.GetPreds().Count == 1 && (next.GetPredExceptions().Count == 0) && next !=
                         graph.GetFirst())
                     {
                         // TODO: implement a dummy start block
                         bool sameRanges = true;
                         foreach (ExceptionRangeCFG range in graph.GetExceptions())
                         {
                             if (range.GetProtectedRange().Contains(block) ^ range.GetProtectedRange().Contains
                                     (next))
                             {
                                 sameRanges = false;
                                 break;
                             }
                         }
                         if (sameRanges)
                         {
                             seq.AddSequence(next.GetSeq());
                             Sharpen.Collections.AddAll(block.GetInstrOldOffsets(), next.GetInstrOldOffsets());
                             next.GetSeq().Clear();
                             RemoveEmptyBlock(graph, next, true);
                             merged = true;
                             break;
                         }
                     }
                 }
             }
         }
         if (!merged)
         {
             break;
         }
     }
 }