[m-rev.] diff: remove redundant code executions in mode_util.m

Zoltan Somogyi zs at unimelb.edu.au
Tue Apr 24 21:21:13 AEST 2012


compiler/mode_util.m:
	Avoid some redundant tests and unnecessary higher order calls.

Zoltan.

Index: compiler/mode_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.222
diff -u -b -r1.222 mode_util.m
--- compiler/mode_util.m	23 Apr 2012 03:34:48 -0000	1.222
+++ compiler/mode_util.m	24 Apr 2012 10:39:00 -0000
@@ -1425,8 +1425,8 @@
 
 recompute_instmap_delta_call(PredId, ProcId, Args, VarTypes, InstMap,
         InstMapDelta, !RI) :-
-    ModuleInfo = !.RI ^ ri_module_info,
-    module_info_pred_proc_info(ModuleInfo, PredId, ProcId, _, ProcInfo),
+    ModuleInfo0 = !.RI ^ ri_module_info,
+    module_info_pred_proc_info(ModuleInfo0, PredId, ProcId, _, ProcInfo),
     proc_info_interface_determinism(ProcInfo, Detism),
     ( determinism_components(Detism, _, at_most_zero) ->
         instmap_delta_init_unreachable(InstMapDelta)
@@ -1436,13 +1436,14 @@
         InstVarSet = !.RI ^ ri_inst_varset,
         rename_apart_inst_vars(InstVarSet, ProcInstVarSet,
             ArgModes0, ArgModes1),
-        mode_list_get_initial_insts(ModuleInfo, ArgModes1, InitialInsts),
+        mode_list_get_initial_insts(ModuleInfo0, ArgModes1, InitialInsts),
 
         % Compute the inst_var substitution from the initial insts
         % of the called procedure and the insts of the argument variables.
+        ( instmap_is_reachable(InstMap) ->
         map.init(InstVarSub0),
-        update_module_info(compute_inst_var_sub(Args, VarTypes, InstMap,
-            InitialInsts, InstVarSub0), InstVarSub, !RI),
+            compute_inst_var_sub(Args, VarTypes, InstMap, InitialInsts,
+                InstVarSub0, InstVarSub, ModuleInfo0, ModuleInfo1),
 
         % Apply the inst_var substitution to the argument modes.
         mode_list_apply_substitution(InstVarSub, ArgModes1, ArgModes2),
@@ -1450,9 +1451,14 @@
         % Calculate the final insts of the argument variables from their
         % initial insts and the final insts of the called procedure
         % (with inst_var substitutions applied).
-        update_module_info(
-            recompute_instmap_delta_call_2(Args, InstMap, ArgModes2),
-            ArgModes, !RI),
+            recompute_instmap_delta_call_2(Args, InstMap, ArgModes2, ArgModes,
+                ModuleInfo1, ModuleInfo),
+            !RI ^ ri_module_info := ModuleInfo
+        ;
+            list.length(Args, NumArgs),
+            list.duplicate(NumArgs, (not_reached -> not_reached), ArgModes),
+            ModuleInfo = ModuleInfo0
+        ),
         instmap_delta_from_mode_list(Args, ArgModes, ModuleInfo, InstMapDelta)
     ).
 
@@ -1470,7 +1476,6 @@
     % This is similar to modecheck_var_has_inst.
     SaveModuleInfo = !.ModuleInfo,
     SaveSub = !.Sub,
-    ( instmap_is_reachable(InstMap) ->
         instmap_lookup_var(InstMap, Arg, ArgInst),
         map.lookup(VarTypes, Arg, Type),
         ( inst_matches_initial_sub(ArgInst, Inst, Type, !ModuleInfo, !Sub) ->
@@ -1484,9 +1489,6 @@
             % which mean inst_matches_initial can sometimes fail here.
             !:ModuleInfo = SaveModuleInfo,
             !:Sub = SaveSub
-        )
-    ;
-        true
     ),
     compute_inst_var_sub(Args, VarTypes, InstMap, Insts, !Sub, !ModuleInfo).
 
@@ -1502,7 +1504,6 @@
 recompute_instmap_delta_call_2([Arg | Args], InstMap, [Mode0 | Modes0],
         [Mode | Modes], !ModuleInfo) :-
     % This is similar to modecheck_set_var_inst.
-    ( instmap_is_reachable(InstMap) ->
         instmap_lookup_var(InstMap, Arg, ArgInst0),
         mode_get_insts(!.ModuleInfo, Mode0, _, FinalInst),
         (
@@ -1516,9 +1517,6 @@
             Mode = (ArgInst0 -> UnifyInst)
         ;
             unexpected($module, $pred, "unify_inst failed")
-        )
-    ;
-        Mode = (not_reached -> not_reached)
     ),
     recompute_instmap_delta_call_2(Args, InstMap, Modes0, Modes,
         !ModuleInfo).
--------------------------------------------------------------------------
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