[m-rev.] for review: [CTGC] memo type_contains_subtype

Peter Wang novalazy at gmail.com
Tue Aug 5 17:41:39 AEST 2008


Branches: main

compiler/ctgc.selector.m:
	Memoise type_contains_subtype.  This greatly speeds up structure
	sharing/reuse analysis on some modules.

	Add a predicate to reset the memo table.

compiler/structure_reuse.analysis.m:
compiler/structure_sharing.analysis.m:
	Reset the memo table after these analyses.

diff --git a/compiler/ctgc.selector.m b/compiler/ctgc.selector.m
index 3aff069..1916065 100644
--- a/compiler/ctgc.selector.m
+++ b/compiler/ctgc.selector.m
@@ -19,6 +19,7 @@
 :- import_module hlds.hlds_module.
 :- import_module parse_tree.prog_data.
 
+:- import_module io.
 :- import_module list.
 
 %-----------------------------------------------------------------------------%
@@ -76,6 +77,10 @@
 :- pred selector_apply_widening(module_info::in, mer_type::in,
     selector::in, selector::out) is det.
 
+    % Reset memoisation tables used by this module.
+    %
+:- pred reset_tables(io::di, io::uo) is det.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -260,12 +265,24 @@ type_contains_subtype(ModuleInfo, FromType, ToType) :-
     ( FromType = ToType ->
         true
     ;
-        queue.put(queue.init, FromType, Queue0),
-        type_contains_subtype_2(ModuleInfo, ToType, Queue0, _Queue,
-            set.init, _SeenTypes, Contains),
+        type_contains_subtype_1(ModuleInfo, FromType, ToType, Contains),
         Contains = yes
     ).
 
+:- pred type_contains_subtype_1(module_info::in, mer_type::in, mer_type::in,
+    bool::out) is det.
+
+    % We assume that type definitions for a module don't change for the
+    % duration of the analysis.
+    %
+:- pragma memo(type_contains_subtype_1/4,
+    [allow_reset, specified([promise_implied, value, value, output])]).
+
+type_contains_subtype_1(ModuleInfo, FromType, ToType, Contains) :-
+    queue.put(queue.init, FromType, Queue0),
+    type_contains_subtype_2(ModuleInfo, ToType, Queue0, _Queue,
+        set.init, _SeenTypes, Contains).
+
 :- pred type_contains_subtype_2(module_info::in, mer_type::in,
     queue(mer_type)::in, queue(mer_type)::out,
     set(mer_type)::in, set(mer_type)::out, bool::out) is det.
@@ -478,6 +495,11 @@ branch_map_search([Type - Sel | TypeSels], KeyType, ValueSel):-
 
 %-----------------------------------------------------------------------------%
 
+reset_tables(!IO) :-
+    table_reset_for_type_contains_subtype_1_4(!IO).
+
+%-----------------------------------------------------------------------------%
+
 :- func this_file = string.
 
 this_file = "ctgc.selector.m".
diff --git a/compiler/structure_reuse.analysis.m b/compiler/structure_reuse.analysis.m
index 11f7e09..330c891 100644
--- a/compiler/structure_reuse.analysis.m
+++ b/compiler/structure_reuse.analysis.m
@@ -112,6 +112,7 @@
 :- import_module parse_tree.prog_ctgc.
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_type.
+:- import_module transform_hlds.ctgc.selector.
 :- import_module transform_hlds.ctgc.structure_reuse.direct.
 :- import_module transform_hlds.ctgc.structure_reuse.domain.
 :- import_module transform_hlds.ctgc.structure_reuse.indirect.
@@ -274,7 +275,9 @@ structure_reuse_analysis(!ModuleInfo, !IO):-
     bimap.foldl(
         remove_useless_reuse_proc(!.ModuleInfo, VeryVerbose, ReuseInfoMap),
         ReuseVersionMap, PredTable0, PredTable),
-    module_info_set_predicate_table(PredTable, !ModuleInfo).
+    module_info_set_predicate_table(PredTable, !ModuleInfo),
+
+    selector.reset_tables(!IO).
 
 %-----------------------------------------------------------------------------%
 
diff --git a/compiler/structure_sharing.analysis.m b/compiler/structure_sharing.analysis.m
index 348a739..4beff1c 100644
--- a/compiler/structure_sharing.analysis.m
+++ b/compiler/structure_sharing.analysis.m
@@ -82,6 +82,7 @@
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_out.
 :- import_module parse_tree.prog_type.
+:- import_module transform_hlds.ctgc.selector.
 :- import_module transform_hlds.ctgc.fixpoint_table.
 :- import_module transform_hlds.ctgc.structure_sharing.domain.
 :- import_module transform_hlds.ctgc.util.
@@ -145,7 +146,9 @@ structure_sharing_analysis(!ModuleInfo, !IO) :-
         make_opt_int(!.ModuleInfo, !IO)
     ;
         true
-    ).
+    ),
+
+    selector.reset_tables(!IO).
 
 %-----------------------------------------------------------------------------%
 %


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list