[m-rev.] diff: turn lvals_in_* into functions

Zoltan Somogyi zs at csse.unimelb.edu.au
Wed Sep 3 13:31:45 AEST 2008


compiler/code_util.m:
	Convert some predicates into functions, to make them easier to use.

compiler/code_info.m:
compiler/reassign.m:
compiler/use_local_vars.m:
compiler/var_locn.m:
	Conform to the change in code_util.m.

Zoltan.

cvs diff: Diffing .
Index: code_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.364
diff -u -b -r1.364 code_info.m
--- code_info.m	6 Jun 2008 07:51:50 -0000	1.364
+++ code_info.m	6 Jun 2008 08:11:34 -0000
@@ -3743,13 +3743,13 @@
 
 assign_expr_to_var(Var, Rval, Code, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
+    Lvals = lvals_in_rval(Rval),
     (
-        code_util.lvals_in_rval(Rval, Lvals),
-        Lvals = []
-    ->
+        Lvals = [],
         var_locn_assign_expr_to_var(Var, Rval, Code,
         VarLocnInfo0, VarLocnInfo)
     ;
+        Lvals = [_ | _],
         unexpected(this_file, "assign_expr_to_var: non-var lvals")
     ),
     set_var_locn_info(VarLocnInfo, !CI).
Index: code_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_util.m,v
retrieving revision 1.183
diff -u -b -r1.183 code_util.m
--- code_util.m	27 Feb 2008 07:23:03 -0000	1.183
+++ code_util.m	27 Mar 2008 23:07:43 -0000
@@ -77,9 +77,9 @@
     % and an lval respectively. Lvals referenced indirectly through
     % lvals of the form var(_) are not counted.
     %
-:- pred lvals_in_rval(rval::in, list(lval)::out) is det.
-:- pred lvals_in_lval(lval::in, list(lval)::out) is det.
-:- pred lvals_in_lvals(list(lval)::in, list(lval)::out) is det.
+:- func lvals_in_rval(rval) = list(lval).
+:- func lvals_in_lval(lval) = list(lval).
+:- func lvals_in_lvals(list(lval)) = list(lval).
 
     % Given a procedure that already has its arg_info field filled in,
     % return a list giving its input variables and their initial locations.
@@ -337,63 +337,48 @@
 
 %-----------------------------------------------------------------------------%
 
-lvals_in_lvals([], []).
-lvals_in_lvals([First | Rest], FirstLvals ++ RestLvals) :-
-    lvals_in_lval(First, FirstLvals),
-    lvals_in_lvals(Rest, RestLvals).
-
-lvals_in_rval(lval(Lval), [Lval | Lvals]) :-
-    lvals_in_lval(Lval, Lvals).
-lvals_in_rval(var(_), []).
-lvals_in_rval(mkword(_, Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_rval(const(_), []).
-lvals_in_rval(unop(_, Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_rval(binop(_, Rval1, Rval2), Lvals1 ++ Lvals2) :-
-    lvals_in_rval(Rval1, Lvals1),
-    lvals_in_rval(Rval2, Lvals2).
-lvals_in_rval(mem_addr(MemRef), Lvals) :-
-    lvals_in_mem_ref(MemRef, Lvals).
-
-lvals_in_lval(reg(_, _), []).
-lvals_in_lval(stackvar(_), []).
-lvals_in_lval(parent_stackvar(_), []).
-lvals_in_lval(framevar(_), []).
-lvals_in_lval(succip, []).
-lvals_in_lval(maxfr, []).
-lvals_in_lval(curfr, []).
-lvals_in_lval(succip_slot(Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_lval(redofr_slot(Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_lval(redoip_slot(Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_lval(succfr_slot(Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_lval(prevfr_slot(Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_lval(hp, []).
-lvals_in_lval(sp, []).
-lvals_in_lval(parent_sp, []).
-lvals_in_lval(field(_, Rval1, Rval2), Lvals1 ++ Lvals2) :-
-    lvals_in_rval(Rval1, Lvals1),
-    lvals_in_rval(Rval2, Lvals2).
-lvals_in_lval(lvar(_), []).
-lvals_in_lval(temp(_, _), []).
-lvals_in_lval(mem_ref(Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_lval(global_var_ref(_), []).
-
-:- pred lvals_in_mem_ref(mem_ref::in, list(lval)::out) is det.
-
-lvals_in_mem_ref(stackvar_ref(Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_mem_ref(framevar_ref(Rval), Lvals) :-
-    lvals_in_rval(Rval, Lvals).
-lvals_in_mem_ref(heap_ref(Rval1, _, Rval2), Lvals1 ++ Lvals2) :-
-    lvals_in_rval(Rval1, Lvals1),
-    lvals_in_rval(Rval2, Lvals2).
+lvals_in_lvals([]) = [].
+lvals_in_lvals([First | Rest]) = FirstLvals ++ RestLvals :-
+    FirstLvals = lvals_in_lval(First),
+    RestLvals = lvals_in_lvals(Rest).
+
+lvals_in_rval(lval(Lval)) = [Lval | lvals_in_lval(Lval)].
+lvals_in_rval(var(_)) = [].
+lvals_in_rval(mkword(_, Rval)) = lvals_in_rval(Rval).
+lvals_in_rval(const(_)) = [].
+lvals_in_rval(unop(_, Rval)) = lvals_in_rval(Rval).
+lvals_in_rval(binop(_, Rval1, Rval2)) =
+    lvals_in_rval(Rval1) ++ lvals_in_rval(Rval2).
+lvals_in_rval(mem_addr(MemRef)) = lvals_in_mem_ref(MemRef).
+
+lvals_in_lval(reg(_, _)) = [].
+lvals_in_lval(stackvar(_)) = [].
+lvals_in_lval(parent_stackvar(_)) = [].
+lvals_in_lval(framevar(_)) = [].
+lvals_in_lval(succip) = [].
+lvals_in_lval(maxfr) = [].
+lvals_in_lval(curfr) = [].
+lvals_in_lval(succip_slot(Rval)) = lvals_in_rval(Rval).
+lvals_in_lval(redofr_slot(Rval)) = lvals_in_rval(Rval).
+lvals_in_lval(redoip_slot(Rval)) = lvals_in_rval(Rval).
+lvals_in_lval(succfr_slot(Rval)) = lvals_in_rval(Rval).
+lvals_in_lval(prevfr_slot(Rval)) = lvals_in_rval(Rval).
+lvals_in_lval(hp) = [].
+lvals_in_lval(sp) = [].
+lvals_in_lval(parent_sp) = [].
+lvals_in_lval(field(_, Rval1, Rval2)) =
+    lvals_in_rval(Rval1) ++ lvals_in_rval(Rval2).
+lvals_in_lval(lvar(_)) = [].
+lvals_in_lval(temp(_, _)) = [].
+lvals_in_lval(mem_ref(Rval)) = lvals_in_rval(Rval).
+lvals_in_lval(global_var_ref(_)) = [].
+
+:- func lvals_in_mem_ref(mem_ref) = list(lval).
+
+lvals_in_mem_ref(stackvar_ref(Rval)) = lvals_in_rval(Rval).
+lvals_in_mem_ref(framevar_ref(Rval)) = lvals_in_rval(Rval).
+lvals_in_mem_ref(heap_ref(Rval1, _, Rval2)) =
+    lvals_in_rval(Rval1) ++ lvals_in_rval(Rval2).
 
 %-----------------------------------------------------------------------------%
 
Index: reassign.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/reassign.m,v
retrieving revision 1.27
diff -u -b -r1.27 reassign.m
--- reassign.m	11 Feb 2008 03:56:11 -0000	1.27
+++ reassign.m	28 Mar 2008 08:34:54 -0000
@@ -386,7 +386,7 @@
     % way the known contents map. This is a conservative approximation of the
     % desired behaviour, which would invalidate only the entries of lvals
     % that may be referred to via this mem_ref.
-    code_util.lvals_in_rval(lval(Target), SubLvals),
+    SubLvals = lvals_in_rval(lval(Target)),
     (
         some [SubLval] (
             list.member(SubLval, SubLvals),
@@ -410,7 +410,7 @@
     dependent_lval_map::in, dependent_lval_map::out) is det.
 
 record_known(TargetLval, SourceRval, !KnownContentsMap, !DepLvalMap) :-
-    code_util.lvals_in_rval(SourceRval, SourceSubLvals),
+    SourceSubLvals = lvals_in_rval(SourceRval),
     ( list.member(TargetLval, SourceSubLvals) ->
         % The act of assigning to TargetLval has modified the value of
         % SourceRval, so we can't eliminate any copy of this assignment
@@ -440,13 +440,13 @@
         % and will add it back in a few lines later on.
         %
         % TargetLval still depends on the lvals inside it.
-        code_util.lvals_in_rval(OldRval, OldSubLvals),
+        OldSubLvals = lvals_in_rval(OldRval),
         list.foldl(make_not_dependent(TargetLval), OldSubLvals, !DepLvalMap)
     ;
         true
     ),
-    code_util.lvals_in_lval(TargetLval, TargetSubLvals),
-    code_util.lvals_in_rval(SourceRval, SourceSubLvals),
+    TargetSubLvals = lvals_in_lval(TargetLval),
+    SourceSubLvals = lvals_in_rval(SourceRval),
     list.append(TargetSubLvals, SourceSubLvals, AllSubLvals),
     list.foldl(make_dependent(TargetLval), AllSubLvals, !DepLvalMap),
     svmap.set(TargetLval, SourceRval, !KnownContentsMap).
Index: use_local_vars.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/use_local_vars.m,v
retrieving revision 1.38
diff -u -b -r1.38 use_local_vars.m
--- use_local_vars.m	11 Feb 2008 03:56:11 -0000	1.38
+++ use_local_vars.m	4 Jun 2008 04:53:33 -0000
@@ -391,9 +391,7 @@
     Instr0 = llds_instr(Uinstr0, _Comment0),
     (
         Uinstr0 = assign(ToLval, FromRval),
-        lvals_in_lval(ToLval, ToSubLvals),
-        lvals_in_rval(FromRval, FromSubLvals),
-        list.append(ToSubLvals, FromSubLvals, SubLvals),
+        SubLvals = lvals_in_lval(ToLval) ++ lvals_in_rval(FromRval),
         list.filter(
             base_lval_worth_replacing_not_tried(AlreadyTried0, NumRealRRegs),
             SubLvals, ReplaceableSubLvals),
@@ -402,7 +400,7 @@
         OrigTempCounter = !.TempCounter,
         counter.allocate(TempNum, !TempCounter),
         TempLval = temp(reg_r, TempNum),
-        lvals_in_lval(ChosenLval, SubChosenLvals),
+        SubChosenLvals = lvals_in_lval(ChosenLval),
         expect(unify(SubChosenLvals, []),
             this_file, "opt_access: nonempty SubChosenLvals"),
         substitute_lval_in_instr_until_defn(ChosenLval, TempLval,
Index: var_locn.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/var_locn.m,v
retrieving revision 1.63
diff -u -b -r1.63 var_locn.m
--- var_locn.m	2 Jun 2008 02:27:29 -0000	1.63
+++ var_locn.m	4 Jun 2008 04:56:10 -0000
@@ -1776,8 +1776,7 @@
 
 get_var_set_roots(Lvals, NoDupRootLvals) :-
     set.to_sorted_list(Lvals, LvalList),
-    code_util.lvals_in_lvals(LvalList, ContainedLvals),
-    list.append(LvalList, ContainedLvals, AllLvals),
+    AllLvals = LvalList ++ lvals_in_lvals(LvalList),
     list.filter(is_root_lval, AllLvals, RootLvals),
     list.sort_and_remove_dups(RootLvals, NoDupRootLvals).
 
cvs diff: Diffing notes
--------------------------------------------------------------------------
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