Skip to content

Commit

Permalink
Selection: CFG pipeline (ocaml-flambda#3073)
Browse files Browse the repository at this point in the history
  • Loading branch information
xclerc authored Oct 23, 2024
1 parent b066005 commit 43b57ce
Show file tree
Hide file tree
Showing 9 changed files with 1,304 additions and 43 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ jobs:
ocamlparam: '_,w=-46,regalloc=gi,regalloc-param=SPLIT_LIVE_RANGES:on,regalloc-param=GI_PRIORITY_HEURISTICS:interval-length,regalloc-param=GI_SELECTION_HEURISTICS:first-available,regalloc-param=GI_SPILLING_HEURISTICS:flat-uses,regalloc-validate=1,cfg-cse-optimize=1'
check_arch: true

- name: cfg-selection
config: --enable-middle-end=flambda2
os: ubuntu-latest
build_ocamlparam: '_,w=-46,regalloc=cfg,cfg-cse-optimize=1,cfg-selection=1,cfg-zero-alloc-checker=1'
ocamlparam: '_,w=-46,regalloc=cfg,cfg-cse-optimize=1,cfg-selection=1,cfg-zero-alloc-checker=1'
check_arch: true

env:
J: "3"
# On macOS, the testsuite is slow, so run only on push to main (#507)
Expand Down
5 changes: 4 additions & 1 deletion backend/amd64/cfg_selection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
open Arch
open Selection_utils

let specific x = Cfg_selectgen.Basic (Op (Specific x))
let specific x =
assert (not (Arch.operation_can_raise x));
Cfg_selectgen.Basic (Op (Specific x))

let pseudoregs_for_operation op arg res =
match (op : Cfg.operation) with
Expand Down Expand Up @@ -318,4 +320,5 @@ class selector =
end

let fundecl ~future_funcnames f =
Cfg_selectgen.reset_next_instr_id ();
(new selector)#emit_fundecl ~future_funcnames f
8 changes: 7 additions & 1 deletion backend/arm64/cfg_selection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ open Arch
open Cmm
open Selection_utils

let specific x = Cfg_selectgen.Basic Cfg.(Op (Specific x))
let specific x =
if Arch.operation_can_raise x
then
Cfg_selectgen.With_next_label
(fun label_after -> Cfg.Specific_can_raise { Cfg.op = x; label_after })
else Cfg_selectgen.Basic Cfg.(Op (Specific x))

class selector =
object (self)
Expand Down Expand Up @@ -167,4 +172,5 @@ class selector =
end

let fundecl ~future_funcnames f =
Cfg_selectgen.reset_next_instr_id ();
(new selector)#emit_fundecl ~future_funcnames f
2 changes: 1 addition & 1 deletion backend/cfg/cfg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module DLL = Flambda_backend_utils.Doubly_linked_list
type basic_instruction_list = basic instruction DLL.t

type basic_block =
{ start : Label.t;
{ mutable start : Label.t;
body : basic_instruction_list;
mutable terminator : terminator instruction;
mutable predecessors : Label.Set.t;
Expand Down
2 changes: 1 addition & 1 deletion backend/cfg/cfg.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type basic_instruction_list =
basic instruction Flambda_backend_utils.Doubly_linked_list.t

type basic_block =
{ start : Label.t;
{ mutable start : Label.t;
body : basic_instruction_list;
mutable terminator : terminator instruction;
mutable predecessors : Label.Set.t;
Expand Down
10 changes: 6 additions & 4 deletions backend/cfg/cfgize.ml
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,10 @@ module Stack_offset_and_exn = struct
match term.desc with
| Tailcall_self _
when stack_offset <> 0 || List.compare_length_with traps 0 <> 0 ->
Misc.fatal_error
Misc.fatal_errorf
"Cfgize.Stack_offset_and_exn.process_terminator: unexpected handler on \
self tailcall"
self tailcall (id=%d)"
term.id
| Never | Always _ | Parity_test _ | Truth_test _ | Float_test _
| Int_test _ | Switch _ | Return | Raise _ | Tailcall_self _
| Tailcall_func _ | Call_no_return _ | Call _ | Prim _
Expand All @@ -616,9 +617,10 @@ module Stack_offset_and_exn = struct
| Poptrap -> (
match traps with
| [] ->
Misc.fatal_error
Misc.fatal_errorf
"Cfgize.Stack_offset_and_exn.process_basic: trying to pop from an \
empty stack"
empty stack (id=%d)"
instr.id
| _ :: traps -> stack_offset, traps)
| Op (Stackoffset n) -> stack_offset + n, traps
| Op
Expand Down
7 changes: 7 additions & 0 deletions backend/cfg/cfgize.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
val terminator_of_test :
Mach.test -> label_false:Label.t -> label_true:Label.t -> Cfg.terminator

module Stack_offset_and_exn : sig
val update_cfg : Cfg.t -> unit
end

val fundecl :
Mach.fundecl ->
before_register_allocation:bool ->
Expand Down
Loading

0 comments on commit 43b57ce

Please sign in to comment.