def find_top_level_loops(cfg):
 blocks_in_loop = set()
 for loop in cfg.loops().values():
  insiders = ((set(loop.body) | set(loop.entries)) | set(loop.exits))
  insiders.discard(loop.header)
  blocks_in_loop |= insiders
 for loop in cfg.loops().values():
  if (loop.header not in blocks_in_loop):
   (yield loop)

def find_top_level_loops ( cfg ) : blocks_in_loop = set ( ) for loop in cfg . loops ( ) . values ( ) : insiders = ( ( set ( loop . body ) | set ( loop . entries ) ) | set ( loop . exits ) ) insiders . discard ( loop . header ) blocks_in_loop |= insiders for loop in cfg . loops ( ) . values ( ) : if ( loop . header not in blocks_in_loop ) : ( yield loop )
a generator that yields toplevel loops given a control-flow-graph .