Skip to content

Commit

Permalink
sort blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Jul 27, 2023
1 parent beeb986 commit 57f8755
Show file tree
Hide file tree
Showing 4 changed files with 666 additions and 658 deletions.
2 changes: 2 additions & 0 deletions compiler/lib/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,8 @@ and compile_block_no_loop st queue (pc : Addr.t) ~fall_through scope_stack =
Structure.get_edges st.dom pc
|> Addr.Set.elements
|> List.filter ~f:(fun pc' -> is_switch pc' || Structure.is_merge_node st.graph pc')
|> List.sort ~cmp:(fun a b ->
compare (Structure.block_order st.graph a) (Structure.block_order st.graph b))
in
if debug () && not (List.is_empty new_scopes)
then
Expand Down
2 changes: 2 additions & 0 deletions compiler/lib/structure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type control_flow_graph =
; block_order : (Addr.t, int) Hashtbl.t
}

let block_order g pc = Hashtbl.find g.block_order pc

let is_backward g pc pc' = Hashtbl.find g.block_order pc >= Hashtbl.find g.block_order pc'

let is_forward g pc pc' = Hashtbl.find g.block_order pc < Hashtbl.find g.block_order pc'
Expand Down
2 changes: 2 additions & 0 deletions compiler/lib/structure.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type control_flow_graph =
; block_order : (int, int) Hashtbl.t
}

val block_order : control_flow_graph -> int -> int

val is_backward : control_flow_graph -> int -> int -> bool

val is_forward : control_flow_graph -> int -> int -> bool
Expand Down
Loading

0 comments on commit 57f8755

Please sign in to comment.