···2525 in
2626 find strict_doms
27272828+let rev_postorder cfg =
2929+ let visited = ref IntSet.empty in
3030+ let order = ref [] in
3131+ let rec dfs id =
3232+ if IntSet.mem id !visited then ()
3333+ else begin
3434+ visited := IntSet.add id !visited;
3535+ let b = IntMap.find id cfg.blocks in
3636+ List.iter dfs b.succs;
3737+ order := id :: !order
3838+ end
3939+ in
4040+ dfs cfg.entry;
4141+ let remaining = IntMap.fold (fun k _ acc ->
4242+ if IntSet.mem k !visited then acc else k :: acc
4343+ ) cfg.blocks [] in
4444+ !order @ remaining
4545+2846let dominators cfg =
2947 let all = IntMap.fold (fun k _ s -> IntSet.add k s) cfg.blocks IntSet.empty in
3048 let init = IntSet.singleton cfg.entry in
4949+ let rpo = rev_postorder cfg in
3150 let rec fixpoint doms =
3232- let new_doms = IntMap.mapi (fun id _ ->
3333- if id = cfg.entry then init
5151+ let new_doms = List.fold_left (fun acc id ->
5252+ if id = cfg.entry then IntMap.add id init acc
3453 else
3554 let b = IntMap.find id cfg.blocks in
3655 match b.preds with
3737- | [] -> IntSet.empty
5656+ | [] -> IntMap.add id IntSet.empty acc
3857 | p :: ps ->
3939- let inter = List.fold_left (fun acc pr ->
4040- try IntSet.inter acc (IntMap.find pr doms)
4141- with Not_found -> acc
4242- ) (try IntMap.find p doms with Not_found -> IntSet.empty) ps in
4343- IntSet.add id inter
4444- ) cfg.blocks in
5858+ let inter = List.fold_left (fun a pr ->
5959+ try IntSet.inter a (IntMap.find pr acc)
6060+ with Not_found -> a
6161+ ) (try IntMap.find p acc with Not_found -> IntSet.empty) ps in
6262+ IntMap.add id (IntSet.add id inter) acc
6363+ ) IntMap.empty rpo in
4564 if IntMap.equal IntSet.equal doms new_doms then doms
4665 else fixpoint new_doms
4766 in