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.

materialise a defs table mapping ssa values to their defining instruction

+15 -1
+15 -1
lib/cfg.ml
··· 6 6 type cfg = { 7 7 blocks : block IntMap.t; 8 8 entry : value; 9 + mutable defs : inst IntMap.t; 9 10 } 10 11 11 12 let build_cfg (f : func) = 12 13 let blocks = List.fold_left (fun m b -> IntMap.add b.id b m) IntMap.empty f.blocks in 13 - let cfg = { blocks; entry = f.entry } in 14 + let cfg = { blocks; entry = f.entry; defs = IntMap.empty } in 14 15 let add_edges b = 15 16 let rec scan acc = function 16 17 | [] -> List.rev acc ··· 31 32 with Not_found -> () 32 33 ) b.succs 33 34 ) blocks; 35 + let defs = IntMap.fold (fun _ b acc -> 36 + List.fold_left (fun d inst -> 37 + match inst with 38 + | Alloca a -> IntMap.add a inst acc 39 + | Load (r, _) -> IntMap.add r inst d 40 + | BinOp (r, _, _) -> IntMap.add r inst d 41 + | Move (r, _) -> IntMap.add r inst d 42 + | Phi (r, _) -> IntMap.add r inst d 43 + | _ -> d 44 + ) acc b.insts 45 + ) blocks IntMap.empty in 46 + cfg.defs <- defs; 34 47 cfg 35 48 36 49 let get_block cfg id = IntMap.find id cfg.blocks 37 50 let get_succs cfg id = (get_block cfg id).succs 38 51 let get_preds cfg id = (get_block cfg id).preds 52 + let get_def cfg v = IntMap.find v cfg.defs