From adf40a76fd9503628508ef1eea5396aabda88eab Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Tue, 5 Mar 2019 14:55:45 +0000 Subject: More optimizations and improvments for C generation Add some comments in constant_fold.ml --- src/constant_fold.ml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/constant_fold.ml') diff --git a/src/constant_fold.ml b/src/constant_fold.ml index 6ad1f663..0ede2401 100644 --- a/src/constant_fold.ml +++ b/src/constant_fold.ml @@ -62,6 +62,9 @@ let optimize_constant_fold = ref false let rec fexp_of_ctor (field, value) = FE_aux (FE_Fexp (mk_id field, exp_of_value value), no_annot) +(* The interpreter will return a value for each folded expression, so + we must convert that back to expression to re-insert it in the AST + *) and exp_of_value = let open Value in function @@ -107,6 +110,32 @@ let safe_primops = "Elf_loader.elf_tohost" ] +(** We can specify a list of identifiers that we want to remove from + the final AST here. This is useful for removing tracing features in + optimized builds, e.g. for booting an OS as fast as possible. + + Basically we just do this by mapping + + f(x, y, z) -> () + + when f is in the list of identifiers to be mapped to unit. The + advantage of doing it like this is if x, y, and z are + computationally expensive then we remove them also. String + concatentation is very expensive at runtime so this is something we + really want when cutting out tracing features. Obviously it's + important that they don't have any meaningful side effects, and + that f does actually have type unit. +*) +let opt_fold_to_unit = ref [] + +let fold_to_unit id = + let remove = + !opt_fold_to_unit + |> List.map mk_id + |> List.fold_left (fun m id -> IdSet.add id m) IdSet.empty + in + IdSet.mem id remove + let rec is_constant (E_aux (e_aux, _)) = match e_aux with | E_lit _ -> true @@ -177,6 +206,11 @@ let rec rewrite_constant_function_calls' ast = let rw_funcall e_aux annot = match e_aux with + (* + | E_app (id, args) when fold_to_unit id -> + ok (); E_aux (E_lit (L_aux (L_unit, Parse_ast.Unknown)), annot) + *) + | E_app (id, args) when List.for_all is_constant args -> evaluate e_aux annot -- cgit v1.2.3 From 2b4018a07e9eead8bfe147611b24a4d5856b4d56 Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Wed, 6 Mar 2019 14:11:24 +0000 Subject: Add option to slice out printing and tracing functions when generating C Make instruction dependency graph use graph.ml Expose incremental graph building functions for performance in graph.mli --- src/constant_fold.ml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/constant_fold.ml') diff --git a/src/constant_fold.ml b/src/constant_fold.ml index 0ede2401..f85fb673 100644 --- a/src/constant_fold.ml +++ b/src/constant_fold.ml @@ -206,10 +206,8 @@ let rec rewrite_constant_function_calls' ast = let rw_funcall e_aux annot = match e_aux with - (* | E_app (id, args) when fold_to_unit id -> - ok (); E_aux (E_lit (L_aux (L_unit, Parse_ast.Unknown)), annot) - *) + ok (); E_aux (E_lit (L_aux (L_unit, fst annot)), annot) | E_app (id, args) when List.for_all is_constant args -> evaluate e_aux annot -- cgit v1.2.3