[m-rev.] for review: let simplification introduce ground_term_const cons_ids
novalazy at gmail.com
Tue Jun 1 12:09:12 AEST 2021
On Mon, 31 May 2021 16:22:47 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> For review by Peter, since we discussed this approach
> a couple of weeks ago on m-rev.
> I haven't had time for benchmarking yet, but I intend to get some
> performance numbers in the next day or so.
> Let simplify introduce ground_term_const cons_ids.
> Fit the new optimization ino the logic that decides whether
> we need two passes through the procedure body, or just one.
> Factor out some common code.
> diff --git a/compiler/common.m b/compiler/common.m
> index a23bb8461..d54772b27 100644
> --- a/compiler/common.m
> +++ b/compiler/common.m
> @@ -188,6 +191,16 @@
> + % This module can implement two optimizations,
> + %
This comment is incomplete.
> +:- type common_info
> + ---> common_info(
> + maybe(common_struct_info),
> + maybe(const_struct_info)
> + ).
> @@ -296,32 +327,152 @@
> + % The const struct optimization, if enabled, looks for construction
> + % unifications X = f(...) where all the RHS arguments are constant terms,
> + % and replaces them with X = ground_term_const(N), where ground constant
> + % term #N in the const_struct_db is f(...).
> + %
> + % The const_var_map, which maps each variable that contains a
> + % knownt-to-be-ground term to its representation as an argument
> -common_optimise_unification(Unification0, UnifyMode, !GoalExpr, !GoalInfo,
> - !Common, !Info) :-
> +common_optimise_unification(RHS0, UnifyMode, Unification0, UnifyContext,
> + !GoalExpr, !GoalInfo, !Common, !Info) :-
> - Unification0 = construct(Var, ConsId, ArgVars, _, How, _, SubInfo),
> + Unification0 = construct(_, _, _, _, _, _, SubInfo),
> ( if
> - % There are three tests we have to pass before we even try
> - % to optimize away a construction. All three usually pass,
> - % so the order in which we test for them does not matter much.
> + % The call to common_optimise_construct below will try to perform
> + % one of two optimizations on this construction unification.
> + %
> + % - The first is replacing a dynamic unification with an
> + % assignment whose right hand side is a reference to
> + % a constant structure. We try to do this if !.Common
> + % contains a const_struct_info.
> + %
> + % - The second is to replace the construction with an assignment
> + % from a variable that already contains the term that the
> + % construction would build. We try to do this if !.Common
> + % contains a common_struct_info.
> + %
> + % There are two tests that must pass before we can attemp
> diff --git a/compiler/simplify_goal.m b/compiler/simplify_goal.m
> index 275186dcb..f1704ca8c 100644
> --- a/compiler/simplify_goal.m
> +++ b/compiler/simplify_goal.m
> +maybe_handle_stack_flush(BeforeAfter, GoalExpr, !Common) :-
> + WillFlish = will_flush(BeforeAfter, GoalExpr),
> + (
> + WillFlish = yes,
> - else
> - true
> + ;
> + WillFlish = no
That looks okay.
More information about the reviews