Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
67ed71a
Gamma domain impl
b-paul Feb 13, 2026
4d0b661
Initial gamma domain impl
b-paul Feb 17, 2026
a51bf22
Lattice map
b-paul Feb 17, 2026
602917d
pretty
b-paul Feb 17, 2026
7660374
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 17, 2026
2e3bc9a
state
b-paul Feb 17, 2026
adffd50
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 17, 2026
46f1e76
state
b-paul Feb 17, 2026
1dce320
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 17, 2026
44a7ba7
state
b-paul Feb 17, 2026
de727c9
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 17, 2026
bde8183
state
b-paul Feb 17, 2026
28f62d8
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 17, 2026
006425e
top on calls
b-paul Feb 17, 2026
71aa1d5
Merge branch 'main' into lattice-collections
b-paul Feb 19, 2026
a9fb4af
latticeset plus proptests
b-paul Feb 19, 2026
2873b38
lattice map tests
b-paul Feb 19, 2026
3bc6219
pretty
b-paul Feb 19, 2026
5affc95
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 19, 2026
97410c3
singleton
b-paul Feb 19, 2026
a2a93f0
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 19, 2026
c522e7a
leq
b-paul Feb 19, 2026
b6d1b5a
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 19, 2026
1517918
use lattice collections properly
b-paul Feb 19, 2026
2c98881
leq (surprisingly complicated)
b-paul Feb 19, 2026
60c6f4b
Merge branch 'main' into lattice-collections
b-paul Feb 19, 2026
ca01df7
fmt
b-paul Feb 19, 2026
0254bc9
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 19, 2026
234c681
Switch mapstate to use latticemap
b-paul Feb 19, 2026
4bf7f40
fmt
b-paul Feb 19, 2026
917c7be
hide patriciatree keys
b-paul Feb 19, 2026
fbda63c
fmt
b-paul Feb 19, 2026
ef2b982
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 19, 2026
996b5b7
expose top map
b-paul Feb 19, 2026
4c4f24e
Merge branch 'lattice-collections' into gamma-domain
b-paul Feb 19, 2026
096b303
use new map state
b-paul Feb 19, 2026
cfb27ba
Merge branch 'main' into gamma-domain
b-paul Feb 20, 2026
0f87530
ide gamma
b-paul Feb 20, 2026
927e14d
Merge branch 'main' into gamma-domain
b-paul Feb 24, 2026
e0e0210
intra tests and comment ide
b-paul Feb 24, 2026
687ca48
Merge branch 'main' into gamma-domain
b-paul Feb 26, 2026
e6a7adf
fmt
b-paul Feb 26, 2026
1a392f1
remove test transform
b-paul Feb 26, 2026
1a6c877
clarify todo note
b-paul Feb 26, 2026
1d15e85
Force summarising all procedures with surprisingly no overhead
b-paul Feb 27, 2026
33e19bc
monotonic scc index
b-paul Feb 27, 2026
b4024a9
optimisations
b-paul Feb 27, 2026
a62dc33
Merge branch 'main' of https://github.com/agle/bincaml into ide-impro…
b-paul Feb 27, 2026
5191ae5
remove prints
b-paul Feb 27, 2026
769cf7e
phase 1 only solver
b-paul Feb 27, 2026
21c6cdc
Merge branch 'main' into ide-improvements
b-paul Mar 3, 2026
9dd134b
Merge branch 'main' into gamma-domain
b-paul Mar 3, 2026
a86e5d4
Change phase1 only api to summarise just procs
b-paul Mar 3, 2026
6cc7b46
dfg analysis
b-paul Mar 3, 2026
21d1183
add ide analysis (depends on ide-improvements)
b-paul Mar 3, 2026
22987b9
handle phis
b-paul Mar 5, 2026
813f254
transfer only modified dls (faster this time!)
b-paul Mar 5, 2026
dc4aea3
dot printer
b-paul Mar 5, 2026
83039d0
Merge branch 'ide-improvements' into gamma-domain
b-paul Mar 5, 2026
fd4db94
Reverse phi dir when forwards
b-paul Mar 5, 2026
a63360e
Merge branch 'ide-improvements' into gamma-domain
b-paul Mar 5, 2026
d6b1c7a
fix for ide changes
b-paul Mar 5, 2026
68eec5d
Correct ide transfer
b-paul Mar 5, 2026
0166ba8
compose on phis...
b-paul Mar 5, 2026
513d14c
Merge branch 'ide-improvements' into gamma-domain
b-paul Mar 5, 2026
e4e3a40
more fix
b-paul Mar 5, 2026
e439d75
Finally make it work then note it's extremely slow
b-paul Mar 5, 2026
0dcacc4
Merge branch 'main' into gamma-domain
b-paul Mar 12, 2026
368f3cf
Untested solver!
b-paul Mar 17, 2026
ccefc79
Maybe works ?!
b-paul Mar 17, 2026
fc51a66
entry2exit cache
b-paul Mar 19, 2026
c881511
gen stubs and perf
b-paul Mar 19, 2026
07a682b
Compute only relevant defuse or usedef
b-paul Mar 19, 2026
7b6b530
compose correctly
b-paul Mar 19, 2026
91551df
phase 2
b-paul Mar 19, 2026
c369103
test promote
b-paul Mar 19, 2026
87903e7
remove test pass
b-paul Mar 19, 2026
28b651b
phase 1 only function
b-paul Mar 19, 2026
3fe939b
Merge remote-tracking branch 'origin/main' into gamma-domain
b-paul Mar 19, 2026
fde644a
Merge branch 'idessa' into gamma-domain
b-paul Mar 19, 2026
3e4d1e9
use idessa
b-paul Mar 19, 2026
be08d91
docs types
b-paul Mar 19, 2026
9af7e40
reusable defuse
b-paul Mar 19, 2026
a0b798b
Merge branch 'idessa' into gamma-domain
b-paul Mar 19, 2026
a38f336
Readd intra to test
b-paul Mar 19, 2026
cb482fe
Merge branch 'main' into gamma-domain
b-paul Mar 19, 2026
63d0672
fixes
b-paul Mar 19, 2026
bc97267
Need output check to catch globals
b-paul Mar 20, 2026
2daea03
ignore globals by assuming
b-paul Mar 20, 2026
d920ebe
interproc test
b-paul Mar 20, 2026
13c9b16
Note issue with using summaries
b-paul Mar 20, 2026
090233f
remove test pass
b-paul Mar 20, 2026
03d9ec6
gen stubs properly (way slower now)
b-paul Mar 20, 2026
19adb8b
merge main
b-paul Apr 7, 2026
0c598ef
Merge branch 'main' into gamma-domain
b-paul Apr 7, 2026
e3a311c
Fix eval args
b-paul Apr 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/analysis/dune
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
lattice_collections
wrapped_intervals
known_bits
gamma_domain
tnum_wint_reduced_product
known_bits
wp_dual
Expand Down
155 changes: 155 additions & 0 deletions lib/analysis/gamma_domain.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
(* The forwards overappraximating gamma domain. It is assumed that the program is in ssa form. *)

include Lang
include Common
include Intra_analysis
include Lattice_collections

module GammaSet = struct
include LatticeSet (struct
include Var

let show = name
let name = "variable"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is confusing, maybe we should change the lattice name value to lattice_name or something

end)

let name = "Gamma set"
let pp fmt v = Format.pp_print_string fmt (show v)
end

module Domain = struct
include MapState (GammaSet)

let name = "Gamma domain"

let init proc =
Procedure.formal_in_params proc
|> StringMap.values
|> Iter.append
((Procedure.specification proc).captures_globs |> Iter.of_list)
|> Iter.map (fun v -> (v, GammaSet.singleton v))
|> Iter.fold (fun m (v, d) -> update v d m) bottom

let transfer_state m stmt =
let open Stmt in
let eval_expr e =
Expr.BasilExpr.free_vars_iter e
|> Iter.fold (fun s v' -> V.join (m v') s) V.bottom
in
match stmt with
| Instr_Assign a ->
Iter.of_list a |> Iter.map (fun (v, e) -> (v, eval_expr e))
| Instr_Assert _ -> Iter.empty
| Instr_Assume _ -> Iter.empty
| Instr_Load { lhs; rhs; addr = Scalar } -> Iter.singleton (lhs, m rhs)
| Instr_Store { lhs; value; addr = Scalar } ->
Iter.singleton (lhs, eval_expr value)
| Instr_Load { lhs; rhs } -> Iter.singleton (lhs, m rhs)
| Instr_Store { lhs; value } ->
Iter.singleton (lhs, V.join (m lhs) (eval_expr value))
(* could use IDE summaries, but that requires access to formal in params of caller *)
| Instr_Call { lhs } | Instr_IntrinCall { lhs } ->
StringMap.values lhs |> Iter.map (fun v -> (v, GammaSet.top))
(* need to globally go to top which the transfer_state api doesn't support *)
(*| Instr_IndirectCall c -> raise (Failure "unsupported")*)
| Instr_IndirectCall _ -> Iter.empty

let transfer m (stmt : Program.stmt) =
let open Stmt in
match stmt with
(* TODO calls can be more precise with modifies information (only send outputs + modifies to top) but this requires spec info *)
| Instr_Call _ | Instr_IntrinCall _ | Instr_IndirectCall _ -> top
| s ->
transfer_state (fun v -> read v m) s
|> Iter.fold (fun m (v, s) -> update v s m) m
end

module CFGAnalysis = Forwards (Domain)
module DFGAnalysis = Dataflow_graph.AnalysisFwd (Domain)
open Idessi

(* TODO handle memory nicely *)
module IDEDomain : IDESSIDomain = struct
let direction = `Forwards

module DL = struct
type t = Lambda | Label of Var.t
[@@deriving eq, ord, show { with_path = false }]

let show = function Lambda -> "L" | Label v -> Var.name v
end

module Value = GammaSet

let show_state s =
s
|> Iter.to_string ~sep:", " (fun (v, s) ->
Var.to_string v ^ "->" ^ GammaSet.show s)

type t = BottomEdge | IdEdge | TopEdge
[@@deriving eq, ord, show { with_path = false }]

let pp fmt v = Format.pp_print_string fmt (show v)
let identity = IdEdge
let bottom = BottomEdge
let top = TopEdge

let compose a b =
match a with IdEdge -> b | BottomEdge -> BottomEdge | TopEdge -> TopEdge

let join a b =
match (a, b) with
| BottomEdge, e | e, BottomEdge -> e
| TopEdge, _ | _, TopEdge -> TopEdge
| IdEdge, IdEdge -> IdEdge

let eval s = function
| BottomEdge -> Value.bottom
| IdEdge -> s
| TopEdge -> Value.top

let init_data (proc : Program.proc) =
Procedure.formal_in_params proc |> StringMap.values

type state_update = (DL.t * t) Iter.t

open DL

let transfer_call call params d =
match d with
| Lambda -> Iter.singleton (d, IdEdge)
| Label v ->
StringMap.to_iter call
|> Iter.filter (fun (_, e) ->
Expr.BasilExpr.free_vars e |> VarSet.mem v)
|> Iter.map (fun (s, _) -> (Label (StringMap.find s params), IdEdge))

let transfer stmt d =
let open Stmt in
match d with
| Lambda -> (
match stmt with
| Instr_Load l -> Iter.singleton (Label l.lhs, TopEdge)
| _ -> Iter.empty)
| Label v -> (
match stmt with
| Instr_Assign a ->
Iter.of_list a
|> Iter.flat_map (fun (v', e) ->
if VarSet.mem v (Expr.BasilExpr.free_vars e) then
Iter.singleton (Label v', IdEdge)
else Iter.empty)
| _ -> Iter.empty)

let transfer_phi lhs rhs d =
match d with
| Lambda -> Iter.empty
| Label v -> Iter.singleton (Label lhs, IdEdge)

let init_p2 (proc : Program.proc) =
Procedure.formal_in_params proc
|> StringMap.values
|> Iter.map (fun v -> (v, Value.singleton v))
end

module IDEAnalysis = IDESSI (IDEDomain)
8 changes: 4 additions & 4 deletions lib/analysis/ide.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module type IDEDomain = sig
val compose : t -> t -> t
(** the composite of edge functions *)

val eval : t -> Value.t -> Value.t
val eval : Value.t -> t -> Value.t
(** evaluate an edge function *)

val init_data : Var.t Iter.t -> Program.proc -> Data.t Iter.t
Expand Down Expand Up @@ -585,7 +585,7 @@ module IDE (D : IDEDomain) = struct
updates
|> Iter.fold
(fun acc ((d1, d3), e) ->
let base = dldlget Lambda d3 summary in
let base = dldlget Lambda d3 acc in
let m = DlMap.get_or d1 acc ~default:DlMap.empty in
match d1 with
| Label v when D.equal base (D.join e base) ->
Expand Down Expand Up @@ -654,7 +654,7 @@ module IDE (D : IDEDomain) = struct
match d3 with
| Label v ->
let st = Hashtbl.get_or states target ~default:DataMap.empty in
let fd = D.eval e21 md in
let fd = D.eval md e21 in
let y = DataMap.get_or v st ~default:D.Value.bottom in
let j = D.Value.join y fd in
if not (D.Value.equal j y) then (
Expand Down Expand Up @@ -750,7 +750,7 @@ module IDE (D : IDEDomain) = struct
match d2 with
| Label v ->
let st = get_st l in
let y = D.eval e x in
let y = D.eval x e in
Hashtbl.replace states l (join_state_with st v y)
| _ -> ())));
states
Expand Down
2 changes: 1 addition & 1 deletion lib/analysis/ide_live.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module IDELiveCommon = struct
| IdEdge, ConstEdge false -> IdEdge
| IdEdge, IdEdge -> IdEdge

let eval f v = match f with IdEdge -> v | ConstEdge c -> c
let eval v f = match f with IdEdge -> v | ConstEdge v -> v
end

module IDELive = struct
Expand Down
6 changes: 3 additions & 3 deletions lib/analysis/idessi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module type IDESSIDomain = sig
val compose : t -> t -> t
(** the composite of edge functions *)

val eval : t -> Value.t -> Value.t
val eval : Value.t -> t -> Value.t
(** evaluate an edge function *)

type state_update = (DL.t * t) Iter.t
Expand Down Expand Up @@ -260,9 +260,9 @@ module IDESSI (D : IDESSIDomain) = struct
| Label v ->
let x =
match d with
| Lambda -> D.eval ef D.Value.bottom
| Lambda -> D.eval D.Value.bottom ef
| Label v' ->
D.eval ef (VarMap.get_or v' m ~default:D.Value.bottom)
D.eval (VarMap.get_or v' m ~default:D.Value.bottom) ef
in
let j =
D.Value.join (VarMap.get_or v m ~default:D.Value.bottom) x
Expand Down
2 changes: 1 addition & 1 deletion lib/analysis/linear_const.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module LinearDomain = struct
| Join (a, b, c), Join (d, e, Bot) ->
Join (Bitvec.mul a d, Bitvec.add (Bitvec.mul a e) b, c)

let eval f x =
let eval x f =
match (f, x) with
| BotEdge, _ -> Value.Bot
| IdEdge, x -> x
Expand Down
8 changes: 8 additions & 0 deletions lib/passes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ module PassManager = struct
control flow graph and prints results";
}

let demo_dfg_gamma =
{
name = "demo-dfg-gamma-analysis";
apply = DFGAnalysis (module Analysis.Gamma_domain.DFGAnalysis);
doc = "Runs a gamma analysis on a data flow graph and prints results";
}

let remove_unused =
{
name = "remove-unused-decls";
Expand Down Expand Up @@ -225,6 +232,7 @@ module PassManager = struct
demo_ival_wint_dfg;
cfg_wrapped_int;
cfg_tnum_wint_reduced;
demo_dfg_gamma;
sparams;
read_uninit false;
read_uninit true;
Expand Down
Loading
Loading