def dominance_frontiers(G, start):
 idom = nx.immediate_dominators(G, start)
 df = {u: set() for u in idom}
 for u in idom:
  if (len(G.pred[u]) >= 2):
   for v in G.pred[u]:
    if (v in idom):
     while (v != idom[u]):
      df[v].add(u)
      v = idom[v]
 return df

def dominance_frontiers ( G , start ) : idom = nx . immediate_dominators ( G , start ) df = { u : set ( ) for u in idom } for u in idom : if ( len ( G . pred [ u ] ) >= 2 ) : for v in G . pred [ u ] : if ( v in idom ) : while ( v != idom [ u ] ) : df [ v ] . add ( u ) v = idom [ v ] return df
returns the dominance frontiers of all nodes of a directed graph .