Skip to content

Commit

Permalink
flambda-backend: Cmm invariants (port upstream PR 1400) (ocaml#258)
Browse files Browse the repository at this point in the history
* Add an optional check for invariants on the Cmm representation

Port cmm invariants (ocaml PR 1400)

* Update .depend

* Update dune file

* Update cmm invariants for new cmm traps in backend

Co-authored-by: Vincent Laviron <vincent.laviron@gmail.com>
  • Loading branch information
gretay-js and lthls authored Oct 1, 2021
1 parent e901f16 commit 8e43a49
Show file tree
Hide file tree
Showing 22 changed files with 396 additions and 42 deletions.
42 changes: 21 additions & 21 deletions .depend
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ parsing/builtin_attributes.cmo : \
utils/misc.cmi \
parsing/longident.cmi \
parsing/location.cmi \
utils/config.cmi \
utils/clflags.cmi \
parsing/asttypes.cmi \
parsing/builtin_attributes.cmi
Expand All @@ -258,6 +259,7 @@ parsing/builtin_attributes.cmx : \
utils/misc.cmx \
parsing/longident.cmx \
parsing/location.cmx \
utils/config.cmx \
utils/clflags.cmx \
parsing/asttypes.cmi \
parsing/builtin_attributes.cmi
Expand Down Expand Up @@ -1590,6 +1592,8 @@ typing/typeopt.cmo : \
typing/typedecl.cmi \
typing/predef.cmi \
typing/path.cmi \
utils/numbers.cmi \
utils/misc.cmi \
lambda/lambda.cmi \
typing/ident.cmi \
typing/env.cmi \
Expand All @@ -1603,6 +1607,8 @@ typing/typeopt.cmx : \
typing/typedecl.cmx \
typing/predef.cmx \
typing/path.cmx \
utils/numbers.cmx \
utils/misc.cmx \
lambda/lambda.cmx \
typing/ident.cmx \
typing/env.cmx \
Expand Down Expand Up @@ -2101,6 +2107,7 @@ asmcomp/asmgen.cmo : \
asmcomp/comballoc.cmi \
asmcomp/coloring.cmi \
asmcomp/cmmgen.cmi \
asmcomp/cmm_invariants.cmi \
asmcomp/cmm_helpers.cmi \
asmcomp/cmm.cmi \
utils/clflags.cmi \
Expand Down Expand Up @@ -2142,6 +2149,7 @@ asmcomp/asmgen.cmx : \
asmcomp/comballoc.cmx \
asmcomp/coloring.cmx \
asmcomp/cmmgen.cmx \
asmcomp/cmm_invariants.cmx \
asmcomp/cmm_helpers.cmx \
asmcomp/cmm.cmx \
utils/clflags.cmx \
Expand Down Expand Up @@ -2378,6 +2386,16 @@ asmcomp/cmm_helpers.cmi : \
middle_end/clambda_primitives.cmi \
middle_end/clambda.cmi \
parsing/asttypes.cmi
asmcomp/cmm_invariants.cmo : \
utils/numbers.cmi \
asmcomp/cmm.cmi \
asmcomp/cmm_invariants.cmi
asmcomp/cmm_invariants.cmx : \
utils/numbers.cmx \
asmcomp/cmm.cmx \
asmcomp/cmm_invariants.cmi
asmcomp/cmm_invariants.cmi : \
asmcomp/cmm.cmi
asmcomp/cmmgen.cmo : \
typing/types.cmi \
middle_end/printclambda_primitives.cmi \
Expand Down Expand Up @@ -3037,19 +3055,16 @@ middle_end/clambda_primitives.cmo : \
typing/types.cmi \
typing/primitive.cmi \
lambda/lambda.cmi \
parsing/asttypes.cmi \
middle_end/clambda_primitives.cmi
middle_end/clambda_primitives.cmx : \
typing/types.cmx \
typing/primitive.cmx \
lambda/lambda.cmx \
parsing/asttypes.cmi \
middle_end/clambda_primitives.cmi
middle_end/clambda_primitives.cmi : \
typing/types.cmi \
typing/primitive.cmi \
lambda/lambda.cmi \
parsing/asttypes.cmi
lambda/lambda.cmi
middle_end/compilation_unit.cmo : \
utils/misc.cmi \
middle_end/linkage_name.cmi \
Expand Down Expand Up @@ -3165,7 +3180,6 @@ middle_end/printclambda.cmo : \
typing/ident.cmi \
middle_end/clambda.cmi \
middle_end/backend_var.cmi \
parsing/asttypes.cmi \
middle_end/printclambda.cmi
middle_end/printclambda.cmx : \
lambda/printlambda.cmx \
Expand All @@ -3174,7 +3188,6 @@ middle_end/printclambda.cmx : \
typing/ident.cmx \
middle_end/clambda.cmx \
middle_end/backend_var.cmx \
parsing/asttypes.cmi \
middle_end/printclambda.cmi
middle_end/printclambda.cmi : \
middle_end/clambda.cmi
Expand All @@ -3183,14 +3196,12 @@ middle_end/printclambda_primitives.cmo : \
typing/primitive.cmi \
lambda/lambda.cmi \
middle_end/clambda_primitives.cmi \
parsing/asttypes.cmi \
middle_end/printclambda_primitives.cmi
middle_end/printclambda_primitives.cmx : \
lambda/printlambda.cmx \
typing/primitive.cmx \
lambda/lambda.cmx \
middle_end/clambda_primitives.cmx \
parsing/asttypes.cmi \
middle_end/printclambda_primitives.cmi
middle_end/printclambda_primitives.cmi : \
middle_end/clambda_primitives.cmi
Expand Down Expand Up @@ -3808,7 +3819,6 @@ middle_end/flambda/alias_analysis.cmo : \
lambda/lambda.cmi \
utils/int_replace_polymorphic_compare.cmi \
middle_end/flambda/flambda.cmi \
parsing/asttypes.cmi \
middle_end/flambda/allocated_const.cmi \
middle_end/flambda/alias_analysis.cmi
middle_end/flambda/alias_analysis.cmx : \
Expand All @@ -3820,7 +3830,6 @@ middle_end/flambda/alias_analysis.cmx : \
lambda/lambda.cmx \
utils/int_replace_polymorphic_compare.cmx \
middle_end/flambda/flambda.cmx \
parsing/asttypes.cmi \
middle_end/flambda/allocated_const.cmx \
middle_end/flambda/alias_analysis.cmi
middle_end/flambda/alias_analysis.cmi : \
Expand All @@ -3829,7 +3838,6 @@ middle_end/flambda/alias_analysis.cmi : \
middle_end/symbol.cmi \
lambda/lambda.cmi \
middle_end/flambda/flambda.cmi \
parsing/asttypes.cmi \
middle_end/flambda/allocated_const.cmi
middle_end/flambda/allocated_const.cmo : \
utils/int_replace_polymorphic_compare.cmi \
Expand Down Expand Up @@ -4598,7 +4606,6 @@ middle_end/flambda/inconstant_idents.cmo : \
middle_end/compilation_unit.cmi \
middle_end/flambda/base_types/closure_id.cmi \
middle_end/backend_intf.cmi \
parsing/asttypes.cmi \
middle_end/flambda/inconstant_idents.cmi
middle_end/flambda/inconstant_idents.cmx : \
middle_end/variable.cmx \
Expand All @@ -4613,7 +4620,6 @@ middle_end/flambda/inconstant_idents.cmx : \
middle_end/compilation_unit.cmx \
middle_end/flambda/base_types/closure_id.cmx \
middle_end/backend_intf.cmi \
parsing/asttypes.cmi \
middle_end/flambda/inconstant_idents.cmi
middle_end/flambda/inconstant_idents.cmi : \
middle_end/variable.cmi \
Expand Down Expand Up @@ -5002,6 +5008,7 @@ middle_end/flambda/lift_constants.cmo : \
utils/strongly_connected_components.cmi \
middle_end/flambda/simple_value_approx.cmi \
utils/misc.cmi \
lambda/lambda.cmi \
middle_end/internal_variable_names.cmi \
utils/int_replace_polymorphic_compare.cmi \
middle_end/flambda/inconstant_idents.cmi \
Expand All @@ -5011,7 +5018,6 @@ middle_end/flambda/lift_constants.cmo : \
middle_end/compilation_unit.cmi \
middle_end/flambda/base_types/closure_id.cmi \
middle_end/backend_intf.cmi \
parsing/asttypes.cmi \
middle_end/flambda/allocated_const.cmi \
middle_end/flambda/alias_analysis.cmi \
middle_end/flambda/lift_constants.cmi
Expand All @@ -5023,6 +5029,7 @@ middle_end/flambda/lift_constants.cmx : \
utils/strongly_connected_components.cmx \
middle_end/flambda/simple_value_approx.cmx \
utils/misc.cmx \
lambda/lambda.cmx \
middle_end/internal_variable_names.cmx \
utils/int_replace_polymorphic_compare.cmx \
middle_end/flambda/inconstant_idents.cmx \
Expand All @@ -5032,7 +5039,6 @@ middle_end/flambda/lift_constants.cmx : \
middle_end/compilation_unit.cmx \
middle_end/flambda/base_types/closure_id.cmx \
middle_end/backend_intf.cmi \
parsing/asttypes.cmi \
middle_end/flambda/allocated_const.cmx \
middle_end/flambda/alias_analysis.cmx \
middle_end/flambda/lift_constants.cmi
Expand All @@ -5048,7 +5054,6 @@ middle_end/flambda/lift_let_to_initialize_symbol.cmo : \
middle_end/flambda/flambda_utils.cmi \
middle_end/flambda/flambda.cmi \
lambda/debuginfo.cmi \
parsing/asttypes.cmi \
middle_end/flambda/lift_let_to_initialize_symbol.cmi
middle_end/flambda/lift_let_to_initialize_symbol.cmx : \
middle_end/variable.cmx \
Expand All @@ -5059,7 +5064,6 @@ middle_end/flambda/lift_let_to_initialize_symbol.cmx : \
middle_end/flambda/flambda_utils.cmx \
middle_end/flambda/flambda.cmx \
lambda/debuginfo.cmx \
parsing/asttypes.cmi \
middle_end/flambda/lift_let_to_initialize_symbol.cmi
middle_end/flambda/lift_let_to_initialize_symbol.cmi : \
middle_end/flambda/flambda.cmi \
Expand Down Expand Up @@ -5114,7 +5118,6 @@ middle_end/flambda/ref_to_variables.cmo : \
utils/int_replace_polymorphic_compare.cmi \
middle_end/flambda/flambda_iterators.cmi \
middle_end/flambda/flambda.cmi \
parsing/asttypes.cmi \
middle_end/flambda/ref_to_variables.cmi
middle_end/flambda/ref_to_variables.cmx : \
middle_end/variable.cmx \
Expand All @@ -5124,7 +5127,6 @@ middle_end/flambda/ref_to_variables.cmx : \
utils/int_replace_polymorphic_compare.cmx \
middle_end/flambda/flambda_iterators.cmx \
middle_end/flambda/flambda.cmx \
parsing/asttypes.cmi \
middle_end/flambda/ref_to_variables.cmi
middle_end/flambda/ref_to_variables.cmi : \
middle_end/flambda/flambda.cmi
Expand Down Expand Up @@ -5350,7 +5352,6 @@ middle_end/flambda/simplify_primitives.cmo : \
middle_end/flambda/flambda.cmi \
utils/clflags.cmi \
middle_end/clambda_primitives.cmi \
parsing/asttypes.cmi \
middle_end/flambda/simplify_primitives.cmi
middle_end/flambda/simplify_primitives.cmx : \
middle_end/flambda/base_types/tag.cmx \
Expand All @@ -5366,7 +5367,6 @@ middle_end/flambda/simplify_primitives.cmx : \
middle_end/flambda/flambda.cmx \
utils/clflags.cmx \
middle_end/clambda_primitives.cmx \
parsing/asttypes.cmi \
middle_end/flambda/simplify_primitives.cmi
middle_end/flambda/simplify_primitives.cmi : \
middle_end/variable.cmi \
Expand Down
1 change: 1 addition & 0 deletions Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ HOST=@host@
FLAMBDA=@flambda@
FLAMBDA2=@flambda2@
WITH_FLAMBDA_INVARIANTS=@flambda_invariants@
WITH_CMM_INVARIANTS=@cmm_invariants@
FORCE_SAFE_STRING=@force_safe_string@
DEFAULT_SAFE_STRING=@default_safe_string@
WINDOWS_UNICODE=@windows_unicode@
Expand Down
11 changes: 11 additions & 0 deletions asmcomp/asmgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ type error =

exception Error of error

let cmm_invariants ppf fd_cmm =
let print_fundecl =
if !Clflags.dump_cmm then Printcmm.fundecl
else fun ppf fdecl -> Format.fprintf ppf "%s" fdecl.fun_name
in
if !Clflags.cmm_invariants && Cmm_invariants.run ppf fd_cmm then
Misc.fatal_errorf "Cmm invariants failed on following fundecl:@.%a@."
print_fundecl fd_cmm;
fd_cmm

let liveness phrase = Liveness.fundecl phrase; phrase

let dump_if ppf flag message phrase =
Expand Down Expand Up @@ -122,6 +132,7 @@ let compile_fundecl ~ppf_dump fd_cmm =
Proc.init ();
Reg.reset();
fd_cmm
++ Profile.record ~accumulate:true "cmm_invariants" (cmm_invariants ppf_dump)
++ Profile.record ~accumulate:true "selection" Selection.fundecl
++ pass_dump_if ppf_dump dump_selection "After instruction selection"
++ Profile.record ~accumulate:true "comballoc" Comballoc.fundecl
Expand Down
Loading

0 comments on commit 8e43a49

Please sign in to comment.