[m-rev.] for review: reasons not to delete procs in dead_proc_elim.m

Julien Fischer jfischer at opturion.com
Fri May 13 17:09:46 AEST 2022


On Fri, 13 May 2022, Zoltan Somogyi wrote:

> Extend debug messages from dead_proc_elim.m.

...

> compiler/dead_proc_elim.m:
> diff --git a/compiler/dead_proc_elim.m b/compiler/dead_proc_elim.m
> index 224a9b77c..2ab4bbba7 100644
> --- a/compiler/dead_proc_elim.m
> +++ b/compiler/dead_proc_elim.m
> @@ -31,24 +31,36 @@
>  :- import_module parse_tree.error_util.
>  :- import_module parse_tree.prog_data.
> 
> +:- import_module io.
>  :- import_module list.
>  :- import_module map.
> +:- import_module set.
> +:- import_module set_ctree234.
>
>  %-----------------------------------------------------------------------------%
>
>  :- type needed_map == map(entity, maybe_needed).
>
>  :- type entity
> -    --->    entity_proc(pred_id, proc_id)
> -    ;       entity_table_struct(pred_id, proc_id)
> +    --->    entity_proc(pred_proc_id)
> +    ;       entity_table_struct(pred_proc_id)
>      ;       entity_type_ctor(module_name, string, int)
>      ;       entity_const_struct(int)
>      ;       entity_mutable(module_name, string, mutable_pred_kind).
>
>  :- type maybe_needed
> -    --->    not_eliminable
> +    --->    not_eliminable(set_ctree234(needed_reason))
>      ;       maybe_eliminable(num_references :: int).
> 
> +:- type needed_reason
> +    --->    nr_exported
> +    ;       nr_foreign_exported
> +    ;       nr_init_fin

I suggest s/fin/final/

> +    ;       nr_type_ctor
> +    ;       nr_const_struct
> +    ;       nr_class_interface_proc
> +    ;       nr_used_by(entity).
> +
>      % Analyze which entities are needed, and for those entities which are
>      % needed, record how many times they are referenced (this information
>      % is used by our inlining heuristics).

...

> @@ -1439,11 +1548,11 @@ dead_pred_initialize_maybe_canonical(ModuleInfo, MaybeCanon, !NeededPreds) :-
>
>  dead_pred_elim_add_entity(Entity, !Queue, !Preds) :-
>      (
> -        Entity = entity_proc(PredId, _),
> +        Entity = entity_proc(proc(PredId, _)),
>          queue.put(PredId, !Queue),
>          set_tree234.insert(PredId, !Preds)
>      ;
> -        ( Entity = entity_table_struct(_, _)
> +        ( Entity = entity_table_struct(_)
>          ; Entity = entity_type_ctor(_, _, _)
>          ; Entity = entity_const_struct(_)
>          ; Entity = entity_mutable(_, _, _)
> @@ -1462,8 +1571,8 @@ dead_pred_elim_initialize(PredId, DeadInfo0, DeadInfo) :-
>              PredModuleName = pred_info_module(PredInfo),
>              PredName = pred_info_name(PredInfo),
>              (
> -                % Don't eliminate special preds since they won't be actually
> -                % called from the HLDS until after polymorphism.
> +                % Don't eliminate unify or compare predicates, because we
> +                % won't identify calls to them until after polymorphism.

I know this is an existing comment, but what's it mean.  Dead procedure
elimination is not run until well after the polymorphism pass anyway --
is "polymorphism" a reference to the pass of the same name?
(Actually, you presuambly cannot delete them unless you can prove that
the types they belong to are unused and/or that they are not going to
be called through RTTI.)

That looks fine otherwise.

Julien.


More information about the reviews mailing list