MLIR DAG rewriter w/ SSA IR, dominance and CFG analysis passes
1

Configure Feed

Select the types of activity you want to include in your feed.

iterate in reverse postorder for faster fixpoint convergence

+28 -9
+28 -9
lib/dominance.ml
··· 25 25 in 26 26 find strict_doms 27 27 28 + let rev_postorder cfg = 29 + let visited = ref IntSet.empty in 30 + let order = ref [] in 31 + let rec dfs id = 32 + if IntSet.mem id !visited then () 33 + else begin 34 + visited := IntSet.add id !visited; 35 + let b = IntMap.find id cfg.blocks in 36 + List.iter dfs b.succs; 37 + order := id :: !order 38 + end 39 + in 40 + dfs cfg.entry; 41 + let remaining = IntMap.fold (fun k _ acc -> 42 + if IntSet.mem k !visited then acc else k :: acc 43 + ) cfg.blocks [] in 44 + !order @ remaining 45 + 28 46 let dominators cfg = 29 47 let all = IntMap.fold (fun k _ s -> IntSet.add k s) cfg.blocks IntSet.empty in 30 48 let init = IntSet.singleton cfg.entry in 49 + let rpo = rev_postorder cfg in 31 50 let rec fixpoint doms = 32 - let new_doms = IntMap.mapi (fun id _ -> 33 - if id = cfg.entry then init 51 + let new_doms = List.fold_left (fun acc id -> 52 + if id = cfg.entry then IntMap.add id init acc 34 53 else 35 54 let b = IntMap.find id cfg.blocks in 36 55 match b.preds with 37 - | [] -> IntSet.empty 56 + | [] -> IntMap.add id IntSet.empty acc 38 57 | p :: ps -> 39 - let inter = List.fold_left (fun acc pr -> 40 - try IntSet.inter acc (IntMap.find pr doms) 41 - with Not_found -> acc 42 - ) (try IntMap.find p doms with Not_found -> IntSet.empty) ps in 43 - IntSet.add id inter 44 - ) cfg.blocks in 58 + let inter = List.fold_left (fun a pr -> 59 + try IntSet.inter a (IntMap.find pr acc) 60 + with Not_found -> a 61 + ) (try IntMap.find p acc with Not_found -> IntSet.empty) ps in 62 + IntMap.add id (IntSet.add id inter) acc 63 + ) IntMap.empty rpo in 45 64 if IntMap.equal IntSet.equal doms new_doms then doms 46 65 else fixpoint new_doms 47 66 in